A question related to linking today.
Why is it advised to put the library options at the end of command line for compilation? Hint: If we have a static library, say libfoo.a which we want to link to our program hello.c
cc hello.c -lfoo
rather than
-l option tells the compiler to link to library [lib]foo. Note that "lib" from libfoo is dropped and only "foo" part is given with -l.
3 comments:
Yes, that's what the option does. But I thought you were going to tell us why cc -o foo foo.c -lthing and not cc -lthing -o foo foo.c (which work identically for me (gcc)).
Did you try linking to a static library?
The explanation will be in the next post :-)
No, I didn't. D'oh.
Post a Comment