Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static linking with cross compiler

Tags:

static

linker

My test.c program uses printf function. I want to statically link library I need. I use arm-linux-gnueabi-gcc cross compiler.

When I compile my code like this

arm-linux-gnueabi-gcc test.c -o test

it passes, but I think he still uses dynamic linking by looking at dissasembly of test.

So,what option should I add in order to statically link libc.a library?

like image 912
MarsaPalas Avatar asked Oct 24 '25 08:10

MarsaPalas


1 Answers

Try

arm-linux-gnueabi-gcc test.c -o test -Xlinker -static /path/to/libc.a

This worked for me. Also, it might complain that you don't have static libgcc_s. Then try this:

arm-linux-gnueabi-gcc test.c -o test -Xlinker -static /path/to/libc.a -static-libgcc

Hope this helps!

like image 72
Tayyar R Avatar answered Oct 28 '25 04:10

Tayyar R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!