Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker error for SDL2 #377

Closed
Kiryu144 opened this issue Oct 6, 2019 · 3 comments

Comments

@Kiryu144
Copy link

@Kiryu144 Kiryu144 commented Oct 6, 2019

I'm currently trying to setup Magnum to play around with it.
Sadly I am not that good in CMake, so its probably that. When I try to compile the sample "MyApplication.cpp", it failes on the linking step.

[100%] Linking CXX executable ..\..\bin\MyApplication.exe
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::Sdl2Application(Magnum::Platform::Sdl2Application::Arguments const&, Magnum::NoCreateT)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:102: undefined reference to `SDL_SetHint'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:108: undefined reference to `SDL_SetHint'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:113: undefined reference to `SDL_SetHint'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:116: undefined reference to `SDL_Init'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::dpiScaling(Magnum::Platform::Sdl2Application::Configuration const&) const':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:218: undefined reference to `SDL_GetDisplayDPI'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:251: undefined reference to `SDL_GetDisplayDPI'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:257: undefined reference to `SDL_GetError'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setWindowTitle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:270: undefined reference to `SDL_SetWindowTitle'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::tryCreate(Magnum::Platform::Sdl2Application::Configuration const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:290: undefined reference to `SDL_CreateWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:300: undefined reference to `SDL_GetError'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::tryCreate(Magnum::Platform::Sdl2Application::Configuration const&, Magnum::Platform::Sdl2Application::GLConfiguration const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:359: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:360: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:361: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:362: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:363: undefined reference to `SDL_GL_SetAttribute'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj):C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:364: more undefined references to `SDL_GL_SetAttribute' follow
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::tryCreate(Magnum::Platform::Sdl2Application::Configuration const&, Magnum::Platform::Sdl2Application::GLConfiguration const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:435: undefined reference to `SDL_CreateWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:445: undefined reference to `SDL_GetError'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:450: undefined reference to `SDL_GL_CreateContext'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:486: undefined reference to `SDL_GetError'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:487: undefined reference to `SDL_GL_DeleteContext'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:489: undefined reference to `SDL_DestroyWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:491: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:492: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:493: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:495: undefined reference to `SDL_GL_SetAttribute'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:497: undefined reference to `SDL_CreateWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:502: undefined reference to `SDL_GetError'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:507: undefined reference to `SDL_GL_CreateContext'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:513: undefined reference to `SDL_GetError'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:514: undefined reference to `SDL_DestroyWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:580: undefined reference to `SDL_GL_DeleteContext'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:581: undefined reference to `SDL_DestroyWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:592: undefined reference to `SDL_ShowWindow'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::windowSize() const':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:604: undefined reference to `SDL_GetWindowSize'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setMinWindowSize(Magnum::Math::Vector2<int> const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:615: undefined reference to `SDL_SetWindowMinimumSize'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setMaxWindowSize(Magnum::Math::Vector2<int> const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:620: undefined reference to `SDL_SetWindowMaximumSize'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::framebufferSize() const':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:629: undefined reference to `SDL_GL_GetDrawableSize'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::swapBuffers()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:649: undefined reference to `SDL_GL_SwapWindow'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::swapInterval() const':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:656: undefined reference to `SDL_GL_GetSwapInterval'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setSwapInterval(int)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:660: undefined reference to `SDL_GL_SetSwapInterval'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:661: undefined reference to `SDL_GetError'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:666: undefined reference to `SDL_GL_GetSwapInterval'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::~Sdl2Application()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:681: undefined reference to `SDL_GL_DeleteContext'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:688: undefined reference to `SDL_DestroyWindow'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:690: undefined reference to `SDL_Quit'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::mainLoopIteration()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:715: undefined reference to `SDL_GetTicks'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:748: undefined reference to `SDL_PollEvent'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:857: undefined reference to `SDL_GetTicks'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:859: undefined reference to `SDL_Delay'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:869: undefined reference to `SDL_GetTicks'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:871: undefined reference to `SDL_Delay'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:876: undefined reference to `SDL_WaitEvent'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setMouseLocked(bool)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:883: undefined reference to `SDL_SetWindowGrab'
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:884: undefined reference to `SDL_SetRelativeMouseMode'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::isTextInputActive()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:893: undefined reference to `SDL_IsTextInputActive'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::startTextInput()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:900: undefined reference to `SDL_StartTextInput'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::stopTextInput()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:907: undefined reference to `SDL_StopTextInput'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::setTextInputRect(Magnum::Math::Range2D<int> const&)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:915: undefined reference to `SDL_SetTextInputRect'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::KeyEvent::keyName[abi:cxx11](Magnum::Platform::Sdl2Application::KeyEvent::Key)':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:996: undefined reference to `SDL_GetKeyName'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::MouseEvent::modifiers()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:1006: undefined reference to `SDL_GetModState'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::MouseMoveEvent::modifiers()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:1012: undefined reference to `SDL_GetModState'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::MouseScrollEvent::position()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:1018: undefined reference to `SDL_GetMouseState'
../magnum/src/Magnum/Platform/libMagnumSdl2Application-d.a(Sdl2Application.cpp.obj): In function `Magnum::Platform::Sdl2Application::MouseScrollEvent::modifiers()':
C:/Users/Kiryu/Dropbox/programming/cpp/Cubes/magnum/src/Magnum/Platform/Sdl2Application.cpp:1025: undefined reference to `SDL_GetModState'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [src\CMakeFiles\MyApplication.dir\build.make:91: ../bin/MyApplication.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:2302: src/CMakeFiles/MyApplication.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:2314: src/CMakeFiles/MyApplication.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:696: MyApplication] Error 2

My CMakeLists.txt in the root folder looks like this:

cmake_minimum_required(VERSION 3.1)
project(MyApplication)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH})

set(CMAKE_PREFIX_PATH "C:/Users/Kiryu/Dropbox/programming/cpp/Libraries/")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/")

set(WITH_SDL2APPLICATION ON CACHE BOOL "" FORCE)

add_subdirectory(corrade)
add_subdirectory(magnum)

add_subdirectory(src)

The one for the Project like this:

cmake_minimum_required(VERSION 3.1)
find_package(Magnum REQUIRED GL Sdl2Application)

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

set(CMAKE_PREFIX_PATH "C:/Users/Kiryu/Dropbox/programming/cpp/Libraries/")

add_executable(MyApplication MyApplication.cpp)

target_link_libraries(MyApplication PRIVATE
    Magnum::Application
    Magnum::GL
    Magnum::Magnum)

Where my file structure looks like this:

cpp
	Libraries
		SDL2-2.0.10
		(...)
	Cubes
		bin
		corrade
		magnum
		modules
		src
		.gitignore
		CMakeList.txt
		(...)

I am pretty sure its just some simple oversight somewhere.

Thanks in advance!

~ David

@Kiryu144

This comment has been minimized.

Copy link
Author

@Kiryu144 Kiryu144 commented Oct 7, 2019

Solved by making the following changes to the makefile:

cmake_minimum_required(VERSION 3.1)
project(MyApplication)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH})

set(CMAKE_PREFIX_PATH "C:/Users/Kiryu/Dropbox/programming/cpp/Libraries/")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/")

set(WITH_SDL2APPLICATION ON CACHE BOOL "" FORCE)

add_subdirectory(corrade)
add_subdirectory(magnum)

add_subdirectory(src)
@Kiryu144 Kiryu144 closed this Oct 7, 2019
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented Oct 8, 2019

Hi, sorry for not replying soon enough -- the external SDL dependency is the main pain point for Windows users at the moment and I'm desperately trying to find a better solution.

The last snippet you posted seems to be exactly the same as the one above, not sure if that was intended? :)

@mosra mosra added this to the 2019.0b milestone Oct 8, 2019
@mosra mosra added this to TODO in Platforms via automation Oct 8, 2019
@mosra mosra moved this from TODO to In progress in Platforms Oct 8, 2019
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented Oct 16, 2019

For the record, the Getting Started Guide got updated in 6b64ee6 and it should be now much easier to follow, with less pain points for Windows users.

@mosra mosra moved this from In progress to Done in Platforms Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Platforms
  
Done
2 participants
You can’t perform that action at this time.