【问题标题】:boost coroutine and asio test build failed on linux x64 platform with gcc4.7使用 gcc4.7 在 linux x64 平台上提升协程和 asio 测试构建失败
【发布时间】:2013-07-26 03:23:06
【问题描述】:

我尝试构建 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上下文库链接,但是链接失败了。

输出如下:

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'是存在的:

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

有人可以给我任何提示吗?我尝试在每个地方都用谷歌搜索,但没有信息。

【问题讨论】:

    标签: linux boost hyperlink boost-asio coroutine


    【解决方案1】:

    尝试交换boost_context和boost_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 答案。

    【讨论】:

      【解决方案2】:

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

      解决方案是使用 MASM 8 重建 Boost Context。

      有关此问题的更多信息,请参阅https://stackoverflow.com/a/26874113/1678468 的答案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-15
        • 2022-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多