Ela*_*782 3 c++ boost cmake visual-studio-2010
我有一个链接到boost_program_options的应用程序,其CMakeLists.txt看起来像
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES( ${SUBPROJECT_NAME} ${Boost_LIBRARIES} )
Run Code Online (Sandbox Code Playgroud)
我#define BOOST_ALL_NO_LIB在我的代码中使用之前包含<boost/program_options.hpp>禁用vs2010中boost的自动链接,因为我想通过cmake指定它以使其与linux兼容.
在Linux中,这段代码编译得很好(使用cmake,make和gcc).但在使用VS2010的Windows中,我得到了一个
2>App.obj : error LNK2001: unresolved external symbol "public: static unsigned int const boost::program_options::options_description::m_default_line_length" (?m_default_line_length@options_description@program_options@boost@@2IB)
2>App.obj : error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > boost::program_options::arg" (?arg@program_options@boost@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
Run Code Online (Sandbox Code Playgroud)
请注意,链接器找到了lib - 如果找不到它,我会得到更多未解决的外部错误.
我将问题跟踪到以下内容:http:
//lists.boost.org/boost-users/2009/11/54015.php,它很好地描述了正在发生的事情(这两个是全局变量).现在提出的解决方案是启用动态链接并链接到DLL.但这不是我想要做的,我想链接静态boost lib(我实际上是尝试做的,在VS中的App属性中Linker-> Input it list D:\boost\boost_1_47\lib\boost_program_options-vc100-mt-gd-1_47.lib.
我也尝试过添加
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
Run Code Online (Sandbox Code Playgroud)
到我的CMakeLists.txt但它没有改变任何东西.
任何想法如何解决这个问题?
更新:当与boost_program_options-vc100-mt-sgd-1_47.lib链接时,我得到了一大堆关于已在boost-lib中定义的CRT符号的新链接器错误.按照panickal的建议更改VS Runtime选项后,这些错误也消失了,并且正在运行.
您必须链接到静态库.尝试链接boost_program_options-vc100-mt-sgd-1_47.lib而不是boost_program_options-vc100-mt-gd-1_47.lib.
该s表示磁带库的静态版本.您可以查看Boost Library Naming以获取有关命名约定的更多详细信息.
更新:要解决了多重定义链接错误,在改变Visual Studio的运行时库选项,Configuration Properties / C/C++ / Code Generation / Runtime Library从 Multi-threaded Debug DLL (/MDd)到Multi-threaded Debug (/MTd).
| 归档时间: |
|
| 查看次数: |
5160 次 |
| 最近记录: |