C++ 无法链接到boost库

C++ 无法链接到boost库,c++,boost,g++,ubuntu-14.04,boost-coroutine,C++,Boost,G++,Ubuntu 14.04,Boost Coroutine,我无法让我的g++在我的机器上编译和链接一个最小的boost协同例程程序(我猜还有其他组件) // example.cpp #include <boost/coroutine/all.hpp> #include <iostream> using namespace boost::coroutines; void mycorofunc(coroutine<void>::push_type &sink){ std::cout << "1

我无法让我的g++在我的机器上编译和链接一个最小的boost协同例程程序(我猜还有其他组件)

// example.cpp

#include <boost/coroutine/all.hpp>
#include <iostream>
using namespace boost::coroutines;

void mycorofunc(coroutine<void>::push_type &sink){
  std::cout << "1";
  sink();
  std::cout << " 3";
}

int main() {
  coroutine<void>::pull_type source{mycorofunc};
  std::cout << " 2";
  source();
  std::cout << " 4!" << std::endl;
}
也不是

工作。g++的输出如下:

In file included from /usr/include/boost/coroutine/v1/coroutine.hpp:19:0,
                 from /usr/include/boost/coroutine/coroutine.hpp:13,
                 from /usr/include/boost/coroutine/all.hpp:11,
                 from example.cpp:3:
/usr/include/boost/type_traits/function_traits.hpp: In instantiation of ‘struct boost::function_traits<void>’:
example.cpp:7:31:   required from here
/usr/include/boost/type_traits/function_traits.hpp:168:8: error: invalid use of incomplete type ‘struct boost::detail::function_traits_helper<void*>’
 struct function_traits : 
        ^
/usr/include/boost/type_traits/function_traits.hpp:21:36: error: declaration of ‘struct boost::detail::function_traits_helper<void*>’
 template<typename Function> struct function_traits_helper;
                                    ^
example.cpp:7:31: error: ‘arity’ is not a member of ‘boost::function_traits<void>’
 void mycorofunc(coroutine<void>::push_type &sink){
                               ^
example.cpp:7:31: error: template argument 2 is invalid
example.cpp:7:44: error: expected ‘,’ or ‘...’ before ‘&’ token
 void mycorofunc(coroutine<void>::push_type &sink){
                                            ^
example.cpp: In function ‘void mycorofunc(int)’:
example.cpp:9:8: error: ‘sink’ was not declared in this scope
   sink();
        ^
example.cpp: In function ‘int main()’:
example.cpp:14:17: error: ‘arity’ is not a member of ‘boost::function_traits<void>’
   coroutine<void>::pull_type source{mycorofunc};
                 ^
example.cpp:14:17: error: template argument 2 is invalid
example.cpp:14:30: error: expected initializer before ‘source’
   coroutine<void>::pull_type source{mycorofunc};
                              ^
example.cpp:16:10: error: ‘source’ was not declared in this scope
   source();
在/usr/include/boost/coroutine/v1/coroutine.hpp:19:0中包含的文件中,
从/usr/include/boost/coroutine/coroutine.hpp:13,
从/usr/include/boost/coroutine/all.hpp:11,
来自示例。cpp:3:
/usr/include/boost/type_traits/function_traits.hpp:在“struct boost::function_traits”的实例化中:
示例.cpp:7:31:此处为必填项
/usr/include/boost/type\u traits/function\u traits.hpp:168:8:错误:无效使用不完整的类型“struct boost::detail::function\u traits\u helper”
结构功能特性:
^
/usr/include/boost/type_traits/function_traits.hpp:21:36:错误:“struct boost::detail::function_traits_helper”的声明
模板结构函数\u特征\u辅助对象;
^
示例.cpp:7:31:错误:“arity”不是“boost::function\u traits”的成员
void mycrofunc(协同程序::推送类型和接收器){
^
示例.cpp:7:31:错误:模板参数2无效
示例.cpp:7:44:错误:在“&”标记之前应为“,”或“…”
void mycrofunc(协同程序::推送类型和接收器){
^
example.cpp:在函数“void mycrofunc(int)”中:
示例.cpp:9:8:错误:未在此作用域中声明“接收器”
水槽();
^
example.cpp:在函数“int main()”中:
示例.cpp:14:17:错误:“arity”不是“boost::function\u traits”的成员
协同程序::pull_类型源{mycrofunc};
^
示例.cpp:14:17:错误:模板参数2无效
示例.cpp:14:30:错误:应在“source”之前使用初始值设定项
协同程序::pull_类型源{mycrofunc};
^
示例.cpp:16:10:错误:“源”未在此范围内声明
来源();
有关我的环境的更多信息:

$$ locate coroutine/all.hpp
/usr/include/boost/coroutine/all.hpp
/usr/local/boost_1_58_0/boost/coroutine/all.hpp

$$ locate boost_system
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0

$$ locate boost_coroutine
/usr/lib/x86_64-linux-gnu/libboost_coroutine.a

$$ g++ -E -x c++ - -v < /dev/null  # printing g++ include path 
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 
COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE - -mtune=generic -march=x86-64 -fstack-protector -Wformat -Wformat-security
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
# 1 "<stdin>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
$$locate coroutine/all.hpp
/usr/include/boost/coroutine/all.hpp
/usr/local/boost_1_58_0/boost/coroutine/all.hpp
$$定位增压系统
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
$$locate boost\u协同程序
/usr/lib/x86_64-linux-gnu/libboost_corroutine.a
$g++-ex+c+-v
编译器:已经尝试过g++(4.8.2版)和g++-5


发行版:Ubuntu14.04.1LTS

经过几天的调试,这就是我找到的解决方案。有可能即使是以下指令的一个子集也足以解决这个问题

没有太多细节的快速说明 执行以下说明:

  • 安装
    g++-6
    (支持
    c++14
    5.2
    更新的任何版本都将 最有可能的工作,以及,虽然我没有测试他们)
  • 安装boost
    1.58
    或更新版本(支持协同程序2)。自 这篇文章是Ubuntu PPA中提供的最新版本
    1.54
    。因此,您需要手动In file included from /usr/include/boost/coroutine/v1/coroutine.hpp:19:0, from /usr/include/boost/coroutine/coroutine.hpp:13, from /usr/include/boost/coroutine/all.hpp:11, from example.cpp:3: /usr/include/boost/type_traits/function_traits.hpp: In instantiation of ‘struct boost::function_traits<void>’: example.cpp:7:31: required from here /usr/include/boost/type_traits/function_traits.hpp:168:8: error: invalid use of incomplete type ‘struct boost::detail::function_traits_helper<void*>’ struct function_traits : ^ /usr/include/boost/type_traits/function_traits.hpp:21:36: error: declaration of ‘struct boost::detail::function_traits_helper<void*>’ template<typename Function> struct function_traits_helper; ^ example.cpp:7:31: error: ‘arity’ is not a member of ‘boost::function_traits<void>’ void mycorofunc(coroutine<void>::push_type &sink){ ^ example.cpp:7:31: error: template argument 2 is invalid example.cpp:7:44: error: expected ‘,’ or ‘...’ before ‘&’ token void mycorofunc(coroutine<void>::push_type &sink){ ^ example.cpp: In function ‘void mycorofunc(int)’: example.cpp:9:8: error: ‘sink’ was not declared in this scope sink(); ^ example.cpp: In function ‘int main()’: example.cpp:14:17: error: ‘arity’ is not a member of ‘boost::function_traits<void>’ coroutine<void>::pull_type source{mycorofunc}; ^ example.cpp:14:17: error: template argument 2 is invalid example.cpp:14:30: error: expected initializer before ‘source’ coroutine<void>::pull_type source{mycorofunc}; ^ example.cpp:16:10: error: ‘source’ was not declared in this scope source();
    $$ locate coroutine/all.hpp
    /usr/include/boost/coroutine/all.hpp
    /usr/local/boost_1_58_0/boost/coroutine/all.hpp
    
    $$ locate boost_system
    /usr/lib/x86_64-linux-gnu/libboost_system.a
    /usr/lib/x86_64-linux-gnu/libboost_system.so
    /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
    
    $$ locate boost_coroutine
    /usr/lib/x86_64-linux-gnu/libboost_coroutine.a
    
    $$ g++ -E -x c++ - -v < /dev/null  # printing g++ include path 
    Using built-in specs.
    COLLECT_GCC=g++
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 
    COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE - -mtune=generic -march=x86-64 -fstack-protector -Wformat -Wformat-security
    ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
    ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
    ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/include/c++/4.8
     /usr/include/x86_64-linux-gnu/c++/4.8
     /usr/include/c++/4.8/backward
     /usr/lib/gcc/x86_64-linux-gnu/4.8/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    End of search list.
    # 1 "<stdin>"
    # 1 "<command-line>"
    # 1 "/usr/include/stdc-predef.h" 1 3 4
    # 1 "<command-line>" 2
    # 1 "<stdin>"
    COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
    LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
    COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    
    ... undefined reference to `ontop_fcontext'  `boost::context::basic_fixedsize_stack<boost::context::stack_traits>::deallocate(boost::context::stack_context&)':
    example.cpp:(...): undefined reference to `boost::context::stack_traits::minimum_size()'
    example.cpp:(...): undefined reference to `boost::context::stack_traits::is_unbounded()'
    example.cpp:(...): undefined reference to `boost::context::stack_traits::maximum_size()'
    
    #include <boost/config.hpp> 
    
    #if defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) || \
         defined(BOOST_NO_CXX11_CONSTEXPR) || \
         defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || \
         defined(BOOST_NO_CXX11_FINAL) || \
         defined(BOOST_NO_CXX11_HDR_TUPLE) || \
         defined(BOOST_NO_CXX11_NOEXCEPT) || \
         defined(BOOST_NO_CXX11_NULLPTR) || \
         defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
         defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) || \
         defined(BOOST_NO_CXX11_UNIFIED_INITIALISATION_SYNTAX) || \
         defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || \
         defined(BOOST_NO_HDR_ATOMIC) || \
         defined(BOOST_NO_HDR_TUPLE)
    #error "execution_context is prevented to be included in this compiler"; 
    #endif