mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support
BSD 2-Clause "Simplified" License
724 stars 120 forks source link

Static link seasocks #184

Open toutriste opened 1 year ago

toutriste commented 1 year ago

Hi, how can I static link seasocks? I did not found anything on the documentation..

I have tried this: LIBRARIES = -lm /home/user/seasocks/build/src/main/c/libseasocks.a

but getting these errors:

/usr/bin/ld: /home/user/seasocks/build/src/main/c/libseasocks.a(Server.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTVN8seasocks6ServerE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

I suppose there is an extra step when I'm building seasocks?

madebr commented 1 year ago

You need to build seasocks with -fPIC. This can be done by configuring seasocks with CMAKE_POSITION_INDEPENDENT_CODE:

cmake -S /path/to/seasocks -B /tmp/seasocks_build -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF
cmake --build /tmp/seasocks_build

Perhaps we should add the following to our cmake script:

set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Enable Position Independent Code")