0

I have compiled a library A with g++ 7.5 that references in a implementation file (.cpp) a class of another library B. But the referenced library B is not added as a dependency to library A.

app -> libA.so -> libB.so

When I run this library A with msvc & Windows, I get no error at application runtime. When run with gcc & linux, there is a undefined symbol error at application runtime.

Why is that? Why is the application running fine under windows, but not under linux? It compiles and links fine under both OS.

martin
  • 11
  • 1
  • 1
    That's odd. Are you manually loading library `A` with `dlopen` on linux? Are you using `RTLD_LAZY` binding? Is the undefined symbol something you expect to be in `B`? Are templates involved? – Ted Lyngmo Aug 17 '20 at 20:24
  • Can you edit your question to show exactly how you are linking on both OSs? Are you using something like CMake to generate build scripts? – 0x5453 Aug 17 '20 at 20:27
  • Yes, I actually use cmake to link the libraries on linux. The generated executable is linked to libA.so. On windows I use Visual Studio/msbuild. – martin Aug 17 '20 at 20:40
  • 1
    I think you need to set the CMAKE_INSTALL_RPATH in Linux . For reference https://stackoverflow.com/questions/32469953/why-is-cmake-designed-so-that-it-removes-runtime-path-when-installing/32470070#32470070 – user3389943 Aug 17 '20 at 20:47
  • 1
    Please provide a [mre] – Alan Birtles Aug 17 '20 at 21:26
  • I put up a zip file including the Visual Studio project files as well as the corresponding cmake files: https://file.io/w12752O38Iaw – martin Aug 19 '20 at 23:37
  • In the app/bin folder the binaries are included. The windows side is based on the app.sln file, the linux side is based on the build.sh file. It took me some time and I was not able to reproduce the error with this small solution. But: If you evaluate the libB.so (nm -u -C libB.so) and compare it to the libB.dll (depwalker), you see that the dll doesn't contain a "typeinfo for A". So question is: why is the symbol for class A exported on the linux build, but not on the windows build? Seems to be some cmake configuration.. – martin Aug 19 '20 at 23:43

0 Answers0