我现在正在使用CMake构建动态库,现在遇到的问题与为库添加文件有关。我的项目结构如下:
----src
|
thrid_party---boost_1_50_0----boost
| --- | ----libs
| --- | ---- | --- filesystem
| --- | ---- | --- | ------src
我的CMakeLists.txt文件位于
src
目录中,文件内容如下:cmake_minimum_required( VERSION 2.6 )
project (temp)
#build the third party library
include_directories( ${irisimp_SOURCE_DIR}/../third_party/boost_1_50_0)
set (boost_path
${irisimp_SOURCE_DIR}/../third_party/boost_1_50_0/libs)
set (BOOST_LIST
${boost_path}/filesystem/src/codecvt_error_category.cpp
${boost_path}/filesystem/src/operations.cpp
${boost_path}/filesystem/src/path.cpp
${boost_path}/filesystem/src/path_traits.cpp
${boost_path}/filesystem/src/portability.cpp
${boost_path}/filesystem/src/unique_path.cpp
${boost_path}/filesystem/src/utf8_codecvt_facet.cpp
${boost_path}/filesystem/src/windows_file_codecvt.cpp
${boost_path}/filesystem/src/windows_file_codecvt.hpp
)
add_library ( boost SHARED ${BOOST_LIST})
我运行该脚本没有问题,但是,输出的Visual Studio 10项目在
${boost_path}/filesystem/src
文件夹中未包含所有源文件。实际上,仅保留了windows_file_codecvt.cpp。因此,编译该项目将失败。我想知道我应该怎么做才能确保Visual Studio 10项目可以包含CMakeLists.txt中指示的所有源文件。 最佳答案
尝试将分号放在路径之间,如下所示:
set (BOOST_LIST
${boost_path}/filesystem/src/codecvt_error_category.cpp;
${boost_path}/filesystem/src/operations.cpp;
${boost_path}/filesystem/src/path.cpp;
${boost_path}/filesystem/src/path_traits.cpp;
${boost_path}/filesystem/src/portability.cpp;
${boost_path}/filesystem/src/unique_path.cpp;
${boost_path}/filesystem/src/utf8_codecvt_facet.cpp;
${boost_path}/filesystem/src/windows_file_codecvt.cpp;
${boost_path}/filesystem/src/windows_file_codecvt.hpp;
)
如果这不起作用,请尝试
add_library(boost SHARED
${boost_path}/filesystem/src/codecvt_error_category.cpp
${boost_path}/filesystem/src/operations.cpp
${boost_path}/filesystem/src/path.cpp
${boost_path}/filesystem/src/path_traits.cpp
...
${boost_path}/filesystem/src/windows_file_codecvt.hpp)
这可能有助于调试问题所在。
关于c++ - 用CMake添加文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12375231/