Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

static linking with gcc on OSX 10.6

I am having problems regarding static linking for OS X 10.6. I want to compile with -static, in which there is no 'crt0.o'. I understand normally one should not use -static, but it makes sense in my case. Here is the issue and Apple's
response.

http://developer.apple.com/mac/library/qa/qa2001/qa1118.html


Apple recommends:

"get the Csu module from Darwin and try building crt0.o statically"

I downloaded the Csu module from:

http://www.opensource.apple.com/source/Csu/Csu-79/

Did a 'make install' and then tried a test program. Does anybody know where
I can get a 'crt0.o' that will work or what I did wrong? I am using a MacBook
with a 10.6 upgrade. Thanks. Here is output of simple test programs.

//32-bit static - compiles fine
[167]gcc -static -m32 -g t.c
[168]a.out
Bus error
[169]


//gdb from above "Bus error"
(gdb) r
Starting program: /private/tmp/a.out

Program received signal EXC BADACCESS, Could not access memory.
Reason: KERN PROTECTIONFAILURE at address: 0x00000001
0x00000001 in ?? ()

//64-bit static
[172]gcc -static t.c
ld: warning: in /usr/lib/gcc/i686-apple-darwin10/4.2.1/libgcc_static.a,
file is not of required architecture
Undefined symbols:
"_exit", referenced from:
start in crt0.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

//64-bit static
[172]gcc -static t.c
ld: warning: in /usr/lib/gcc/i686-apple-darwin10/4.2.1/libgcc_static.a,
file is not of required architecture
Undefined symbols:
"_exit", referenced from:
start in crt0.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


//64-bit static
[172]gcc -static t.c
ld: warning: in /usr/lib/gcc/i686-apple-darwin10/4.2.1/libgcc_static.a,
file is not of required architecture
Undefined symbols:
"_exit", referenced from:
start in crt0.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


//now 32-bit no longer works due to the Csu 'make install' overridding
// /usr/lib/crt1.10.6.o
[175]gcc -m32 t.c
ld: warning: in /usr/lib/crt1.10.6.o, file is not of required
architecture ld: could not find entry point "start" (perhaps missing
crt1.o)
collect2: ld returned 1 exit status

Mac OS X (10.6)

Posted on Dec 2, 2009 12:25 PM

Reply
20 replies

Sep 9, 2011 8:35 AM in response to pacolanciano

pacolanciano wrote:


I have a code that requires several additional libraries to be built and I want my student to use the program without using much time on compilation and building phases.

That is not an adequate explanation for wanting to use -static. You don't need that to link additional libraries. It certainly isn't going to help with compilation time.

static linking with gcc on OSX 10.6

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.