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

From http://www.adp-gmbh.ch/cpp/gcc/create_lib.html:

Note: the library must start with the three letters lib and have the suffix .a.

Is this an operating system convention, or a gcc/ar quirk? Xcode seems to be able to create libraries without the prefix. What's it doing differently?

See Question&Answers more detail:os

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

1 Answer

You can name a library whatever you want, but if you want gcc's -l flag to find the right one, you need to name it the way that link describes. For example:

gcc -o myapp myapp.c -lm

Will compile myapp.c, link the resulting object with libm.a, and output an executable called myapp. These days, there might be a more complicated search path involving dynamic library names, etc., but you should get the basic idea from this example.

From the gcc man page:

-l library ...

... surrounds library with lib and .a and searches several directories.


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