CMake在linux中构build共享对象.so文件

任务 – >运行Cmake在Windows中生成DLL,在Linux中共享对象(.so文件)。

我将代码从windows移植到linux。 我已经在源代码中进行了必要的更改。 我试图改变CMakeLists.txt文件,但是当我试图做它抱怨“无法find源文件”。 愿你们指点我出错的地方。 CMakeList.txt如下所示。 cmake在Windows中运行良好,但在Linux中抱怨错误。
我已经评论了几行,并在CMakeLIsts.txt中添加行,使其在Linux中工作,但它不工作。

CMAKE_MINIMUM_REQUIRED( VERSION 2.8 ) CMAKE_POLICY( SET CMP0017 NEW ) PROJECT( disk_space_model ) INCLUDE( ../libs/helper_functions.cmake ) INCLUDE_THIRD_PARTY_SFC() SET( HEADER_FILES stdafx.h INS_sensor_model.h ) SET( SOURCE_FILES Disk_space_model.cpp ) SET( RESOURCE_FILES "Disk Space DLL.rc" resource.h ) COMMON_SETUP() SETUP_Lab_LIB_FILES( lib_foo lib_boo_files lib_platform lib_utils ) #ADD_DEFINITIONS(-D_USRDLL -DINSSENSORDLL_EXPORTS) #ADD_LIBRARY( disk_space_model SHARED ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} ${CMAKE_HELPER_FILES} ) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols") ADD_LIBRARY( disk_space_model [ STATIC | SHARED ] ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} ${CMAKE_HELPER_FILES} ) SET_OUTPUT_DIRS( disk_space_model ) TARGET_LINK_LIBRARIES( disk_space_model ${LIB_FILES} ) 

下面是我在CMake-gui上制作和生成后得到的以下错误

  4 bit compiler -- Configuring done CMake Error at CMakeLists.txt:37 (ADD_LIBRARY): Cannot find source file: [ Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error in CMakeLists.txt: Cannot find source file: STATIC Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error in CMakeLists.txt: Cannot find source file: | Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error in CMakeLists.txt: Cannot find source file: SHARED Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error in CMakeLists.txt: Cannot find source file: ] Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx -- Build files have been written to: /home/mydir/svn/proj1/apps/disk space make: *** [cmake_check_build_system] Error 1 

这是因为:

 ADD_LIBRARY( disk_space_model [ STATIC | SHARED ] ${SOURCE_FILES} ${HEADER_FILES} ${RESOURCE_FILES} ${CMAKE_HELPER_FILES} ) 

我想你是复制粘贴的[ STATIC | SHARED ] [ STATIC | SHARED ]从文档。 这应该是STATICSHARED (后者,在你的情况)的选择。