我尝试将cmake与外部库一起使用,但我不能。我使用minGW和g ++编译器。 我的项目组织如下: 项目/
cmake生成器工作`cmake -G" Eclipse CDT4 - Unix Makefiles"
我的cmake文件: `
#
# File generated by CMakeBuilder
#
#
cmake_minimum_required(VERSION 2.6)
PROJECT ( project CXX )
################ INCLUDE Libs ####################
SET (CMAKE_INCLUDE_PATH "${PROJECT_SOURCE_DIR}/include/")
SET (CMAKE_LINKER_PATH "${PROJECT_SOURCE_DIR}/lib/win/x86/SDL2-2.0.3/")
message(STATUS "INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}" )
message(STATUS "LINKER_PATH: ${CMAKE_LINKER_PATH}" )
INCLUDE_DIRECTORIES(${CMAKE_INCLUDE_PATH})
LINK_DIRECTORIES(${CMAKE_LINKER_PATH})
set (CMAKE_CXX_FLAGS "-lSDL2main -lSDL2 -lmingw32 ")
#Generate file source
file( GLOB_RECURSE source_files src/*)
ADD_EXECUTABLE(project ${source_files})
set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
但是当我启动make时,我得到了这个错误:
`
CMakeFiles/project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x0): multiple
definition of main
C:/Users/Gege/workspaces/workspaceCPP/project/lib/win/x86/SDL2-2.0.3/SDL2m
ain.lib(./Release/SDL_windows_main.obj):(.text[_main]+0x0): first defined here
Warning: corrupt .drectve at end of def file
C:/Users/Gege/workspaces/workspaceCPP/project/lib/win/x86/SDL2-2.0.3/SDL2m
ain.lib(./Release/SDL_windows_main.obj):(.text[_main]+0x12): undefined reference
to SDL_main'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:/Users/Gege/workspaces/workspaceCPP/project/lib/win/x86/SDL2- 2.0.3/SDL2main.lib(./
Release/SDL_windows_main.obj): bad reloc address 0x8 in section .text[_WinMain@
16]'
collect2.exe: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:87: recipe for target 'bin/project.exe'
failed
make[2]: *** [bin/project.exe] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/project.dir/all' faile
d
make[1]: *** [CMakeFiles/arduinoGeo.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2
` 实际上我不想把我的lib放在minGW文件夹中以保持其他人的构建。
谢谢你的帮助