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

时间:2013-03-04 10:44:20

标签: c++ linux windows cmake

任务 - >运行Cmake在windows中生成dll,在linux中生成共享对象(.so文件)。

我将代码从windows移植到linux。我在源代码中进行了必要的更改。我尝试过更改CMakeLists.txt文件但是当我试图让它抱怨“无法找到源文件”时。请你们指点我错误的地方。 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

1 个答案:

答案 0 :(得分:3)

因为这个原因而被打破:

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

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