cmake和外部库

时间:2015-02-23 18:06:17

标签: c++ cmake

我尝试将cmake与外部库一起使用,但我不能。我使用minGW和g ++编译器。 我的项目组织如下: 项目/

  • 的CMakeLists.txt
  • SRC
    • 的main.cpp
  • LIB
      • 86
        • SDL2-2.0.3(包含SDL2.dll,SDL2.lib,SDL2main.lib和SDL2test.lib
  • 包括
    • SDL2(包含所有标题)

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文件夹中以保持其他人的构建。

谢谢你的帮助

0 个答案:

没有答案