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

/usr/bin/ld: cannot find -ltaskchampion-lib #3485

Closed
djmitche opened this issue Jun 14, 2024 · 9 comments · Fixed by #3487
Closed

/usr/bin/ld: cannot find -ltaskchampion-lib #3485

djmitche opened this issue Jun 14, 2024 · 9 comments · Fixed by #3487
Assignees
Labels
build-system Related to build system (Cmake)

Comments

@djmitche
Copy link
Collaborator

All tests are now failing with

#16 89.86    Compiling taskchampion-lib v0.1.0 (/root/code/src/tc/lib)
#16 90.17 [ 96%] Built target commands
#16 90.20 [ 98%] Building CXX object src/CMakeFiles/task_executable.dir/main.cpp.o
#16 90.20 [ 98%] Building CXX object src/CMakeFiles/lex_executable.dir/lex.cpp.o
#16 90.20 [ 98%] Building CXX object src/CMakeFiles/calc_executable.dir/calc.cpp.o
#16 90.30 warning: method `ptr_to_arg_out` is never used
#16 90.30    --> src/tc/lib/src/traits.rs:138:15
#16 90.30     |
#16 90.30 80  | pub(crate) trait PassByPointer: Sized {
#16 90.30     |                  ------------- method in this trait
#16 90.30 ...
#16 90.30 138 |     unsafe fn ptr_to_arg_out(self, arg_out: *mut *mut Self) {
#16 90.30     |               ^^^^^^^^^^^^^^
#16 90.30     |
#16 90.30     = note: `#[warn(dead_code)]` on by default
#16 90.30 
#16 91.53 warning: `taskchampion-lib` (lib) generated 1 warning
#16 91.53     Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 25s
#16 91.60 Copying byproducts `libtaskchampion_lib.a` to /root/code/build/src/tc
#16 91.72 [100%] Linking CXX executable lex
#16 91.83 [100%] Linking CXX executable calc
#16 91.87 [100%] Linking CXX executable task
#16 91.96 /usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory
#16 92.00 collect2: error: ld returned 1 exit status

The warning has been around forever, and is (I think) unrelated.

@djmitche
Copy link
Collaborator Author

I can build locally, so I wonder if this is some race condition? But the logging above suggests that the .a file is copied 360ms before it's referenced..

@djmitche
Copy link
Collaborator Author

It looks like it is. Trying to reproduce on the train, cargo couldn't download dependent crates fast enough and I see

[ 98%] Building CXX object src/CMakeFiles/lex_executable.dir/lex.cpp.o
[100%] Linking CXX executable lex
[100%] Linking CXX executable calc
/usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/lex_executable.dir/build.make:106: src/lex] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:464: src/CMakeFiles/lex_executable.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable task
/usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/calc_executable.dir/build.make:106: src/calc] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:434: src/CMakeFiles/calc_executable.dir/all] Error 2
/usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/task_executable.dir/build.make:106: src/task] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:404: src/CMakeFiles/task_executable.dir/all] Error 2
warning: spurious network error (3 tries remaining): [28] Timeout was reached (SSL connection timeout)
  Downloaded async-stream v0.3.5
  Downloaded scopeguard v1.1.0

which is to say, things are calling ld with -ltaskchampion-lib before the Rust build has even begun.

@djmitche
Copy link
Collaborator Author

corrosion docs say

For Rust library targets an INTERFACE library target is created with the same name as defined in the [lib] section of the Manifest.
...
The created library targets can be linked into other CMake targets by simply using target_link_libraries.

That target, from src/tc/lib/Cargo.toml, is taskchampion-lib. So I think this should work??

The target_link_libraries docs say

target_link_libraries( ... ... ...)
...
Each may be:
A library target name: The generated link line will have the full path to the linkable library file associated with the target. The buildsystem will have a dependency to re-link if the library file changes.
...
A plain library name: The generated link line will ask the linker to search for the library (e.g. foo becomes -lfoo or foo.lib).

since the error is regarding -ltaskchampion-lib and not /some/path/to/taskchampion-lib.so, I wonder if it's being interpreted as a plain library name?

@djmitche
Copy link
Collaborator Author

The docker images are using cmake 3.22, while I'm using 3.29. Maybe that's related?

@djmitche
Copy link
Collaborator Author

Nope, I can repro with 3.29 installed in a n ubuntu-22.04 docker image

@djmitche
Copy link
Collaborator Author

Hm, maybe not a race -- in the docker image, with cmake-3.29:

root@c2e3eb5fbea3:/repo# cmake --build build
[ 15%] Built target task
[ 29%] Built target libshared
[ 51%] Built target columns
[ 91%] Built target commands
[ 96%] Built target tc
[ 96%] Linking CXX executable task
/usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/task_executable.dir/build.make:106: src/task] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:404: src/CMakeFiles/task_executable.dir/all] Error 2
gmake: *** [Makefile:166: all] Error 2

With -v that's

[ 96%] Linking CXX executable task
cd /repo/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/task_executable.dir/link.txt --verbose=1
/usr/bin/c++ -Wall -Wextra -Wsign-compare -Wreturn-type -std=c++17  -g CMakeFiles/task_executable.dir/main.cpp.o -o task  libtask.a tc/libtc.a commands/libcommands.a tc/libtc.a columns/libcolumns.a liblibshared.a libtask.a liblibshared.a -ldl -lpthread /usr/lib/x86_64-linux-gnu/libuuid.so -ltaskchampion-lib
/usr/bin/ld: cannot find -ltaskchampion-lib: No such file or directory

@djmitche
Copy link
Collaborator Author

Outside of docker, -v shows

[100%] Linking CXX executable task
cd /home/dustin/p/taskwarrior/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/task_executable.dir/link.txt --verbose=1
/usr/bin/c++ -Wall -Wextra -Wsign-compare -Wreturn-type -std=c++17  -g CMakeFiles/task_executable.dir/main.cpp.o -o task  libtask.a tc/libtc.a commands/libcommands.a tc/libtc.a columns/libcolumns.a liblibshared.a libtask.a liblibshared.a -ldl -lpthread /usr/lib/x86_64-linux-gnu/libuuid.so tc/libtaskchampion_lib.a -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc

@djmitche
Copy link
Collaborator Author

Notably, locally it's using tc/libtaskchampion_lib.a, as I would expect.

@djmitche
Copy link
Collaborator Author

Ah, Rust-1.79 was released yesterday, and downgrading to 1.78 in the docker container

corrosion-rs/corrosion#501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-system Related to build system (Cmake)
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant