对`boost::program_options::options_description::m_default_line_length'的未定义引用 [英] undefined reference to `boost::program_options::options_description::m_default_line_length'

查看:22
本文介绍了对`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})

这篇关于对`boost::program_options::options_description::m_default_line_length'的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆