Skip to content
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

Compilation of subproject failed due to -L-L #13853

Open
WN90 opened this issue Nov 1, 2024 · 3 comments
Open

Compilation of subproject failed due to -L-L #13853

WN90 opened this issue Nov 1, 2024 · 3 comments

Comments

@WN90
Copy link

WN90 commented Nov 1, 2024

Describe the bug
I have a subproject built using CMake that links a library in a directory. Failed to compile it with meson, and LINK_ARGS in build.ninja contains -L-L.

cmake = import('cmake')

helloworld_proj = cmake.subproject('helloworld')
ninja -v
[1/1] c++  -o subprojects/helloworld/libhelloworld.so subprojects/helloworld/libhelloworld.so.p/src_main.cpp.o -L-L/home/lys/code/meson/subprojects/helloworld/world/lib -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libhelloworld.so -lworld /home/lys/code/meson/subprojects/helloworld/world/lib/libworld.so -Wl,--end-group
FAILED: subprojects/helloworld/libhelloworld.so 
c++  -o subprojects/helloworld/libhelloworld.so subprojects/helloworld/libhelloworld.so.p/src_main.cpp.o -L-L/home/lys/code/meson/subprojects/helloworld/world/lib -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libhelloworld.so -lworld /home/lys/code/meson/subprojects/helloworld/world/lib/libworld.so -Wl,--end-group
/usr/bin/ld: cannot find -lworld: No such file or directory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Changing -L-L to -L, the compilation can pass.

To Reproduce
See the attachment
messon_subproject_failed.tar.gz

Expected behavior
The compillation should pass.

system parameters

  • meson 1.3.2
  • ubuntu24.04
  • Python 3.12.3
  • ninja 1.11.1
@andy5995
Copy link
Contributor

andy5995 commented Nov 7, 2024

I downloaded your attachment and tried it out.

I noticed this cmake warning:

| CMake Warning (dev) at CMakeLists.txt:9 (add_library):
| Policy CMP0156 is not set: De-duplicate libraries on link lines based on
| linker capabilities.  Run "cmake --help-policy CMP0156" for policy details.
| Use the cmake_policy command to set the policy and suppress this warning.

On L22 I changed 'PUBLIC' to 'INTERFACE' and the library compiled successfully.

The cmake warning I mentioned above still persists though, so I'm not too sure the change I made is doing what needs to be done. I'm not very experienced with cmake.

@andy5995
Copy link
Contributor

andy5995 commented Nov 7, 2024

Actually, scratch that. There's no problem when I build it bypassing meson, using only cmake.

But here's the log from builddir/meson-logs:

meson-log.txt

@WN90
Copy link
Author

WN90 commented Nov 11, 2024

I downloaded your attachment and tried it out.

I noticed this cmake warning:

| CMake Warning (dev) at CMakeLists.txt:9 (add_library):
| Policy CMP0156 is not set: De-duplicate libraries on link lines based on
| linker capabilities.  Run "cmake --help-policy CMP0156" for policy details.
| Use the cmake_policy command to set the policy and suppress this warning.

On L22 I changed 'PUBLIC' to 'INTERFACE' and the library compiled successfully.

The cmake warning I mentioned above still persists though, so I'm not too sure the change I made is doing what needs to be done. I'm not very experienced with cmake.

From https://cmake.org/cmake/help/v3.0/command/target_link_libraries.html:
The PUBLIC, PRIVATE and INTERFACE keywords can be used to specify both the link dependencies and the link interface in one command. Libraries and targets following PUBLIC are linked to, and are made part of the link interface. Libraries and targets following PRIVATE are linked to, but are not made part of the link interface. Libraries following INTERFACE are appended to the link interface and are not used for linking <target>.

It seems that when using INTERFACE, the compilation of libhelloworld.so does not link against libworld.so, so no error is reported.
When using PRIVATE or PUBLIC, it links against libworld.so, and then when specifying the path to libworld.so, it results in the path being incorrectly specified as -L-L, leading to a link failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants