Dr Deo
Dr Deo

Reputation: 4848

Help on linking in gcc

In Microsoft visual c++ compiler, you can specify linker options using

 #pragma comment(lib, "MSVCRT") //links with the MVCRT library  

see this page

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

Answers (3)

ndim
ndim

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

Mark Rushakoff
Mark Rushakoff

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

Matti Virkkunen
Matti Virkkunen

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

Related Questions