0

I am trying to create a dynamic library written using pure "C" (libSetupConfig.so) and another one using "C++" (libUserAnalysis.so) such that the second one uses the functionality of the first one. The project is built using CMake.

The full source is here: https://github.com/evovch/Useful/tree/master/go4_5H_processor

Compilation runs fine. Output is here: https://github.com/evovch/Useful/blob/master/go4_5H_processor/compile.txt

When trying to use the library, I get a runtime error like that: go4analysis: symbol lookup error: .../build/src/libUserAnalysis.so: undefined symbol: _Z18InitStcSetupConfigP17_stc_setup_config

https://github.com/evovch/Useful/blob/master/go4_5H_processor/err.txt

So, I check that the symbol is present in the so:

nm libSetupConfig.so
...
0000000000001140 T InitStcSetupConfig
...

https://github.com/evovch/Useful/blob/master/go4_5H_processor/auxiliary/nm_output.txt

To be honest, I don't know how to interpret the full symbol string _Z18InitStcSetupConfigP17_stc_setup_config

My top CMakeLists.txt contains the following lines:

add_subdirectory(src)
add_subdirectory(setupconfig)

The CMakeLists.txt under src, which corresponds to the libUserAnalysis.so contains:

add_library(UserAnalysis SHARED ${SOURCE_LIB})
target_link_libraries(UserAnalysis Go4Analysis)
target_link_libraries(UserAnalysis SetupConfig)

The CMakeLists.txt under setupconfig which corresponds to libSetupConfig.so contains:

add_library(SetupConfig SHARED ${SOURCE_LIB})
add_executable(setup_config_test ${SOURCE_EXE})
target_link_libraries(setup_config_test SetupConfig)

From this I assume that the libUserAnalysis.so will be linked against libSetupConfig.so

I also check that the libSetupConfig.so library is linked when compiling the libUserAnalysis.so; see the last lines of https://github.com/evovch/Useful/blob/master/go4_5H_processor/compile.txt the necessary flags -L and -l are there -L/home/evovch/soft/go4-5.3.0_fairsoftroot/lib -Wl,-rpath,/home/evovch/soft/FairSoft_install/lib/root:/home/evovch/soft/go4-5.3.0_fairsoftroot/lib:/home/evovch/Documents/Useful/go4_5H_processor/build/setupconfig -lGo4Analysis ../setupconfig/libSetupConfig.so

PS. I understand that the problem most probably comes not from the fact that the languages are different.

evovch
  • 43
  • 7
  • 1
    Place relevant code in the question itself. SO is meant to be mostly self-contained. Please see [ask]. Additionally, work on creating a [mcve] – AndyG Apr 19 '18 at 11:47
  • 1
    [*Combining C++ and C - how does #ifdef __cplusplus work?*](https://stackoverflow.com/q/3789340/1171191). – BoBTFish Apr 19 '18 at 11:51
  • 2
    `c++filt _Z18InitStcSetupConfigP17_stc_setup_config` gives `initStcSetupConfig(_stc_setup_config*)` that menas you function declaration got mangled and to resolve against pure C lib you should have written the declaration of `initStcSetupConfig` in extern C block – g-217 Apr 19 '18 at 11:52
  • Thank you. These links helped me to solve the problem fast. I have enclosed my "C" functions' declarations with extern "C" and both g++-compiled full project and cc-compiled SetupConfig part do work. – evovch Apr 19 '18 at 12:13

0 Answers0