将错误与升压过程(以及其他升压库)链接

时间:2014-04-04 23:01:23

标签: c++ boost linker

这是我的代码。我只是在测试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位
提升:1.55(通过pacman安装)
Boost :: process:0.5
编译命令:g++ -Wall test.cpp -o spegh.elf -lboost_system

1 个答案:

答案 0 :(得分:0)

一次简单的搜索让我感到-This-

看到你发布了编译命令,我猜你在链接器设置中只是遗漏了-lboost_iostreams