Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

For example I did this:

${CROSS_COMPILE}gcc -static myinit.c -o myinit

Also I did this without static:

${CROSS_COMPILE}gcc  myinit.c -o myinit

There is no effect in my case, in both cases binary gives same result.

So what is the role of static here?

Here is the program I am compiling:

#include <stdio.h>

int
main ()
{
    printf ("
");
    printf ("Hello world from %s!
", __FILE__);
    while (1) { }
    return 0;
}

Also

${CROSS_COMPILE} is arm-xilinx-linux-gnueabi-

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

From the gcc man page, it's used to enforce static linking of libraries. Some systems will always link statically if dynamic linking is not supported.

-static On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.

       This option will not work on Mac OS X unless all libraries (including libgcc.a)
       have also been compiled with -static.  Since neither a static version of
       libSystem.dylib nor crt0.o are provided, this option is not useful to most
       people.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...