Cmake用全名寻找提升lib,而不是明确地说短提

时间:2017-04-04 16:32:40

标签: c++ visual-studio boost cmake bamboo

我正在开发一个使用boost编译库的项目。我想在Bamboo上运行回归。我的想法是当我在我的电脑上构建时使用我的系统路径中的boost,以及在竹子上构建时复制的libboost_program_options.lib。我复制了boost头文件和libboost_program_options,因此它们位于CMAKE_SOURCE_DIR / boost文件夹中。该库使用--layout = system编译,因此文件名为libboost_program_options.lib。

这就是我的cmake的样子

cmake_minimum_required (VERSION 3.4)
project (Project)

file(GLOB SOURCES src/*.cpp)

set (SOURCE_FILES main.cpp other.cpp)

if (WIN32)
    set (SOURCE_FILES ${SOURCE_FILES} many_other_windows.cpp )
endif (WIN32)

if (UNIX)
        set (SOURCE_FILES ${SOURCE_FILES} many_other_unix.cpp)
endif (UNIX)


set(Boost_USE_STATIC_LIBS ON)

# This is a hint for find_package to look for boost libs / includes in this dirs but it doesnt work
set(BOOST_INCLUDEDIR ${CMAKE_SOURCE_DIR}/boost)
set(BOOST_LIBRARYDIR ${CMAKE_SOURCE_DIR}/boost)

find_package(Boost 1.63.0 COMPONENTS program_options)

if(Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
  set(TARGET_LINK_LIBRARIES ${Boost_LIBRARIES})

else()
  include_directories(${CMAKE_SOURCE_DIR})
  link_directories(${CMAKE_SOURCE_DIR}/boost)
  if (WIN32)
      set(TARGET_LINK_LIBRARIES libboost_program_options)
  endif (WIN32)
  if (UNIX)
      set(TARGET_LINK_LIBRARIES libboost_program_options.a)
  endif (UNIX)
endif()


add_executable (Project ${SOURCE_FILES})


if (WIN32)
    set(TARGET_LINK_LIBRARIES ${TARGET_LINK_LIBRARIES} shlwapi)
endif (WIN32)


target_link_libraries(Project ${TARGET_LINK_LIBRARIES})

visual studio项目文件的一部分

输入路径/ project.vcxproj:

(...)
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;libboost_program_options.lib;shlwapi.lib</AdditionalDependencies>
(...)

并且调用链接器

04-Apr-2017 17:58:28      D:\MIDDLEWARE\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe /ERRORREPORT:QUEUE /OUT:"D:\bamboo-home\xml-data\build-dir\AS-CA-W64\Project\bin\Release\Project.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"D:/bamboo-home/xml-data/build-dir/AS-CA-W64/PostCompilator/boost" /LIBPATH:"D:/bamboo-home/xml-data/build-dir/AS-CA-W64/PostCompilator/boost/Release" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib libboost_program_options.lib shlwapi.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"D:/bamboo-home/xml-data/build-dir/AS-CA-W64/Project/bin/Release/Project.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/bamboo-home/xml-data/build-dir/AS-CA-W64/PostCompilator/bin/Release/Project.lib" /MACHINE:X64  /machine:x64 Project.dir\Release\main.obj

04-Apr-2017 17:58:28    LINK : fatal error LNK1104: cannot open file 'libboost_program_options-vc140-mt-1_64.lib' [D:\bamboo-home\xml-data\build-dir\AS-CA-W64\Project\build\Project\Project.vcxproj]
04-Apr-2017 17:58:28    Done Building Project "D:\bamboo-home\xml-data\build-dir\AS-CA-W64\Project\build\Project\Project.vcxproj" (default targets) -- FAILED.

注意在cmake中如何使用编译器名称和版本更改短名称。

任何人都知道如何让cmake找到那个库? 有没有人有任何建议我怎么能更好地使我的项目可以在我的电脑上建立系统路径的提升,如竹子我想要复制lib?也许有人更好地了解如何将boost集成到我的竹子项目中

祝你好运

1 个答案:

答案 0 :(得分:1)

原因是boost窗口标题添加了一些pragma,可以自动查找.lib文件自动填充它的名称。这是导致cmake查找库的全名的原因&#34; libboost_program_options-vc140-mt-1_64.lib&#34;。我通过添加:

解决了这个问题
add_definitions(-DBOOST_ALL_NO_LIB) # disabling of auto filling boost libs names to versioned