Hello
os: ubuntu 9.10 x64
I would like to create shared library
I use creator to create project ProjExec which is console app(only contains main with return 0) and ProSlib which is shared library:
I configured:
ProSlib:
Project->Set programs and arguements->This prog provides main executable [checked] and I set path to [Generated binary from ProjExec]
ProjExec:
ProjExec->properties->projcet's dependecis->ProExec depends on ProSlib.
If I would like to build my ProSlib I got this output
-------------- Build: Debug in ProjSlib ---------------
Linking dynamic library: bin/Debug/libProjSlib.so
/usr/bin/ld: obj/Debug/main.o: relocation R_X86_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
obj/Debug/main.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
What I did wrong or didn't do to get this compiled and working?
I have no idea what you did wrong;
If you turn on full compiler logging and post the build log where an expert on building this library can read it. They should see the problem.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Tim S.
Most probably you're building c++ code with the c compiler.
Remember that the file extension matters => .c files are compiled by c compiler, .cpp files by c++ compiler.
Actually, the linker seems to tell you very clearly, what you did wrong and what you should do to fix the problem.
Quote/usr/bin/ld: obj/Debug/main.o: relocation R_X86_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
Thanks for fast answer.
recompile with -fPIC I have not idea guide me please.
My files are cpp
That was full command line output :/
Googling gave me no solution which I know how to use...
http://code.google.com/p/gosu/issues/detail?id=38 (http://code.google.com/p/gosu/issues/detail?id=38)
I have g++ 4.4 with multilib
Exec main.cpp
///Headers
#include <cstdlib>
#include <iostream>
#include <string>
///Specials
using namespace std;
///Globals Varuabels
int main(){
return 0;
}
Slib main.cpp
#ifdef __cplusplus
extern "C" {
#endif
// A function adding two integers and returning the result
int SampleAddInt(int i1, int i2)
{
return i1 + i2;
}
// A function doing nothing ;)
void SampleFunction1()
{
// insert code here
}
// A function always returning zero
int SampleFunction2()
{
// insert code here
return 0;
}
#ifdef __cplusplus
}
#endif
-fPIC is a compiler flag, that should be used when compiling the source files of the shared library. Probably goes under "Other Options". Consult your Code::Blocks manual about how to set compiler flags.
FYI:
You really need to turn on Full Compiler Logging and ask in a group that supports the library.
Or an Linux person who builds Libraries.
Tim S.
Quote from: str0g on March 08, 2010, 03:05:02 PM
ProSlib:
Project->Set programs and arguements->This prog provides main executable [checked] and I set path to [Generated binary from ProjExec]
This does not sound right; but, it might be OK.
I will try it and see what happens.
I can not find the option under windows.
The code Compiles under Windows; with no errors; no idea without Good Full Compiler Build log what the issue is.
Tim S.
Adding compilation flag fix the problem, thanks!
How to include your library?
#include "yourlibheaderFile.hpp"
build options->Search directories->Compiler->add dir with headers.
build options->linker link libraries->add dir to your library.