#pragma comment GCC equivelent

Oct 20, 2011 at 7:52am
Hello Everyone!

I was finding an equivelent for MSVC #pragma comment GCC equivelent. Someone was saying there's nothing ready, you just need to specify .lib files and someone was talking about something that looks like a "-|".

I really don't want to go looking for the .lib files, as I may be working on different PCs.

What to do?

Thanks!
Oct 20, 2011 at 11:32am
What to do?


Specify the library using the linker options. http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

I really don't want to go looking for the .lib files, as I may be working on different PCs.


#pragma comment does not magically fix differences between PCs. If the library is missing, it's missing. You shouldn't have to go looking for them using Visual Studio (which I'm guessing is what you usually use), and you shouldn't have to go looking for them under anything else either. They should be installed to a common directory, or the installtion instructions that came with the library should tell you which sub-directory they are installed to.
Last edited on Oct 20, 2011 at 11:36am
Oct 20, 2011 at 2:55pm
Okay, I am asking this because I want the code to run on different compilers example MSVC, so in the preprocessor directive I can say: if MSVS is defined use pragma else use the GCC equivelent.

Unfortunately there is no such thing, and I have to manually link the libs.

Anyway, thanks for the help. Appreciated!

Sidenote: I wonder why GCC developers haven't thought of such a directive, I mean it could save time.
Oct 21, 2011 at 8:29am
Sidenote: I wonder why GCC developers haven't thought of such a directive, I mean it could save time.


The time spent typing -lsomeLib is surely less than #pragma comment(lib, "someLib") :)

If it's not broken, don't fix it. Amongst other problems, I am told that auto-linking under the MS Visual Studio tool chain assumes that ALL libraries exist in a known location. Windows can store that information in the Registry, which means MS tools can easily track that information down. Different *nixs store their libraries in different locations, and have different mechanisms for keeping track of where they are, updating them, etc. When your environment doesn't provide a consistent mechanism for providing all of this information, providing auto-linking suddenly becomes very, very challenging; especially when downloading source and building locally is common, as is the case for *nix users. Having a slightly different layout to the original author would break the linking.

Additionally, correct linking can depend on the order of linking. Switches on the linker command allow the user to choose the order. Once auto-linking comes onto the scene, this becomes much harder.
Last edited on Oct 21, 2011 at 9:31am
Oct 21, 2011 at 2:49pm
The time spent typing -lsomeLib is surely less than #pragma comment(lib, "someLib") :)


I believe this should be typed in the command line, every time you compile. I don't compile via the command line anyway, but that's good to know.

Thanks again!
Oct 21, 2011 at 11:22pm
At the command line, you compile by typing "make".
Different environments, different ways of doing things.
Topic archived. No new replies allowed.