[Bug]: undefined reference to `absl::lts_20211102::
Describe the issue
Hi, I have built abseil from source, but when I compile other projects using absl, I got a lot undefined reference to absl::lts_20211102:: .....` errors.
git clone https://github.com/abseil/abseil-cpp.git --recursive
cd abseil-cpp
git checkout 20211102.0
git submodule update --init --recursive
mkdir build && cd build
cmake -DCMAKE_CXX_STANDARD=17 -DABSL_CXX_STANDARD=17 -DABSL_USE_GOOGLETEST_HEAD=ON -DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined -Wl,--no-undefined\" -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DBUILD_SHARED_LIBS=ON -DNDEBUG=1 ..
make -j
make -j install
I notice that after I built it, for example, there is a
absl::variant_internal::ThrowBadVariantAccess()
in the file, but is there any way we can set the namespace to be as defined in /mydir/abseil-cpp/absl/base/options.h, Line 208~209:
#define ABSL_OPTION_USE_INLINE_NAMESPACE 1
#define ABSL_OPTION_INLINE_NAMESPACE_NAME lts_20211102
As when compiling my other project, it always raises the error like this:
../libtritonserver.so: undefined reference to `absl::lts_20211102::variant_internal::ThrowBadVariantAccess()'
Steps to reproduce the problem
As listed above
What version of Abseil are you using?
20211102.0, but I have also tried multiple other versions
What operating system and version are you using?
RHEL 8
What compiler and version are you using?
gcc 8.5
What build system are you using?
cmake 3.26
Additional context
No response
I think this is unlikely to be an Abseil bug and probably has nothing to do with the namespace. It's more likely that your build command is missing linker inputs. You need to provide instructions to build your whole project for us to look into this.
Hi, @derekmauro , thanks for the reply.
Sure, so my project does not directly use Absl, but instead, it has dependencies on GRPC, GoogleTest, and Google-cloud-cpp. After building absl, I also built them using the following command:
For GRPC:
export absl_DIR=/mydir/abseil-cpp/build/install/lib64/cmake/absl
git clone --recurse-submodules -b v1.48.0 https://github.com/grpc/grpc.git
cd grpc
mkdir build && cd build
cmake -DCMAKE_CXX_STANDARD=17 -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_PREFIX_PATH=/mydir/abseil-cpp/build/install ..
make -j
make -j install
For GoogleTest,
export absl_DIR=/mydir/abseil-cpp/build/install/lib64/cmake/absl
git clone https://github.com/google/googletest.git
cd googletest
git checkout v1.8.x
git submodule update --init --recursive
mkdir build
cd build
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_CXX_FLAGS="-lboost_regex" -DCMAKE_PREFIX_PATH="/mydir/boost_1_78_0/install" ..
make -j
make -j install
For google-cloud-cpp,
git clone https://github.com/googleapis/google-cloud-cpp.git --recurse-submodules
cd google-cloud-cpp
git checkout v2.8.0
git submodule update --init --recursive
mkdir build && cd build
cmake -DCMAKE_CXX_STANDARD=17 DCMAKE_PREFIX_PATH=/mydir/abseil-cpp/build/install -DgRPC_ROOT=/mydir/grpc/build/install -DGTest_ROOT=/mydir/googletest/build/install -DGMOCK_ROOT=/mydir/googletest/build/install -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ..
make -j
make -j install
And finally, when compiling my project, I pass googletest, grpc, google-cloud-cpp dir to CMAKE_PREFIX_PATH.
Hey @YJHMITWEB did you managed to solve your problem ?