Re: Passing names of libraries to linker.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > MS C++ compiler supports a
> >
> > #pragma comment(lib, "library.lib")
> >
> > directve, that causes the compiler to pass the quoted file name to the
> > linker. The linker is expected to add this file name to the list of
> > libraries to be searched for external symbols. Is there a similar mechanism
> > in gcc/g++?

Maybe some short "introduction". 
When you compile file, gcc (gcc -c some.c -o some.o) (-c option means
compile file but do not link) makes object file, eg. some.o.
If you want to compile another file and link it with some.o. Then you can write:
gcc another.c some.o
gcc will automatically compile another.c, and pass those two files
(object file of another.c and some.o) to linker.

>From manual:
 The only difference between using an -l option and specifying a file
(my example) name is that -l surrounds "library" with `lib' and `.a'
and searches several directories. (eg.: gcc -llibrary means find file
named liblibrary.a and link with it, the same goes with dynamic
libraries...)

Arturas Moskvinas
P.S.: if you will compile C++ program, do not use "gcc file.cpp" (or
file.cc)(it will complain about linking problems...), use gcc-c++:
"c++ file.cpp".


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux