Pragma linking?

Started by Magnus Haganderover 19 years ago5 messages
#1Magnus Hagander
mha@sollentuna.net

When working through my cleanup of the vc++ build scripts, I came across
a handy feature. I originally thought it'd cut down the size of my
scripts, and it does - but not very much. However, it might be handy
elsewhere. I have no idea if this feature is available for other
platforms/compilers.

For VC++ you can add a #pragma directive to the header files to direct
the compiler/linker to link with a specific library. This could be used
to automatically link with libpq whenever libpq-fe.h is brought in, and
similar things for the backend (links to postgres.exe) and ecpg.
(Naturally, there'd be a #define you can set to have it *not* do this,
for special cases). That would make it even easier to build client and
server projects - if you use MSVC++.

What do you think? If it's good, I can incorporate it in the next
version of the VC++ patch.

//Magnus

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Magnus Hagander (#1)
Re: Pragma linking?

"Magnus Hagander" <mha@sollentuna.net> writes:

For VC++ you can add a #pragma directive to the header files to direct
the compiler/linker to link with a specific library.

Count on Microsoft to invent stupid "features" :-(. If the directive
includes a full path then we can't put it in our standard headers, and
if it doesn't then it's useless.

regards, tom lane

#3Magnus Hagander
mha@sollentuna.net
In reply to: Tom Lane (#2)
Re: Pragma linking?

For VC++ you can add a #pragma directive to the header

files to direct

the compiler/linker to link with a specific library.

Count on Microsoft to invent stupid "features" :-(.

I guess stupid is a relative matter - I find it quite handy.

If the directive includes a full path then we can't put it in our
standard headers, and if it doesn't then it's useless.

It can optionally include the full path. Which we can't use, of course.

It will work just fine when you don't, as long as you include the
directory where the lib file is in your LIB path. Which is the same way
the linker commandline option works. I don't see how that makes it
useless, though.

//Magnus

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Magnus Hagander (#3)
Re: Pragma linking?

"Magnus Hagander" <mha@sollentuna.net> writes:

It will work just fine when you don't, as long as you include the
directory where the lib file is in your LIB path. Which is the same way
the linker commandline option works. I don't see how that makes it
useless, though.

If you have to include (the equivalent of) -L in your link command
anyway, I don't see where being able to leave off -l buys much.

regards, tom lane

#5Magnus Hagander
mha@sollentuna.net
In reply to: Tom Lane (#4)
Re: Pragma linking?

It will work just fine when you don't, as long as you include the
directory where the lib file is in your LIB path. Which is the same
way the linker commandline option works. I don't see how

that makes it

useless, though.

If you have to include (the equivalent of) -L in your link
command anyway, I don't see where being able to leave off -l
buys much.

You don't, as long as you either stick the LIB file in the default
library directory, or modify the environment variable LIB to include
wherever you stick the LIB file. Both of which could be handled by an
installer.

//Magnus