# libcompat



## izotov (Feb 1, 2011)

Hi,
I try to build an old code on 8.1 amd64 with gcc using -lcompat and I get the following message:


```
gcc -shared -Xlinker -x -o <lots of files here> -lc -lcrypt -lcompat
/usr/bin/ld: /usr/lib/libcompat.a(ftime.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/usr/lib/libcompat.a: could not read symbols: Bad value
*** Error code 1
```
So as I can understand it wants me to rebuild libcompat with -fPIC. How can I do that?
Thanks!


----------



## Alt (Feb 1, 2011)

I think you should simple add -fPIC option to CFLAGS in Makefile


----------



## Lainoox (Feb 3, 2011)

-fPIC
If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k, PowerPC and SPARC.
Position-independent code requires special support, and therefore works only on certain machines.

When this flag is set, the macros __pic__ and __PIC__ are defined to 2.


----------



## izotov (Feb 4, 2011)

I was managed to build it with adding -fPIC in the Makefile but still needs testing whether it works or not.

I read somewhere that shared objects on amd64 must be compiled with this flag anyways.


----------



## i_masoomi (Feb 8, 2011)

*make.conf*

Goto /etc/
edit /etc/make.conf
add 
	
	



```
CFLAGS+= -fPIC
```

or add the same line in your port's Makefile in port directory.
then [cmd=]make clean[/cmd] your port and [cmd=]make install[/cmd] again.


----------



## SirDice (Feb 8, 2011)

i_masoomi said:
			
		

> Goto /etc/
> edit /etc/make.conf
> add
> 
> ...


Don't be tempted to do this. This will also effect the building of the kernel and world. Something you really don't want to mess with.


----------



## i_masoomi (Feb 9, 2011)

*rebuilding libcompat with -fPIC*

Yep, you *must* have sources on your system, (if otherwise run sysinstall and add sources). 

[cmd=]# cd /usr/src/lib/libcompat[/cmd]
[cmd=]# make clean[/cmd]

Edit /usr/src/lib/libcompat/Makefile and add the line 
	
	



```
CFLAGS+= -fPIC
```

then

[cmd=]# make[/cmd]

This will make all libcompat libraries with the specified flag.

[cmd=]# make install[/cmd]

This will copy newly generated libs to the proper location.

If this  does not suffice, manually copy files to your needed location. You can build any library the same way.


----------



## izotov (Feb 9, 2011)

i_masoomi said:
			
		

> Yep, you *must* have sources on your system, (if otherwise run sysinstall and add sources).
> 
> [cmd=]# cd /usr/src/lib/libcompat[/cmd]
> [cmd=]# make clean[/cmd]
> ...


Yes, I did this way.


----------



## DutchDaemon (Feb 9, 2011)

i_masoomi, would you please use proper formatting on these forums?


----------

