#pragma comment (lib, "xxx.lib") is the Linux equivalent?

I have a static library file named libunp.a , I know that I could use gcc -lunp xx to reference the library.

I could use #pragma comment(lib,"xxx.lib") to tell the Microsoft C / C ++ compiler to enable the library; how can i do this on linux / gcc?

+52
gcc static-linking
Nov 06 '09 at 3:20
source share
3 answers

Plain; You can not. GCC does not have such an equivalent. Specify -l as the gcc parameter, create a script linker, call ld , call 911 or something else.

Not that such a pragma even made sense. Libraries should be indicated at the linking stage. Such information simply does not belong within the translation unit. The translation unit can be pre-processed, compiled and assembled even without a binding step. The tool binding used by Visual Studio allows this because it is a braindead and always performs the binding.

You might want to keep yourself tedious typing and create a MakeFile for your project: GNU Make Manual

-four
Nov 06 '09 at 3:35
source share

Libraries should be indicated at the linking stage. Such information is simply not included in the translation unit. The translation unit can be pre-processed, compiled and assembled even without a binding step.

Just because #pragma comment(lib,"xxx.lib") is in the source file, this does not mean that the compiler uses it. In fact, it comes as a comment and is subsequently used by the linker. Not much different from * nix.

+18
Nov 26 '10 at 12:23
source share

There seems to be no mention of any equivalent pragmas in the GCC man page in pragmas .

One of the reasons I saw that GCC does not support a link in the source code was that sometimes the correct binding depends on the order of the links ; and this will require you to make sure that the binding order is correct, regardless of the compilation order. If you are going to go for this job, you can simply pass the linker arguments on the command line (or otherwise), I suppose.

+14
Nov 06 '09 at 3:35
source share



All Articles