gcc - Linking SDL2 and Clion -


i have clion pointing sdl2 directories , libs, fails link libraries when try build. ideas on how fix this?

cmakelists:

cmake_minimum_required(version 3.3)  project(cavestory_development)  set(cmake_c_flags "${cmake_c_flags} -wall -werror -lsdl2")  set(sdl2_include_dir c:/sdl2-2.0.3/i686-w64-mingw32/include/sdl2)  set(sdl2_library c:/sdl2-2.0.3/i686-w64-mingw32/lib)  find_package(sdl2 required)  include_directories(${sdl2_include_dir})  set(source_files main.cpp)  add_executable(cavestory_development ${source_files})  target_link_libraries(cavestory_development ${sdl2_library}) 

build errors:

"c:\program files (x86)\jetbrains\clion 1.1\bin\cmake\bin\cmake.exe" --build c:\users\conne_000\.clion11\system\cmake\generated\8a943732\8a943732\debug --target cavestory_development -- -j 8 [ 50%] linking cxx executable cavestory_development.exe cmakefiles\cavestory_development.dir/objects.a(main.cpp.obj): in function `sdl_main': c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:11: undefined reference `sdl_init' c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:21: undefined reference `sdl_createwindow' c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:26: undefined reference `sdl_geterror' c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:32: undefined reference `sdl_delay' c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:35: undefined reference `sdl_destroywindow' c:/users/conne_000/documents/clionprojects/cavestory_development/main.cpp:38: undefined reference `sdl_quit' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference `winmain@16' collect2.exe: error: ld returned 1 exit status mingw32-make.exe[3]: *** [cavestory_development.exe] error 1 cmakefiles\cavestory_development.dir\build.make:96: recipe target 'cavestory_development.exe' failed cmakefiles\makefile2:66: recipe target 'cmakefiles/cavestory_development.dir/all' failed mingw32-make.exe[2]: *** [cmakefiles/cavestory_development.dir/all] error 2 mingw32-make.exe[1]: *** [cmakefiles/cavestory_development.dir/rule] error 2 cmakefiles\makefile2:78: recipe target 'cmakefiles/cavestory_development.dir/rule' failed mingw32-make.exe: *** [cavestory_development] error 2 makefile:117: recipe target 'cavestory_development' failed 

here minimal example started sdl2 on windows (main.cpp contains hello sdl lazyfoo)

cmake_minimum_required(version 3.0) project(hello_sdl2)  # configure sdl (cf. "sdl2-2.0.3\i686-w64-mingw32\lib\pkgconfig\sdl2.pc") # c++ flags set(sdl2_flags "-mwindows -wl,--no-undefined -static-libgcc") # library paths set(sdl2_root     "d:/path/to/sdl2-2.0.3/i686-w64-mingw32") set(sdl2_includes "${sdl2_root}/include") set(sdl2_libdir   "${sdl2_root}/lib") # imported targets cmake (cf. https://cmake.org/wiki/cmake/tutorials/exporting_and_importing_targets) add_library(sdl2     static imported) add_library(sdl2main static imported) set_property(target sdl2     property imported_location "${sdl2_libdir}/libsdl2.a") set_property(target sdl2main property imported_location "${sdl2_libdir}/libsdl2main.a") # libs link against # note: gcc, order important... set(sdl2_libs mingw32 sdl2 sdl2main m dinput8 dxguid dxerr8 user32 gdi32 winmm imm32 ole32 oleaut32 shell32 version uuid)  # configure project # include sdl flags set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11 ${sdl2_flags}") # collect sources set(source_files main.cpp) # define target add_executable(hello_sdl2 ${source_files}) # include sdl headers target_include_directories(hello_sdl2 system private ${sdl2_includes}) # link against sdl (and dependencies) target_link_libraries(hello_sdl2 ${sdl2_libs}) 

tested on win8.1 64bits sdl2-2.0.3, mingw-w64 i686-5.2.0-posix-dwarf-rt_v4-rev0 , clion 1.2 eap (build 142.5239.6)


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -