Reputation: 4848
In Microsoft visual c++ compiler, you can specify linker options using
#pragma comment(lib, "MSVCRT") //links with the MVCRT library
I find this feature very useful because linker errors are common and i want to just place all the linker options in my source code instead of specifying them to the compiler.
question: Is there a way to do this in gcc (or dev-cpp or codeblocks ide)?
Thanks in advance.
Upvotes: 1
Views: 825
Reputation: 37885
Given that link options and library names vary very much from system to system, I am quite glad to have them separated from my source code files and thus can keep the source code system independent.
Then the build system can decide how to build on what system. Much cleaner approach overall, I'd say.
Upvotes: 1
Reputation: 258418
GCC doesn't support this because to link correctly, the order in which you link your objects matters.
See also my answer and others in the question "#pragma comment(lib, “xxx.lib”) equivalent under Linux?"
Upvotes: 3
Reputation: 65166
In short, GCC does not support specifying libraries to link in the source code.
If your IDE handles the compilation and linking process, you can probably add references in your IDE and have it worry about passing the correct options to gcc for each unit.
Upvotes: 1