libzippp icon indicating copy to clipboard operation
libzippp copied to clipboard

Linking issue since 5.1-1.8.0

Open Werni2A opened this issue 1 year ago • 3 comments

Host Environment

  • OS: Linux x64

Failure logs

/usr/bin/ld: ../vcpkg_installed/x64-linux/debug/lib/libzippp_static.a(libzippp.cpp.o): warning: relocation against `_ZSt7nothrow@@GLIBCXX_3.4' in read-only section `.text'
/usr/bin/ld: ../vcpkg_installed/x64-linux/debug/lib/libzippp_static.a(libzippp.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTVN8libzippp8ZipEntryE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

See https://github.com/Werni2A/OpenAllegroParser/runs/7693726908 for the full compile log.

Additional context I tried to figure out which commit in vcpkg introduced the issue by fixing the baseline to a few 'interesting' commits. It happens that after incorporating https://github.com/microsoft/vcpkg/pull/24885 my software does not link anymore. The major change was to bump the libzippp package, therefore I guess that the issue is located somewhere here.

Do you experience similar issues or am I doing something wrong?

Werni2A avatar Aug 05 '22 23:08 Werni2A

Hi @Werni2A,

Actually, I don't see anything that could break the linkage in the changes since v5.0. Maybe related to the upgrade of zlib ? :thinking:

I did not have any issue other than yours about this kind of problem.

ctabin avatar Aug 06 '22 10:08 ctabin

Hi @ctabin, I also took a look at the change set. My guess is that its somehow related to the changes of -fPIC for zlib compilation.

Later I will give it a try to create a small reproducer and get back to you.

Werni2A avatar Aug 06 '22 10:08 Werni2A

Hi @ctabin,

I attached a small reproducer. You can build it with the following command where vcpkg is located in the parent directory.

cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build

The library should build as is but as soon as you change the version in vcpkg.json from 5.0-1.8.0#0 to 5.1-1.8.0#0, linking fails.

Linking is only an issue when building a library. For executables it works somehow.

LibzippLinkIssueReproducer.zip

Werni2A avatar Aug 06 '22 13:08 Werni2A

Hi @Werni2A, Do you mind testing with the v6 version of libzippp if the problem is still present ? Thanks !

ctabin avatar Dec 15 '22 19:12 ctabin

Hi, I tested again with 6.0-1.9.2#1 from vcpkg but the same issue still persists.

I tried adding set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) to my CMakeFile which changes the the linking issue slightly. Find the error log below. Interestingly the PIC flag changes the linking issue against _ZTVN8libzippp8ZipEntryE as reported initially to stderr@@GLIBC_2.2.5. Still I have no idea what this issue is about. I don't even know if it's related to this library, the vcpkg port files or my own CMake scripts.

In case you have no suggestions what to do feel free to close this issue. I guess there is low value in leaving this open. Looks like I'm the only one having this issue anyway.

/usr/bin/ld: ../vcpkg_installed/x64-linux/debug/lib/libzippp_static.a(libzippp.cpp.o): warning: relocation against `_ZSt7nothrow@@GLIBCXX_3.4' in read-only section `.text'
/usr/bin/ld: ../vcpkg_installed/x64-linux/debug/lib/libzippp_static.a(libzippp.cpp.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

Werni2A avatar Dec 16 '22 20:12 Werni2A

@Werni2A Thanks for the test.

Obviously it seems related to -fPIC flag. I remember having the issue while changing the Makefile (because I was defining a global CFLAGS and then changed it to ZLIB_CFLAGS). Maybe this give you some hint ?

At this point I don't have any idea about this issue neither :-(

ctabin avatar Dec 16 '22 20:12 ctabin

I played around with different ways and locations to specify PIC but without any success. :disappointed: For now I will use the older version and close this issue.

Nonetheless, thank you for your time and maintaining this library. :smile: :+1:

Werni2A avatar Dec 16 '22 20:12 Werni2A

I experienced the same issue, also via vcpkg building. I put an issue in vcpkg but they had difficulties reproducing the error.

I "solved" this by letting my build system build libzippp.cpp itself, bypassing your cmake system and vcpkg and then it worked with the same source code file, so it is definitely something with how it is built. Note that I did not have to change anything in the build of zlib or other dependencies, these are still built by a standard vcpkg build (their tag 2023.02.24) so I'm pretty sure the problem is in your cmakelists files. I tried blaming there and saw there were recent changes, but didn't understand much.

It could be just that vcpkg is behind on following your releases, maybe.

BengtGustafsson avatar Apr 29 '23 15:04 BengtGustafsson

Note: -fPIC is needed when an object or static library is linked into a shared library, but not when linked into an executable. As I understand it this is as the shared library can be located anywhere when linked into the executable at runtime. So that's why it only fails when linked into a .so file.

BengtGustafsson avatar Apr 29 '23 15:04 BengtGustafsson

The issue is there: https://github.com/ctabin/libzippp/blob/ec69c0d2b2d46877b67852e27a485f7e754b6f78/CMakeLists.txt#L27-L31

This overwrites flags from the toolchain.

dg0yt avatar Apr 29 '23 16:04 dg0yt

Hi @dg0yt,

Thanks for the analyze. Do you mind submitting a PR to solve it ? That would be great !

ctabin avatar Apr 29 '23 18:04 ctabin

It is just adding ${<var name>} at the beginning or end of each string, to combine toolchain and project settings...

dg0yt avatar Apr 29 '23 20:04 dg0yt

Thanks a lot for fixing this!

BengtGustafsson avatar May 01 '23 09:05 BengtGustafsson