views:

99

answers:

2

I'm trying to create a lib with g++ 4.0.1, but it looks for _main (which deliberately isn't in the code). Must I put a _main in there or can I circumvent with some nifty switch? My current command line looks like:

g++ -shared -o mylib.so myobj1.o myobj2.o ...

On a sidenote I'm using g++ powerpc-apple-darwin9, but I'm guessing/hoping that this should be irrelevant. A more complete printout:

$g++ -O0 -ggdb -fPIC -D_DARWIN_C_SOURCE -D_STLP_THREADS -D_POSIX_PTHREAD_SEMANTICS -Istlport/stlport -Iutf8cpp -Ifreealut-1.1.0/include -Iode-0.11.1/include -Iode-0.11.1/ode/src -Iode-0.11.1/ode/src/joints -Iode-0.11.1/OPCODE -Iode-0.11.1/GIMPACT/include -Iode-0.11.1/ou/include -DPOSIX -D_XOPEN_SOURCE=600 -D_DEBUG -D_CONSOLE -DPNG_NO_ASSEMBLER_CODE -DdSingle -DdTLS_ENABLED=1 -DHAVE_CONFIG_H=1 -DLEPRA_WITHOUT_FMOD -framework OpenGL -framework CoreServices -framework OpenAL -DMAC_OS_X_VERSION=1050 -Wno-unknown-pragmas -o myfile.o -c myfile.cpp

$g++ -shared -framework OpenGL -framework AppKit -framework Cocoa -lobjc -lstlport -framework CoreServices -Lstlport/build/lib/obj/gcc/so -L. -Lopenal-soft-1.10.622 -Lfreealut-1.1.0/admin/VisualStudioDotNET/alut -L../Lepra -L../TBC -L../Cure -L../UiLepra -L../UiTBC -L../UiCure -L../Life -framework OpenAL -o libThirdParty.so myfile.o
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libThirdParty.so] Error 1
A: 

i am not getting any error though the g++ version is 4.1.2. Please post the error message and how you are compiling the source files.

Adil
I posted 'em, but not sure it's going to help. I've tried stripping everything but the -shared and -o switches, but with no success. I would like to know why g++ wants an entry point for my shared lib. Do you know of any reason it might want one? Bug in 4.0.1? "DLL entry"?
Jonas Byström
Not sure what the problem is but check the links:http://forums.codeblocks.org/index.php/topic,9934.0http://discussions.apple.com/thread.jspa?messageID=9703700
Adil
Already had the -dynamiclib switch in there, as you can see. The solution was to upgrade the compiler: 4.3.4 did the job.
Jonas Byström
+1  A: 

The solution is to upgrade the compiler. As stated by Adil, 4.1.2 seems to work. Myself, I upgraded to 4.3.4 and that worked great too.

Jonas Byström