首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在带有gcc4.7的linux x64平台上,增强协程和asio测试构建失败。

在带有gcc4.7的linux x64平台上,增强协程和asio测试构建失败。
EN

Stack Overflow用户
提问于 2013-07-26 09:36:09
回答 2查看 4.1K关注 0票数 2

我尝试构建boost asio提供的示例代码示例:http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/example/cpp11/spawn/echo_server.cpp

我复制了所有代码并将其放入cpp文件中,在linux上使用gcc4.7和cmake进行编译,使用boost协程和boost上下文库进行链接,但链接失败。

输出如下所示:

代码语言:javascript
复制
Linking CXX executable ../../../output/bin/unit_test
cd /home/watson/ID_project/build/server_linux_makefile_gcc/abc/test/unit/abc_async && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/unit_test.dir/link.txt --verbose=1
/usr/bin/c++   -std=c++11 -O3 -DNDEBUG  -pthread -lrt -ltcmalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free CMakeFiles/unit_test.dir/TestFileChannel.cpp.o CMakeFiles/unit_test.dir/TestStreamBuffer.cpp.o CMakeFiles/unit_test.dir/TestTimer.cpp.o CMakeFiles/unit_test.dir/TestThreadPool.cpp.o CMakeFiles/unit_test.dir/TestScheduler.cpp.o CMakeFiles/unit_test.dir/PCH.cpp.o CMakeFiles/unit_test.dir/main.cpp.o CMakeFiles/unit_test.dir/TestUDPNetwork.cpp.o CMakeFiles/unit_test.dir/TestTCPNetwork.cpp.o  -o ../../../output/bin/unit_test -rdynamic ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_unit_test_framework-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_context-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_coroutine-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_thread-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_filesystem-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libyaml-cpp.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libmongoc.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_system-gcc47-mt-1_54.a ../../../../../../install/thirdparty_linux_makefile_gcc/lib/libprotobuf.a
../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_coroutine-gcc47-mt-1_54.a(coroutine_context.o): In function `boost::coroutines::detail::coroutine_context::coroutine_context(void (*)(long), boost::coroutines::stack_context*)':
coroutine_context.cpp:(.text+0x103): undefined reference to `make_fcontext'
../../../../../../install/thirdparty_linux_makefile_gcc/lib/libboost_coroutine-gcc47-mt-1_54.a(coroutine_context.o): In function `boost::coroutines::detail::coroutine_context::jump(boost::coroutines::detail::coroutine_context&, long, bool)':
coroutine_context.cpp:(.text+0x1bc): undefined reference to `jump_fcontext'
collect2: error: ld returned 1 exit status
make[2]: *** [abc/output/bin/unit_test] Error 1

我打印.a文件中的符号表,发现符号jump_fcontext' andmake_fcontext‘存在:

代码语言:javascript
复制
nm libboost_context-gcc47-mt-1_54.a

make_x86_64_sysv_elf_gas.o:
                 U _GLOBAL_OFFSET_TABLE_
                 U _exit
000000000000002e t finish
0000000000000000 T make_fcontext

jump_x86_64_sysv_elf_gas.o:
0000000000000000 T jump_fcontext

有人能给我一些建议吗?我试着在每个地方搜索,但没有任何信息。

EN

回答 2

Stack Overflow用户

发布于 2013-07-26 21:52:47

尝试交换boost_contextboost_coroutine的链接顺序。

linker documentation声明:

...链接器按指定的顺序搜索和处理库和目标文件。因此,‘foo.o -lz bar.o’在文件foo.o之后但在bar.o之前搜索库‘z’。如果bar.o引用‘z’中的函数,则可能无法加载这些函数。

在这种情况下,Boost.Coroutine依赖于Boost.Context。因此,在链接时,boost_coroutine应该出现在boost_context之前。有关链接器排序的更多详细信息,请考虑阅读this answer。

票数 8
EN

Stack Overflow用户

发布于 2014-11-12 06:38:30

为此添加另一种可能性(特别是使用Boost上下文库)-如果是在Windows上的MinGW下构建的,使用早期版本的MASM可以生成不包含可链接符号的静态库,这是由于符号导出的方式所致。

解决方案是使用MASM 8重建Boost上下文。

有关这方面的更多信息,请参阅https://stackoverflow.com/a/26874113/1678468上的答案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17871486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档