getting error “recompile with -fPIC”

4

After ./configure asterisk in CentOS I type make command but getting the following error

/usr/bin/ld: /usr/local/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/liblua.a: could not read symbols: Bad value

I tried this ./configure CFLAGS=-fPIC but getting same error as above.

Bilal

Posted 2013-02-26T21:49:10.817

Reputation: 43

Answers

5

At this point in asterisk, you're trying to build a dynamic lib. Since this dynamic lib can be loaded at any memory location, everything needs to be relocatable. The -fPIC flag means Position Independent Code, the code is made to be independent of load location - loaded anywhere.

As part of this asterisk dynamic lib build, it's trying to bring in the Lua interpreter. Since it's bringing into a dynamic lib, it needs everything compiled PIC. But you're using a static lib of lua, which was not built with -fPIC. It rejects this, since the lua objects in the static lib can not be relocated.

BTW: this is why adding -fPIC to the asterisk build won't help. It's not your asterisk code objects that are incompatible (which -fPIC can affect), but liblua.a, specifically the objects carried by liblua.a (e.g lapi.o). Besides, you're building a dynamic lib at that point, and Im sure you already have relocatable code flags such as -fPIC for the asterisk objects you're trying to pull together at that point.

I see three solutions.

  • One is to drop lua from your build. If you don't need it specifically and were thinking more that "this may be fun to play with later" you may be able to and not lose wanted features.

  • Another is to get a dynamic version of liblua, liblua.so, one that can be referenced in your asterisk build. I don't know your distro, so I can't say how to get it.

  • The other, more pain in the ass one, is to rebuild lua, and liblua.a, with -fPIC. You'd have compatibility issues maybe from inconsistent build flags (what you made and what else is on disk), so I think finding a liblua.so to match your currently built lua is the better option.

If you find liblua.so, you may want to look into the '-rpath' linker flag for this though, specifically '-Wl,-rpath,/path/to/lua/libs'

Rich Homolka

Posted 2013-02-26T21:49:10.817

Reputation: 27 121

I did apply solution number 1 and it worked fine, Thank you for your help. – Bilal – 2013-02-27T21:11:15.317

@BilalWaheed if it worked, please mark the answer as accepted. No problem on the help. – Rich Homolka – 2013-02-27T22:59:29.423