1833780 Members
2688 Online
110063 Solutions
New Discussion

Re: g++ and ld

 
sunil_7
Occasional Advisor

g++ and ld

Is it possible, that we compile the code with
$g++ -c
and then link the objects with ld.

As i am getting the following errors when link with g++ -shared


g++: /opt/gcc/lib/libstdc++.a: linker input file unused because linking not
done
/home/manju/FiltersDepot/sunilfdk/samples/filter/CandCplus/aCC.bat[5]:
echodone compilation: not found.
/usr/ccs/bin/ld: DP relative code in file /var/tmp/ccWehcie.o - shared
library must be position

3 REPLIES 3
sunil_7
Occasional Advisor

Re: g++ and ld

The latest error for the above problem i am getting is, although i am using -fPIC while compiling

/usr/ccs/bin/ld: DP relative code in file /var/tmp/ccc0Ehoc.o - shared library must be position
independent. Use +z or +Z to recompile.
collect2: ld returned 1 exit status


Sridhar Bhaskarla
Honored Contributor

Re: g++ and ld

Sunil,

did you really try like this?.

$g++ -c -fPIC abc.c

Now you can combine the object files into the shared library

$g++ -shared -fPIC -o abc.so abc.o xyz.o

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Santosh Nair_1
Honored Contributor

Re: g++ and ld

The -fPIC option to gcc (and g++) generate position independent code similar to the way the +z option does in HP's compiler.

-Santosh
Life is what's happening while you're busy making other plans