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

tests linking fails when LDFLAGS contain "-Wl,--as-needed" #11

Closed
bircoph opened this issue Aug 11, 2015 · 7 comments
Closed

tests linking fails when LDFLAGS contain "-Wl,--as-needed" #11

bircoph opened this issue Aug 11, 2015 · 7 comments

Comments

@bircoph
Copy link

bircoph commented Aug 11, 2015

Hi,

with --as-needed in LDFLAGS (default it Gentoo) tests fail to link:

cd /var/tmp/portage/sci-libs/asl-0.1.5-r1/work/asl-0.1.5_build/test/testACL && /usr/bin/cmake -E cmake_link_script CMakeFiles/testMatrixOfElements.dir/link.txt --verbose=1
/usr/lib64/ccache/bin/x86_64-pc-linux-gnu-g++   -O2 -pipe  -fpermissive  -Wno-deprecated   -Wl,--as-needed  CMakeFiles/testMatrixOfElements.dir/testMatrixOfElements.cc.o  -o testMatrixOfElements -rdynamic ../../src/libasl.so.0.1.5 ../../src/acl/libaslacl.so.0.1.5 ../../src/acl/Operators/libaslacloperators.so.0.1.5 ../../src/acl/aclMath/libaslaclmath.so.0.1.5 -lOpenCL ../../src/math/libaslmath.so.0.1.5 ../../src/data/libasldata.so.0.1.5 ../../src/libaslcommon.so.0.1.5
../../src/math/libaslmath.so.0.1.5: undefined reference to `asl::generateDataContainer_SP(asl::Block const&, acl::VectorOfElements const&, unsigned int)'
../../src/math/libaslmath.so.0.1.5: undefined reference to `asl::offset(asl::Block const&, int)'
collect2: error: ld returned 1 exit status
test/testACL/CMakeFiles/testMatrixOfElements.dir/build.make:102: recipe for target 'test/testACL/testMatrixOfElements' failed

This happens due to incorrect order of library arguments: libasl.so.0.1.5 should follow libaslmath.so.0.1.5 because libaslmath uses symbols from libasl.

On the other hand testACL/CMakeLists.txt contains:

target_link_libraries(testMatrixOfElements aslacl aslmath asldata asl)

which looks valid (asl is the last library on the list).

This problem starts with >=cmake-3.1.0: for 3.0.2 such problem is not reproducible, for 3.1.0 and later versions it takes place. Current version of cmake used for the build is 3.3.0.

Full build log is available here:
https://bpaste.net/show/56abb9c2f641

@ghisvail
Copy link
Contributor

Same thing happening on up-to-date Debian Testing using CMake 3.2.2.

Nicely spotted @bircoph !

@ghisvail
Copy link
Contributor

As a temporary fix, I commented out the non-building test and the rest of the testsuite builds successfully. Unfortunately, neither make test nor ctest seems to be doing anything.

EDIT: typo

@bircoph
Copy link
Author

bircoph commented Aug 11, 2015

Unfortunately, neither make test nor ctest seems to be doing anything.

This happens when running from the top build directory.

cd test && ctest

works.

@AvtechScientific, it will be nice to have top-level CTestTestfile.cmake which includes test/CTestTestfile.cmake (or test subdirectory).

@AvtechScientific
Copy link
Owner

We look for a newer system to reproduce the errors, in the meanwhile, could you, please, check whether swapping aslmath and asldata helps:

target_link_libraries(testMatrixOfElements aslacl asldata aslmath asl)

@bircoph
Copy link
Author

bircoph commented Aug 12, 2015

target_link_libraries(testMatrixOfElements aslacl asldata aslmath asl)

It still fails to build:

FAILED: : && /usr/lib64/ccache/bin/x86_64-pc-linux-gnu-g++   -march=native -O2 -funswitch-loops -fpredictive-commoning -ftree-vectorize -ftree-slp-vectorize -fvect-cost-model  -fgcse-after-reload -ftree-partial-pre -ftree-loop-im -fweb -frename-registers -fomit-frame-pointer -fexcess-precision=fast -pipe -frecord-gcc-switches -fno-stack-protector -fvisibility-inlines-hidden  -fpermissive  -Wno-deprecated  -march=native -O2 -funswitch-loops -fpredictive-commoning -pipe -Wl,-O1,--as-needed,--sort-common,-z,combreloc,-z,relro,-z,now,--relax,--hash-style=gnu test/testACL/CMakeFiles/testMatrixOfElements.dir/testMatrixOfElements.cc.o  -o test/testACL/testMatrixOfElements  -rdynamic src/libasl.so.0.1.5 src/acl/libaslacl.so.0.1.5 src/acl/Operators/libaslacloperators.so.0.1.5 src/acl/aclMath/libaslaclmath.so.0.1.5 -lOpenCL src/data/libasldata.so.0.1.5 src/math/libaslmath.so.0.1.5 src/libaslcommon.so.0.1.5 && :
src/math/libaslmath.so.0.1.5: undefined reference to `asl::generateDataContainer_SP(asl::Block const&, acl::VectorOfElements const&, unsigned int)'
src/math/libaslmath.so.0.1.5: undefined reference to `asl::offset(asl::Block const&, int)'
collect2: error: ld returned 1 exit status

Please note that if in the build command one moves "src/libasl.so.0.1.5" to the end of the list, build is fine. Now the question is how to move it there, because it is already on the end of the list in test/testACL/CMakeLists.txt. I have no idea what and why moves it around during cmake run.

@ghisvail
Copy link
Contributor

@bircoph Most ASL binaries are quite underlinked (see #13), which is likely to be the source of the missing references.

@bircoph
Copy link
Author

bircoph commented Aug 14, 2015

Current git head fixes this for me.

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