从使用G++编译的C++应用程序my_app中,我正在从另一个共享库tool.so调用几个API(tool.so也是使用C++开发的(。来自tool.so的API调用的每个引用,我从GDB得到下面的分段错误。
Thread 1 "my_app" received signal SIGSEGV, Segmentation fault.
0x00007ffff61406cd in boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*) () from /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1
问题似乎是boost版本不匹配。myapp需要boost1.65,但是tool.so使用boost1.55编译。我正在静态链接两者,并得到分段错误。我修改了CmakeList.txt,使其动态链接my_app,工具。但是我仍然得到相同的分割错误。有什么建议吗?
CmakeLists.txtadd_library(工具共享导入(set_target_properties(工具properties IMPORTED_LOCATION${tool_LIB_DIR}/tool.so(target_link_libraries(my_app PRIVATE工具(
Thread 1 "my_app" received signal SIGSEGV, Segmentation fault.
0x00007ffff61406cd in boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*) () from /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1
int main(int argc, const char* argv[])
{
..
if(TOOL_Initialize() == TOOL_FAIL) ----> Call 1
{
std::cout <<" failed to initialize.n";
}
..
..
..
if(TOOL_DEVICE_GetCount(DEVICE_TYPE)!= TOOL_SUCCESS)--> call 2
{
cout << "Get CPU count API failed exiting" << endl ;
}
}
在调用1中出现分段错误,如果注释输出调用1,则在调用lib调用的任何位置进入调用2
通过添加此选项,target_link_options(my_app PUBLIC"LINKER:/home/fkamalmu/toollib_1_7_8/lib/linux/tool.so"(而不是以下方式链接add_library(工具共享导入(
set_target_properties(工具properties IMPORTED_LOCATION${tool_LIB_DIR}/tool.so(
target_link_libraries(my_app PRIVATE工具(