如何使用 -Ofast 保持 gcc 7 和 gcc 9 之间的兼容性
How to maintain compatibility between gcc 7 and gcc 9 with -Ofast
我有一个库,我在 Ubuntu 18.04 上使用捆绑在 build-essential
包 gcc 7.5.0 中的 gcc 版本编译。
如果我随后尝试在 Ubuntu 20.04 和 link 上针对我之前使用默认 gcc 版本 gcc 9.3.0 构建的那个库编译应用程序,那么我会得到一堆未定义引用 __expf_finite
等错误。请注意,我确实使用 -Ofast
编译我的原始库,因为我需要利用所有优化。根据 this SO 问题,它表明 math-finite.h
不再被 libc 更新支持。
因此,作为一个可能的解决方案,我尝试使用 gcc 9.3.0 在 Ubuntu 20.04 上编译我的库,然后看看我是否可以 link 使用用 gcc 7.5 编译的应用程序针对该库。 Ubuntu 18.04 上的 0(基本上与第一种情况相反)。
但是,当我这样做时,出现 std::string
:
的 ABI 兼容错误
./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'
我还得到了对 fcntl64
的未定义引用。
那么解决方法是什么?如何编译与多个版本的 gcc 兼容的库?
根据评论,它看起来不兼容,因为使用了 -Ofast
编译器优化标志。
我有一个库,我在 Ubuntu 18.04 上使用捆绑在 build-essential
包 gcc 7.5.0 中的 gcc 版本编译。
如果我随后尝试在 Ubuntu 20.04 和 link 上针对我之前使用默认 gcc 版本 gcc 9.3.0 构建的那个库编译应用程序,那么我会得到一堆未定义引用 __expf_finite
等错误。请注意,我确实使用 -Ofast
编译我的原始库,因为我需要利用所有优化。根据 this SO 问题,它表明 math-finite.h
不再被 libc 更新支持。
因此,作为一个可能的解决方案,我尝试使用 gcc 9.3.0 在 Ubuntu 20.04 上编译我的库,然后看看我是否可以 link 使用用 gcc 7.5 编译的应用程序针对该库。 Ubuntu 18.04 上的 0(基本上与第一种情况相反)。
但是,当我这样做时,出现 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'
我还得到了对 fcntl64
的未定义引用。
那么解决方法是什么?如何编译与多个版本的 gcc 兼容的库?
根据评论,它看起来不兼容,因为使用了 -Ofast
编译器优化标志。