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

linker error not detected, when using "--no-undefined" linker option #1469

Closed
gunrot opened this issue Sep 17, 2018 · 5 comments
Closed

linker error not detected, when using "--no-undefined" linker option #1469

gunrot opened this issue Sep 17, 2018 · 5 comments

Comments

@gunrot
Copy link

gunrot commented Sep 17, 2018

I use cmake 3.12.1 and ninja (1.8.2). When using Wl,--no-undefined -Wl,--no-allow-shlib-undefined linker options, a linker error is not recognized by ninja, error code is 0. Using Unix Makefiles generator works as expected.
Sample code is here: ninjabug.zip

 cmake --build . || echo "error"
[1/1] : && /usr/bin/c++ -fPIC -Wl,--no-as-needed  -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -shared -Wl,-soname,libninjabug.so -o libninjabug.so CMakeFiles/ninjabug.dir/ninjabug.cpp.o   && /usr/bin/cmake -E __run_co_compile --lwyu=libninjabug.so || true && :
CMakeFiles/ninjabug.dir/ninjabug.cpp.o: In function `ninjabug()':
ninjabug.cpp:(.text+0x5): undefined reference to `HelloWorld()'
collect2: error: ld returned 1 exit status

Using Makefiles is like this:

 cmake --build . || echo "error"
[ 50%] Linking CXX shared library libninjabug.so
CMakeFiles/ninjabug.dir/ninjabug.cpp.o: In function `ninjabug()':
ninjabug.cpp:(.text+0x5): undefined reference to `HelloWorld()'
collect2: error: ld returned 1 exit status
CMakeFiles/ninjabug.dir/build.make:83: recipe for target 'libninjabug.so' failed
make[2]: *** [libninjabug.so] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ninjabug.dir/all' failed
make[1]: *** [CMakeFiles/ninjabug.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
error

@mathstuf
Copy link
Contributor

This might be a CMake issue.

@mathstuf
Copy link
Contributor

Hmm, ninja itself is returning success here:

% cmake --build .
[0-1->2/2@24.4] Linking CXX shared library libninjabug.so
/usr/bin/ld: CMakeFiles/ninjabug.dir/ninjabug.cpp.o: in function `ninjabug()':
ninjabug.cpp:(.text+0x5): undefined reference to `HelloWorld()'
collect2: error: ld returned 1 exit status
% echo 0
0
% ninja
[0-1->1/1@125000.0] Linking CXX shared library libninjabug.so
/usr/bin/ld: CMakeFiles/ninjabug.dir/ninjabug.cpp.o: in function `ninjabug()':
ninjabug.cpp:(.text+0x5): undefined reference to `HelloWorld()'
collect2: error: ld returned 1 exit status
% echo 0
0

But this is due to this being the rule for the link step:

  command = $PRE_LINK && /usr/lib64/ccache/c++ -fPIC $LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS $LINK_FLAGS -shared $SONAME_FLAG$SONAME -o $TARGET_FILE $in $LINK_PATH $LINK_LIBRARIES && /usr/bin/cmake -E __run_co_compile --lwyu=libninjabug.so || true && $POST_BUILD

The || true is probably the problem. Please refile on CMake's issue tracker.

@mathstuf
Copy link
Contributor

Specifically, it seems to be an issue with CMAKE_LINK_WHAT_YOU_USE being set to ON.

@jhasse
Copy link
Collaborator

jhasse commented Oct 29, 2018

Closing as it seems to be a CMake issue. Btw: Run ninja with -v to see the command that was run.

@jhasse jhasse closed this as completed Oct 29, 2018
@mathstuf
Copy link
Contributor

Filed here.

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

3 participants