由于第三方库名称冲突导致的Segfault

时间:2012-04-14 08:24:08

标签: c++ linker segmentation-fault hydra

我正在尝试使用sixense的专有sdk(游戏控制器的驱动程序)。看起来他们静态链接到boost :: thread。我的应用程序和它的一些依赖项也使用boost :: thread,我得到一个段错误。

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bd1bb5 in boost::thread::start_thread() () from /usr/lib/libboost_thread.so.1.42.0
(gdb) bt
#0  0x00007ffff7bd1bb5 in boost::thread::start_thread() () from /usr/lib/libboost_thread.so.1.42.0
#1  0x00007ffff79869bb in USBDetector::start_hotplug_thread() ()
   from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#2  0x00007ffff7986c7e in USBDetector::start(std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >, std::vector<unsigned int, std::allocator<unsigned int> >) () from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#3  0x00007ffff7987298 in USBManagerLinux::start(std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >, std::vector<unsigned int, std::allocator<unsigned int> >, int) () from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#4  0x00007ffff79842f3 in USBManager::start(std::vector<unsigned int, std::allocator<unsigned int> >, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >, std::vector<unsigned int, std::allocator<unsigned int> >, int) () from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#5  0x00007ffff79a03d6 in DriverMain::start(int) ()
   from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#6  0x00007ffff79a1e32 in sixenseInit ()
   from /home/joschu/Downloads/sixenseSDK_linux_OSX/samples/linux_x64/sixense_simple3d/libsixense_x64.so
#7  0x0000000000400d0d in main () at /home/joschu/bulletsim/src/hydra/hi.cpp:6

如果我切换项目链接的方式,我发现我的其他库最终调用了sixense的boost :: thread。

有没有解决这个问题的方法?

1 个答案:

答案 0 :(得分:2)

  

看起来他们静态链接到boost :: thread

您没有说明他们将boost::thread静态链接到的内容。我假设他们将其链接到libsixense_x64.so

有几种避免名称冲突的一般方法:

  1. 让sdk开发人员清理他们的行为。他们应该做的是静态链接提升和隐藏这个事实,例如通过使用-fvisibility = hidden进行编译,并仅导出其预期的接口,而不是导出所有内容(这听起来就是这样)。
  2. 如果您无法强制sdk开发人员进行清理,您可以通过dlopen RTLD_LOCAL绑定加载他们的sdk库。这使得使用sdk有点尴尬,但应该将其符号保留在全局动态链接器命名空间中。
  3. 最后,为了完整性:如果您使用的是Linux(您的消息建议但未说明),则可以使用dlmopen将sdk加载到完全独立的动态链接器命名空间中。与选项2相比,我没有看到任何优势,并且存在一些缺点。