skeskinen/bert.cpp

Unable to build static library

jjzazuet opened this issue · 5 comments

Hi, thanks for this library! Trying to build under Linux, I'm getting this error:

~/code/bert.cpp/build$ cmake .. -DBERT_STATIC=ON -DBUILD_SHARED_LIBS=ON
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- x86 detected
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- x86 detected
-- Linux detected
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jjzazuet/code/bert.cpp/build
~/code/bert.cpp/build$ make
[ 25%] Building C object ggml/src/CMakeFiles/ggml.dir/ggml.c.o
[ 50%] Linking C shared library libggml.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [ggml/src/CMakeFiles/ggml.dir/build.make:97: ggml/src/libggml.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:141: ggml/src/CMakeFiles/ggml.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Perhaps I'm missing something obvious, but any help or pointers are appreciated.

$ uname -a
Linux echoes 6.1.0-9-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.27-1 (2023-05-08) x86_64 GNU/Linux

$ cat /etc/debian_version 
12.0

Thanks!

You have to compile static and dynamic separately. -DBERT_STATIC=ON -DBUILD_SHARED_LIBS=ON at the same time doesn't work

Ok I'll give that a try and ping back. Thanks.

Ah, yes, my bad. Specifying a single flag did work correctly. Much appreciated! Closing issue.

$ cmake .. -DBERT_STATIC=ON
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- x86 detected
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- x86 detected
-- Linux detected
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jjzazuet/code/bert.cpp/build
$ make
[  8%] Building C object ggml/src/CMakeFiles/ggml.dir/ggml.c.o
[ 16%] Linking C static library libggml.a
[ 16%] Built target ggml
[ 25%] Building CXX object CMakeFiles/bert.dir/bert.cpp.o
[ 33%] Linking CXX static library libbert.a
[ 33%] Built target bert
[ 41%] Building CXX object examples/CMakeFiles/server.dir/server.cpp.o
[ 50%] Linking CXX executable ../bin/server
[ 50%] Built target server
[ 58%] Building CXX object examples/CMakeFiles/main.dir/main.cpp.o
[ 66%] Linking CXX executable ../bin/main
[ 66%] Built target main
[ 75%] Building CXX object examples/CMakeFiles/test_tokenizer.dir/test_tokenizer.cpp.o
[ 83%] Linking CXX executable ../bin/test_tokenizer
[ 83%] Built target test_tokenizer
[ 91%] Building CXX object models/CMakeFiles/quantize.dir/quantize.cpp.o
[100%] Linking CXX executable ../bin/quantize
[100%] Built target quantize

By the way, I've now created Java bindings for bert.cpp. Thanks!

https://github.com/vaccovecrana/bert.jni

Cool project!