Static library fails to link with specific compiler-linker combinations
See original GitHub issueBug description
I just switched from CMake to Meson, and I noticed that when compiling Pistache as a static library with Clang and the default Debian linker (ld.bfd
) and with GCC + LLD I get an error when linking it to the main program. The issue does not appear when using GCC + ld, Clang + LLD, or CMake.
Here’s the Clang + ld error:
/usr/bin/ld: subprojects/pistache/libcm_pistache_static.a: error adding symbols: archive has no index; run ranlib to add one
[33/33] Linking target Scraf
FAILED: Scraf
c++ -o Scraf Scraf.p/meson-generated_student_odb.cpp.o Scraf.p/meson-generated_school_class_odb.cpp.o Scraf.p/meson-generated_school_odb.cpp.o Scraf.p/meson-generated_teacher_odb.cpp.o Scraf.p/src_main.cpp.o -flto -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group subprojects/pistache/libcm_pistache_static.a -pthread /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/local/lib/libodb.so /usr/local/lib/libodb-pgsql.so /usr/lib/x86_64-linux-gnu/libgtest.a -lpthread /usr/lib/x86_64-linux-gnu/libsimdjson.so.5.0.0 /usr/lib/x86_64-linux-gnu/libsodium.so -Wl,--end-group -Wl,-rpath,/usr/local/lib -Wl,-rpath-link,/usr/local/lib
/usr/bin/ld: subprojects/pistache/libcm_pistache_static.a: error adding symbols: archive has no index; run ranlib to add one
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Steps to reproduce
- Clone
scraf-backend
- Build the project using
Clang
+ld.bfd
orGCC
+LLD
meson.build
I’m using (lines 1-33 should’t be relevant)
System parameters
- Build type: Native build, both debug and release
- Operating system: Debian Testing
- Python: 3.9.1
- Meson: 0.56.2
- Ninja: 1.10.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Linker failing to find existing static library with correct name
I got it to compile; it seemed to be that ld on MinGW-w64 was looking for the specific name lib<library name>.a . I...
Read more >Working with libraries and the linker
To allow multiple versions of the library to exist on disk, they obviously require differing file names. The soname scheme uses a combination...
Read more >Link Options (Using the GNU Compiler Collection (GCC))
No startup files and only the libraries you specify are passed to the linker, and options specifying linkage of the system libraries, such...
Read more >FAQ: Building Open MPI
Can I pass specific flags to the compilers / linker used to build ... How do I statically link to the libraries of...
Read more >/LTCG (Link-time code generation) | Microsoft Learn
(Optional) Specifies that the linker only applies whole program optimization or link-time code generation (LTCG) to files affected by an edit, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think that this also happened when using Clang + gold (and already happens with GCC + LLD)
Uhm, you’re probably right, but I’d like to investigate this a bit more. I’ll do it tomorrow 😃
I haven’t been able to reproduce this in a minimal project, but today I’ve encountered this CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/20818
Maybe this is caused by Meson not defining
CMAKE_INTERPROCEDURAL_OPTIMIZATION
whenb_lto
is enabled?