我有一个使用SDL2的项目。构建系统是cmake,我试图让它构建在windows上(它需要构建,因为它主要用于windows)。在linux上,它基于第一次尝试。在窗户上,我在过去的3个小时里一直在努力奋斗,没有运气。
在linux上,我刚刚安装了SDL软件包,但在Windows上我试图包含一个本地副本。我的CMakeLists.txt文件如下所示:
include_directories(../include)
# Add libraries for linux
if(UNIX)
enable_language(ASM)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL_PKG sdl2)
if(NOT SDL_PKG_FOUND)
message(FATAL_ERROR "No sdl found")
endif()
include_directories(${SDL_PKG_INCLUDE_DIRS})
LIST(APPEND LIBS ${SDL_PKG_LIBRARIES})
endif()
# Add libraries for windows
if(WIN32)
include_directories(../sdl-mingw/include/SDL2)
LIST(APPEND LIBS ${CMAKE_SOURCE_DIR}/sdl-mingw/lib/libSDL2.a)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-long-long")
set(SOURCES main.c paddles.c pong.c assets.S)
set_property(SOURCE assets.S PROPERTY LANGUAGE C)
add_executable(pong ${SOURCES})
target_link_libraries(pong ${LIBS})
install(TARGETS pong DESTINATION bin)
在构建项目时,我得到以下输出(滚动到底部以获得令人兴奋的部分):
-------------- Clean: all in pong (compiler: GNU GCC Compiler)---------------
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 clean
mingw32-make.exe[1]: Entering directory `C:/Users/Kevin/Documents/pong/build'
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f src\CMakeFiles\pong.dir\build.make src/CMakeFiles/pong.dir/clean
mingw32-make.exe[2]: Entering directory `C:/Users/Kevin/Documents/pong/build'
cd /d C:\Users\Kevin\Documents\pong\build\src && "C:\Program Files (x86)\CMake\bin\cmake.exe" -P CMakeFiles\pong.dir\cmake_clean.cmake
mingw32-make.exe[2]: Leaving directory `C:/Users/Kevin/Documents/pong/build'
mingw32-make.exe[1]: Leaving directory `C:/Users/Kevin/Documents/pong/build'
Cleaned "pong - all"
-------------- Build: all in pong (compiler: GNU GCC Compiler)---------------
Running command: C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f "C:/Users/Kevin/Documents/pong/build/Makefile" VERBOSE=1 all
"C:\Program Files (x86)\CMake\bin\cmake.exe" -HC:\Users\Kevin\Documents\pong -BC:\Users\Kevin\Documents\pong\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\Kevin\Documents\pong\build\CMakeFiles C:\Users\Kevin\Documents\pong\build\CMakeFiles\progress.marks
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory `C:/Users/Kevin/Documents/pong/build'
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f src\CMakeFiles\pong.dir\build.make src/CMakeFiles/pong.dir/depend
mingw32-make.exe[2]: Entering directory `C:/Users/Kevin/Documents/pong/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\Kevin\Documents\pong C:\Users\Kevin\Documents\pong\src C:\Users\Kevin\Documents\pong\build C:\Users\Kevin\Documents\pong\build\src C:\Users\Kevin\Documents\pong\build\src\CMakeFiles\pong.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory `C:/Users/Kevin/Documents/pong/build'
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f src\CMakeFiles\pong.dir\build.make src/CMakeFiles/pong.dir/build
mingw32-make.exe[2]: Entering directory `C:/Users/Kevin/Documents/pong/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\Kevin\Documents\pong\build\CMakeFiles 1
[ 33%]
Building C object src/CMakeFiles/pong.dir/main.c.obj
cd /d C:\Users\Kevin\Documents\pong\build\src && C:\PROGRA~2\CODEBL~1\MinGW\bin\gcc.exe -Wall -Wno-long-long @CMakeFiles/pong.dir/includes_C.rsp -o CMakeFiles\pong.dir\main.c.obj -c C:\Users\Kevin\Documents\pong\src\main.c
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\Kevin\Documents\pong\build\CMakeFiles 2
[ 66%]
Building C object src/CMakeFiles/pong.dir/paddles.c.obj
cd /d C:\Users\Kevin\Documents\pong\build\src && C:\PROGRA~2\CODEBL~1\MinGW\bin\gcc.exe -Wall -Wno-long-long @CMakeFiles/pong.dir/includes_C.rsp -o CMakeFiles\pong.dir\paddles.c.obj -c C:\Users\Kevin\Documents\pong\src\paddles.c
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\Kevin\Documents\pong\build\CMakeFiles 3
[100%] Building C object src/CMakeFiles/pong.dir/pong.c.obj
cd /d C:\Users\Kevin\Documents\pong\build\src && C:\PROGRA~2\CODEBL~1\MinGW\bin\gcc.exe -Wall -Wno-long-long @CMakeFiles/pong.dir/includes_C.rsp -o CMakeFiles\pong.dir\pong.c.obj -c C:\Users\Kevin\Documents\pong\src\pong.c
Linking C executable pong.exe
cd /d C:\Users\Kevin\Documents\pong\build\src && "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\pong.dir\link.txt --verbose=1
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\pong.dir/objects.a
C:\PROGRA~2\CODEBL~1\MinGW\bin\ar.exe cr CMakeFiles\pong.dir/objects.a @CMakeFiles\pong.dir\objects1.rsp
C:\PROGRA~2\CODEBL~1\MinGW\bin\gcc.exe -Wall -Wno-long-long -Wl,--whole-archive CMakeFiles\pong.dir/objects.a -Wl,--no-whole-archive -o pong.exe -Wl,--out-implib,libpong.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\pong.dir\linklibs.rsp
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x7c): undefined reference to `SDL_PollEvent'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x12a): undefined reference to `SDL_RenderCopy'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x393): undefined reference to `SDL_SetRenderDrawColor'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x3a0): undefined reference to `SDL_RenderClear'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x4a3): undefined reference to `SDL_RenderCopy'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x4d0): undefined reference to `SDL_SetRenderDrawColor'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x4e7): undefined reference to `SDL_RenderFillRect'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x4fe): undefined reference to `SDL_RenderFillRect'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x52b): undefined reference to `SDL_SetRenderDrawColor'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x55b): undefined reference to `SDL_RenderFillRect'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x58b): undefined reference to `SDL_RenderFillRect'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x598): undefined reference to `SDL_RenderPresent'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x5b9): undefined reference to `SDL_Init'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x5c2): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x61e): undefined reference to `SDL_CreateWindow'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x62c): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x66f): undefined reference to `SDL_CreateRenderer'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x677): undefined reference to `assets_font_size'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x682): undefined reference to `assets_font'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x687): undefined reference to `SDL_RWFromMem'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x695): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x6d0): undefined reference to `SDL_LoadBMP_RW'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x6e5): undefined reference to `SDL_CreateTextureFromSurface'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x6f4): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x727): undefined reference to `SDL_FreeSurface'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x72c): undefined reference to `assets_sprites_size'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x737): undefined reference to `assets_sprites'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x73c): undefined reference to `SDL_RWFromMem'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x74a): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x785): undefined reference to `SDL_LoadBMP_RW'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x79a): undefined reference to `SDL_CreateTextureFromSurface'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x7a9): undefined reference to `SDL_GetError'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x7dc): undefined reference to `SDL_FreeSurface'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x844): undefined reference to `SDL_DestroyTexture'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x84f): undefined reference to `SDL_DestroyRenderer'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x85a): undefined reference to `SDL_DestroyWindow'
CMakeFiles\pong.dir/objects.a(pong.c.obj):pong.c:(.text+0x85f): undefined reference to `SDL_Quit'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [src/pong.exe] Error 1
mingw32-make.exe[1]: *** [src/CMakeFiles/pong.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
mingw32-make.exe[2]: Leaving directory `C:/Users/Kevin/Documents/pong/build'
mingw32-make.exe[1]: Leaving directory `C:/Users/Kevin/Documents/pong/build'
Process terminated with status 2 (0 minute(s), 3 second(s))
37 error(s), 0 warning(s) (0 minute(s), 3 second(s))
令人兴奋的部分是所有未定义的符号。其中大多数来自SDL,但有些来自assets.S
(您可以看到here)。
为什么我的libSDL2.a
文件没有链接到可执行文件?
此外,为什么链接器也看不到我的assets.S
文件中的导出符号?
我检查了linklibs.rsp
文件,确实列出了libSDL2.a
。如果我更改名称,make会全部失望,所以我认为这意味着链接器正在读取文件。通常我可以弄清楚这些问题,但我在这方面根本没有取得任何进展。
肮脏的细节
Windows 8上的CMake
使用MinGW(使用代码:: blocks安装的那个)为Code :: Blocks配置的CMake构建
SDL 2.0.3