nginx_upstream_module icon indicating copy to clipboard operation
nginx_upstream_module copied to clipboard

Can't compile as shared object

Open donbarthel opened this issue 7 years ago • 5 comments

make build-all-dynamic gives error: /usr/bin/ld: /home/user/Code/nginx_upstream_module/third_party/yajl/build/yajl-2.1.0/lib/libyajl_s.a(yajl.c.o): relocation R_X86_64_32 against '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC

It appears to me that the yajl library is statically linked into our dynamic library but the Makefile for yajl compiles without the needed -fPIC flag. The -fPIC flag is used only when the yajl library is dynamically linked.

My work around is to specify the -fPIC flag for all compiles of yajl.

Change in ./third_party/yajl/CMakeLists.txt: SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") to: SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

donbarthel avatar Mar 01 '18 12:03 donbarthel

Sorry for long the answer, was offline. Thank you for the report!

Yep, this looks like a bug. Which operating system did you use? And did you use GCC and CLang?

dedok avatar Mar 23 '18 06:03 dedok

I'm using Ubuntu 16.04 compiling with GCC.

donbarthel avatar Mar 26 '18 00:03 donbarthel

Not sure how it could be fixed. Probably patch for Yajl? Or PR into yajl repo? What do you think?

dedok avatar Apr 15 '19 19:04 dedok

We can conditionally set -fPIC flag: enable it only for dynamic build.

Totktonada avatar Apr 16 '19 14:04 Totktonada

The question here is about yajl in the submodule. Everything work with system-wide yajl (at least for me).

Totktonada avatar Apr 16 '19 14:04 Totktonada