public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Passing names of libraries to linker.
@ 2005-06-29 18:37 Angel Tsankov
  2005-06-29 20:00 ` Arturas Moskvinas
  0 siblings, 1 reply; 4+ messages in thread
From: Angel Tsankov @ 2005-06-29 18:37 UTC (permalink / raw)
  To: gcc-help mailing list

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++? 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Passing names of libraries to linker.
  2005-06-29 18:37 Passing names of libraries to linker Angel Tsankov
@ 2005-06-29 20:00 ` Arturas Moskvinas
  2005-06-29 20:15   ` Arturas Moskvinas
  2005-06-29 23:26   ` Rupert Wood
  0 siblings, 2 replies; 4+ messages in thread
From: Arturas Moskvinas @ 2005-06-29 20:00 UTC (permalink / raw)
  To: Angel Tsankov; +Cc: gcc-help mailing list

> 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++?

I do not think this behavior (#pragma comment(lib, "library.lib")) is
written in C or C++ standart (gcc is refering to these standarts not
to microsoft or any other...).

I think your answer about linking will be answered on this page:
http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Link-Options.html

Arturas Moskvinas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Passing names of libraries to linker.
  2005-06-29 20:00 ` Arturas Moskvinas
@ 2005-06-29 20:15   ` Arturas Moskvinas
  2005-06-29 23:26   ` Rupert Wood
  1 sibling, 0 replies; 4+ messages in thread
From: Arturas Moskvinas @ 2005-06-29 20:15 UTC (permalink / raw)
  To: Angel Tsankov; +Cc: gcc-help mailing list

> > 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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Passing names of libraries to linker.
  2005-06-29 20:00 ` Arturas Moskvinas
  2005-06-29 20:15   ` Arturas Moskvinas
@ 2005-06-29 23:26   ` Rupert Wood
  1 sibling, 0 replies; 4+ messages in thread
From: Rupert Wood @ 2005-06-29 23:26 UTC (permalink / raw)
  To: 'Arturas Moskvinas', 'Angel Tsankov'
  Cc: 'gcc-help mailing list'

Arturas Moskvinas wrote:

> I do not think this behavior (#pragma comment(lib, "library.lib"))
> is written in C or C++ standart (gcc is refering to these standarts
> not to microsoft or any other...).

GCC has plenty of extensions of its own. Virtually all compilers do. And it
does even borrow some of the Microsoft ones, e.g. dllimport/export, for
Windows compatibility.

The point of #pragma comment(lib, ...) is convenience. The MFC header file
afx.h, for example, has a large preprocessor block in it which works out
which MFC lib flavour you need from the #defines you're building with
(NDEBUG, _UNICODE, etc.) and comment-libs the right one in for you
automatically. All you need to do is #include <afx.h> and it All Just Works.
There's no reason this couldn't work for say KDE headers or ncurses on unix
say.


Angel,

No - nice though it'd be, I don't think there is.

One thing you'll discover coming to unixes from Windows is that it's very
sensitive about the order you link libraries in; if you were implementing
#pragma comment(lib) on unix, you'd probably get all the commented libraries
and put them at the front of the link order but you'd need some logic to
work out what order they should be linked in in; you can imagine it'd be
easy enough to get the same two comments in different orders in different
compilation units because the header files were included the other way
around. That not insurmountable, but there's probably plenty of nasty corner
cases if you think about it hard enough. Best leave it to someone else :-)

Rup.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-29 23:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-29 18:37 Passing names of libraries to linker Angel Tsankov
2005-06-29 20:00 ` Arturas Moskvinas
2005-06-29 20:15   ` Arturas Moskvinas
2005-06-29 23:26   ` Rupert Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).