0

I have library which I have compiled on Ubuntu 18.04 using the version of gcc which comes bundled in the build-essential package, gcc 7.5.0.

If I then try to compile an application on Ubuntu 20.04 and link against the that library I previous built using the default gcc version, gcc 9.3.0, then I get a bunch of errors such as undefined reference to __expf_finite. Note, I do compile my original library with -Ofast as I need to take advantage of all optimizations. According to this SO question, it suggests that math-finite.h is no longer supported by the libc update.

So as a possible solution, I tried compiling my library on Ubuntu 20.04 using gcc 9.3.0 to then see if I can link against that library using an application compiled with gcc 7.5.0 on Ubuntu 18.04 (basically the reverse of the first scenario). However, when I do this, I get ABI compat errors with std::string:

./trueface_sdk/libtf.a(ocl.cpp.o): In function `cv::ocl::Kernel::set(int, cv::ocl::KernelArg const&)':
ocl.cpp:(.text._ZN2cv3ocl6Kernel3setEiRKNS0_9KernelArgE+0x375): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text._ZN2cv3ocl6Kernel3setEiRKNS0_9KernelArgE+0x49d): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
../trueface_sdk/libtf.a(ocl.cpp.o): In function `oclCleanupCallback.cold':
ocl.cpp:(.text.unlikely.oclCleanupCallback+0x36): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text.unlikely.oclCleanupCallback+0xcf): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text.unlikely.oclCleanupCallback+0x184): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
../trueface_sdk/libtf.a(ocl.cpp.o):ocl.cpp:(.text._ZN2cv3ocl6Device4ImplC2EPv[_ZN2cv3ocl6Device4ImplC5EPv]+0xb7b): more undefined references to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' follow
../trueface_sdk/libtf.a(sqlite3.c.o):(.data.rel+0xb0): undefined reference to `fcntl64'

I also get undefined reference to fcntl64.

So what is the solution? How can I compile a library that will be compatible with multiple version of gcc?

cyrusbehr
  • 1,100
  • 1
  • 12
  • 32
  • The issue isn't `-Ofast` per-se, that is common to all gcc/g++ versions from 4.6 on. With libraries and version differences, you usually run into soname issues (library version requirements). There will be small changes in how everything is glued together, for lack of better words, and ensuring library compatibility can be tricky, especially when you have told the compiler to go as wild as it wants to optimizing, even if that breaks some standard compliance. Back the optimization off to `-O2` and see if the same problems occur. (the runtime difference will be negligible) – David C. Rankin Apr 06 '21 at 22:18
  • The big culprit is likely to be a difference in glibc between your build environments. Check what version of glibc each has. A mismatch there can cause issue like you describe. – David C. Rankin Apr 06 '21 at 22:24

1 Answers1

0

Based on the comments, it looks like it is not compatible because of the use of the -Ofast compiler optimization flag.

cyrusbehr
  • 1,100
  • 1
  • 12
  • 32