对`boost::program_options::options_description::m_default_line_length'的未定义引用
我正在尝试编译代码,但出现错误
I am trying to compile a code and I get the error
对boost::program_options::options_description::m_default_line_length的未定义引用
我在 Ubuntu 12.04 中使用 g++.虽然我做过一些 C++ 编程,但我是 Linux 开发环境的新手(以前只使用过 IDE).
I use g++ in Ubuntu 12.04. Although I have done some C++ programming I am new to the Linux development environment (used only IDEs previously).
所以我对这个问题进行了基本搜索,发现了一些链接问题.我不太了解他们,因为我是新手.阅读其中一些解决方案让我更加困惑.我的 boost 库文件夹位于 /usr/include
中.一些解决方案说它应该在 /usr/lib
中.但是我那里没有任何 boost 文件夹.
So I did a basic search for this trouble, and found about some linking issues. I didn't quite understand them as I am a newbie. Reading some of those solutions confused me further. My boost library folder is in /usr/include
. Some solutions says that it should be in /usr/lib
. But I don't have any boost folder there.
我需要改变什么?
推荐答案
如果你已经从 repo 安装了 boost,只需使用 -lboost_program_options
就足够了.
如果您在其他库中安装了 boost 库,则需要通过 -L/path/to/lib
If you have installed boost from repo just use -lboost_program_options
that will suffice.
If you installed boost libraries in some other library, you need to specify that directoty by -L/path/to/lib
在 CMake 中你可以指定 set(CMAKE_CXX_FLAGS "-lboost_program_options")
In CMake you may specify set(CMAKE_CXX_FLAGS "-lboost_program_options")
但是你应该使用 CMake
However with CMake you should use
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(target ${Boost_LIBRARIES})
相关文章