ggllm.cpp icon indicating copy to clipboard operation
ggllm.cpp copied to clipboard

linking error with static build

Open WilliamTambellini opened this issue 2 years ago • 2 comments

Prerequisites

  • [X] I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • [X] I carefully followed the README.md.
  • [X] I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • [X] I reviewed the Discussions, and have a new bug or useful enhancement to share.

Your exact command line to replicate the issue

cmake ..  -DLLAMA_CUBLAS=ON -DLLAMA_STATIC=1
make

Environment and Context

  • Physical (or virtual) hardware you are using, e.g. for Linux: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz

  • Operating System, e.g. for Linux: CentOS 7 + gcc11.3 + cuda 11.6

Steps to Reproduce

  1. cmake .. -DLLAMA_CUBLAS=ON -DLLAMA_STATIC=1
  2. make

Failure Logs

...
Consolidate compiler generated dependencies of target quantize-stats
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: attempted static link of dynamic object `/usr/lib64/librt.so'
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: attempted static link of dynamic object `/usr/lib64/librt.so'
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: attempted static link of dynamic object `/usr/lib64/librt.so'
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: attempted static link of dynamic object `/usr/lib64/librt.so'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/test-sampling] Error 1
collect2: error: ld returned 1 exit status
make[2]: *** [bin/test-quantize-perf] Error 1
collect2: error: ld returned 1 exit status
make[1]: *** [tests/CMakeFiles/test-sampling.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** [bin/falcon_quantize] Error 1
collect2: error: ld returned 1 exit status
make[1]: *** [tests/CMakeFiles/test-quantize-perf.dir/all] Error 2
make[1]: *** [examples/falcon_quantize/CMakeFiles/falcon_quantize.dir/all] Error 2
make[2]: *** [bin/test-quantize-fns] Error 1
make[1]: *** [tests/CMakeFiles/test-quantize-fns.dir/all] Error 2

When adding CMAKE_VERBOSE_MAKEFILE=1:

g++ -O3 -DNDEBUG -static CMakeFiles/quantize-stats.dir/quantize-stats.cpp.o -o ../../bin/quantize-stats   
-L/usr/local/cuda/targets/x86_64-linux/lib/stubs  -L/usr/local/cuda/targets/x86_64-linux/lib  
../../libllama.a -pthread /usr/local/cuda/lib64/libcudart_static.a -pthread -ldl 
/usr/lib64/librt.so /usr/local/cuda/lib64/libcublas_static.a /usr/local/cuda/lib64/libcublasLt_static.a 
/usr/local/cuda/lib64/libculibos.a -lcudadevrt -lcudart_static 
-lrt -lpthread -ldl 

For some reasons (mainly the added "-static"), cmake adds both "/usr/lib64/librt.so" (not a static lib) and "-lrt" (that one is usually acceptable even for a static build).

WilliamTambellini avatar Jul 31 '23 18:07 WilliamTambellini

You try to manually add "-static" in the main cmake script: https://github.com/cmp-nct/ggllm.cpp/blob/66aa59e790f097bd8f19e8749c0a7f29e84a0fe1/CMakeLists.txt#L364

According to https://www.man7.org/linux/man-pages/man1/gcc.1.html

-static
           On systems that support dynamic linking, this overrides -pie
           and prevents linking with the shared libraries.  On other
           systems, this option has no effect.

I m not sure why you use "-static" but you probably have/had good reasons to. On my side, removing that line does resolve the link issue and generates execs/libs with minimum dyn deps:

ldd falcon_main
	linux-vdso.so.1 =>  (0x00007fffa456b000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007efd36cef000)
	librt.so.1 => /lib64/librt.so.1 (0x00007efd36ae7000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007efd368cb000)
	libstdc++.so.6 (0x00007efd364cd000)
	libm.so.6 => /lib64/libm.so.6 (0x00007efd361cb000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007efd35fb5000)
	libc.so.6 => /lib64/libc.so.6 (0x00007efd35be7000)
	/lib64/ld-linux-x86-64.so.2 (0x00007efd36ef3000)

which is good for my purpose.

@cmp-nct would you mind if I add a cmake option to not "-static" there: https://github.com/cmp-nct/ggllm.cpp/blob/66aa59e790f097bd8f19e8749c0a7f29e84a0fe1/CMakeLists.txt#L364 ? Best

WilliamTambellini avatar Jul 31 '23 20:07 WilliamTambellini

I'll look into it, I am still burried with a large overhaul of the code and stuck in details. Hope to finish at least a experimental branch before I go on vacation.

Once the new code is ready I'll add the smaller suggestions and fixes, otherwise I'll need to do all twice.

cmp-nct avatar Aug 05 '23 23:08 cmp-nct