cmp-nct / ggllm.cpp

Falcon LLM ggml framework with CPU and GPU support
Other
244 stars 21 forks source link

linking error with static build #76

Open WilliamTambellini opened 1 year ago

WilliamTambellini commented 1 year ago

Prerequisites

Your exact command line to replicate the issue

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

Environment and Context

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 commented 1 year ago

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

cmp-nct commented 1 year ago

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.