QwenLM / qwen.cpp

C++ implementation of Qwen-LM
Other
506 stars 40 forks source link

fix: Fixing static compilation issues when installing modules with pip #57

Open uniartisan opened 6 months ago

uniartisan commented 6 months ago

Error message: When trying to link the libre2.a static library, "relocation R_X86_64_TPOFF32 against symbol '_ZN3re25hooks7contextE' can not be used when making a shared object; recompile with -fPIC "problem. This means that the library is not compiled with the -fPIC option, which prevents it from being linked to a shared object.

Error analysis: This error is caused by an attempt to link a static library (in this case libre2.a) that is not compiled with the -fPIC (Position Independent Code) option. Location-independent code means that a program can be executed anywhere in memory, which is important for generating dynamic link libraries. When creating shared or dynamic libraries, you need all object code to be location-independent.

Possible fix description: We can fix this problem by adding the -fPIC option in CMakeLists.txt. We add the -fPIC option when compiling the re2 library, but this changes the upstream content. So I chose to make sure that all targets defined in CMakeLists.txt are set to generate location-independent code by default. This can be done by adding the following line at the top of the CMakeLists.txt file:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

This way, when you build the libre2.a library again and try to install qwen-cpp, the problem should be resolved.