Reputation: 5208
I am rather new with C++ and using eclipse.
I have a Native C++ Static Library with a C++/CLI Wrapper in Visual Studio 2012.
Now I am building the Native C++ code in Linux with Eclipse (Juno Service Release 2) and GCC 4.2.4.
I created a Shared Library Empty Project in Eclipse and added all my .h and .cpp files, and let Eclipse do the building. However I got the error
relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
I added the -fPIC flag in Project->Settings->GCC C++ Compiler-> Miscellaneous-> Other Flags.
I don't know anyone proficient using Linux/Eclipse so I am not sure I took the best path.
Is there a best/"more correct" way to build a shared library than the way I just described? Are there any issues to the approach I took?
Upvotes: 2
Views: 3700
Reputation: 14860
Adding -fPIC
is the right thing to do, you should be fine.
Shared libraries need to be relocated when loaded (by ldd
) and there are two main approaches: load-time relocation and Position Independent Code (PIC), with the latter being mainstream in modern solutions and architectures.
Upvotes: 1