【问题标题】:Linking error with boost process (and other boost libs)与提升过程(和其他提升库)链接错误
【发布时间】:2014-04-04 23:01:22
【问题描述】:

这是我的代码。我只是在测试 Boost::process 所以我可以在需要时使用它。我不知道为什么我得到了我得到的链接错误。我是一个相当新手的 C++ 程序员。我知道这些概念,但我在实践中经常犯错误并且不擅长调试。感谢您在这方面获得的任何帮助。

#include<iostream>
#include<boost/process.hpp>
#include<boost/iostreams/device/file_descriptor.hpp>

namespace bp = ::boost::process;
namespace bpi = ::boost::process::initializers;
namespace bio = ::boost::iostreams;

int main(int argc, char *argv[])
{
  bp::pipe p = bp::create_pipe();
  bio::file_descriptor_sink sink(p.sink, bio::close_handle);

  bp::execute(
          bpi::run_exe("/usr/bin/ls"),
          bpi::bind_stdout(sink)
          );
  return(0);
}

这是我的错误……

/tmp/cc7cmrV8.o: In function `main':
test.cpp:(.text+0x2b): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
/tmp/cc7cmrV8.o: In function `boost::process::posix::initializers::bind_stdout::bind_stdout(boost::iostreams::file_descriptor_sink const&)':
test.cpp:(.text._ZN5boost7process5posix12initializers11bind_stdoutC2ERKNS_9iostreams20file_descriptor_sinkE[_ZN5boost7process5posix12initializers11bind_stdoutC5ERKNS_9iostreams20file_descriptor_sinkE]+0x2b): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/tmp/cc7cmrV8.o: In function `void boost::process::posix::initializers::bind_stdout::on_exec_setup<boost::process::posix::executor>(boost::process::posix::executor&) const':
test.cpp:(.text._ZNK5boost7process5posix12initializers11bind_stdout13on_exec_setupINS1_8executorEEEvRT_[_ZNK5boost7process5posix12initializers11bind_stdout13on_exec_setupINS1_8executorEEEvRT_]+0x18): undefined reference to `boost::iostreams::file_descriptor::handle() const'
collect2: error: ld returned 1 exit status

平台:Linux 64 位
Boost:1.55(通过 pacman 安装)
提升::进程:0.5
编译命令:g++ -Wall test.cpp -o spegh.elf -lboost_system

【问题讨论】:

    标签: c++ boost linker


    【解决方案1】:

    一个简单的搜索让我找到了-This-

    看到您发布了编译命令,我猜您只是在链接器设置中缺少-lboost_iostreams

    【讨论】:

    • 抱歉。我搜索但没有找到任何东西。我回家后会试试的。请原谅我的菜鸟问题,但是您链接的那个线程表明该链接器选项很明显。这对我来说并不明显。我在哪里查看需要哪些链接器选项以供将来参考?
    • @smalltock 因为有些事情对某些人来说很明显,但并不意味着对每个人来说都很明显,所以不要担心“新手”的问题。我不是 Boost 专家,但我首先要看的是文档/手册。 -Here- 是 boost 库的文档。该页面列出了每个库,我猜每个库都应该与-lboost_&lt;lib-name-here&gt; 链接(使用时),但我可能是错的。也许-Boost Getting started- 页面可能会提供一些额外的信息。 =]
    猜你喜欢
    • 2013-01-21
    • 2023-03-24
    • 2018-08-29
    • 1970-01-01
    • 2018-04-19
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多