本人将多线程程序交叉编译后在板上执行,发现了一个让人费解的错误。
terminate called after throwing an instance of '__gnu_cxx::__concurrence_broadcast_error'
what(): __gnu_cxx::__concurrence_broadcast_error
查了一下出错原因,是arm工具链的pthread库没有正确复制到目标板,可通过使用arm-linux-g++ -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc解决问题。
--whole-archive 和 --no-whole-archive 是ld(gnu连接器)专有的命令行参数,所以要添加-Wl才能使之辨认到该参数,
--whole-archive 可以把 在其后面出现的静态库包含的函数和变量输出到动态库,
所以使用 -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc 选项可以将pthread库添加到可执行文件中,
这样子就解决了问题了。
本文介绍了一种在交叉编译多线程程序时遇到的问题及解决方案。主要原因是ARM工具链的pthread库未正确复制到目标板,通过添加特定的链接器参数解决了这一问题。
3019

被折叠的 条评论
为什么被折叠?



