Search code examples
c++boostsegmentation-fault

Thread 1 "my_app" received signal SIGSEGV, Segmentation fault when accessing API from another library


From my C++ application my_app compiled using G++, I am invoking several API's from another shared library tool.so (tool.so also developed using C++). Each reference of API call from tool.so I am getting the below segmentation fault from the 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

problem seem to be boost version mismatch. myapp needs boost 1.65 but tool.so compiled using boost 1.55. I am statically linking both and get segmentation error. I modified the CmakeList.txt, so that it dynamically links my_app, tool. but still I get the same segmentation error. any suggestion?

CmakeLists.txt add_library(tool SHARED IMPORTED) set_target_properties(tool PROPERTIES IMPORTED_LOCATION ${TOOL_LIB_DIR}/tool.so) target_link_libraries(my_app PRIVATE tool)

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 ; 
    }
}    

Getting segmentation fault in call 1, if comment out call 1 then getting in call 2 wherever I am invoking lib call


Solution

  • it worked by adding this option, target_link_options(my_app PUBLIC "LINKER:/home/fkamalmu/toollib_1_7_8/lib/linux/tool.so") instead of below way of linking add_library(tool SHARED IMPORTED)

    set_target_properties(tool PROPERTIES IMPORTED_LOCATION ${TOOL_LIB_DIR}/tool.so)

    target_link_libraries(my_app PRIVATE tool)