-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cmake links all abseil components and results in a link time error #225
Comments
Also, my Appveyor and Travis build fail with nonsense errors. Appveyor: https://ci.appveyor.com/project/bstaletic/ycmd-noh9b/builds/20561052/job/y64dyb0cytehw06t They are both mentioning (conflicting) redeclarations/redefinitions. This doesn't happen when I build on my own computer. |
I'll look at the CI errors. Could you try your example but with absl::core_headers instead of container and hash? those two probably pull in a huge chunk of abseil between the two of them, whereas core_headers is the lowest-level target we have. |
So, actual lists of pulled in dependencies:
|
Getting back around to this. We've been doing a lot of overhaul of our CMakeLists.txt files. Is this still an issue? |
The CI errors are different, and it definitely looks like an improvement.
EDIT: In case you glossed over it, I am compiling everything with |
Thanks for the update. I'm a little confused, how is python being used here? |
Our project links against For the MSVC failures, if you think that is an okay solution, I can submit a PR that wraps the overloads in |
cries. We probably should have prepended AbslInternal to our names, and ABSL_ to the macros. This will require some substantial migrations to fix as far as I can see. Or Python could take an Abseil dep :P For the MSVC that might work, but we would need to also release a migration tool for that as well, since that would be an api-breaking change. |
Adding Alex who has more insight both on int128 and also the migration tools required for these bugfixes |
I took a quick look at
According to compiler explorer |
For the MSVC bug, https://docs.microsoft.com/en-us/previous-versions/dh8che7s(v=vs.140) looks promising |
Wow, thanks for that! Turns out, on MSVC, our project was explicitly using That leaves us with the linker error and the conflict with the CPython function. For the linker error, every search I've been able to make was about
Indeed, all abseil components that are compiled are compiled into static libraries. Then I tried adding Once again, thanks for the help. |
For the linker error, this is what I'm currently doing:
And this solved the linker error. I am fine with this, since |
Let me check in to that. I'm pretty sure we build with PIC internally, I'm surprised we don't externally. I'm not sure if I missed it somewhere but can you detail the platform and toolchain you're using? As for the MSVC bug, that's awesome! I also wrote a change today to wrap the wchar_t typedefs so we're always picking up __wchar_t on MSVC. So if for whatever reason you actually need that /Zwchar_t- option you should be good. |
I'm able to reproduce the linker error on three completely different systems, all of which end up compiling without
With |
for set_property(TARGET ${_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) just here: abseil-cpp/CMake/AbseilHelpers.cmake Lines 168 to 170 in 111ca70
src: https://cmake.org/cmake/help/latest/prop_tgt/POSITION_INDEPENDENT_CODE.html |
Do we want to do that ourselves? Wouldn't that cause issues if our users didn't compile with PIC on? Seems like we need to inherit that somehow from our users |
I've tried it out on our project. Usually, compiling our benchmark looks like this:
I changed our Then I tried to compile our test suit and it worked as well. So current builds wouldn't be broken if However, I also measured the size and compile time of BoostParts with and without |
Hey there! I'm just now getting back from vacation, sorry I didn't say anything on this thread. Is there any update on your end? I can talk with the team about turning on PIC. It doesn't seem super controversial, although I think we should try to figure out why we aren't linking on some systems without PIC, as there are other systems where we build and link just fine. |
No real news. I've been following Abseil's master and everything works as long as I add |
Quick question. I just reread teh comments and looked more closely into I have a guess. From https://gcc.gnu.org/wiki/Visibility
I wonder if there aren't linker collisions in symbols which are elided when PIC is turned on? I'm going to investigate this, just keeping you up to speed with what I'm looking at. I also asked another Abseil engineer who is more well-versed in DSO design to look into this as well. |
Yes, I've tried |
I managed to create a minimal example that shows the issue with missing CMakeLists.txt: cmake_minimum_required(VERSION 2.8.12)
project(my_project)
add_subdirectory(abseil-cpp)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package (Threads REQUIRED)
add_library(my_lib SHARED foo.cpp)
target_link_libraries(my_lib absl::flat_hash_map Threads::Threads) foo.cpp:
Generate The linker error:
|
I reproduced your error, and it looks like it's the rng in GetGeometricVariable. However changing the rng to a static instead of thread_local reveals similar issues in the standard library.
Also, I tried building my_lib as a static library and everything worked perfectly. I think the moral of the story here is you just have to use -fPIC for shared libraries. Are there any objections to closing this at this point? |
I don't mind closing the issue, but I've got a question. Currently I'm using |
Looks like you want to use CMAKE_POSITION_INDEPENDENT_CODE as suggested by @Mizux earlier. I added set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) to your CMakeLists.txt file from above and confirmed everything built and linked. I'm closing this, please feel free to reopen |
Great, that worked! Thanks for helping out. |
Hi, I'm facing an almost the same issue, using abseil with pybind11. environment: ubuntu 20.04 LTS, python 3.8, gcc-9, cmake 3.16.3 installed with apt-get. Here's a minimum reproduce folder structure:
Here's the
Here's the
build commands and informations
|
@linrongbin16 in your CMakeLists.txt before set(CMAKE_POSITION_INDEPENDENT_CODE ON) Also you should set the C++ dialect instead of using the ugly
before |
Thanks, got it. |
- first build for Sisyphus libabseil-cpp-20211102.0-alt3 - rebuilt with -DCMAKE_POSITION_INDEPENDENT_CODE=ON (see abseil/abseil-cpp#225)
No matter what I try, cmake builds the whole abseil and then links everything into my shared library. I could reproduce this with a minimal cmake example:
main.cpp
contains only the following:For an actual project where I'm trying to use abseil, I get a linker error in debug mode that says the following:
The project in question is here.
Top level
CmakeLists.txt
Shared object defining
CMakeLists.txt
Abseil, at commit a06c4a1, is a submodule of my project. The build instructions are:
git submodule update --init --recursive
mkdir build && cd build
cmake ../cpp -DCMAKE_BUILD_TYPE=Debug
Other build time dependencies are python headers. For python3
-DUSE_PYTHON2=OFF
is needed.The text was updated successfully, but these errors were encountered: