Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linking with a pragma with g++

In Visual C++, one may link to a library in the code itself by doing #pragma comment (lib, "libname.lib"). Is something similar possible in g++?

like image 431
Epro Avatar asked Oct 20 '10 01:10

Epro


People also ask

Does pragma work in GCC?

GCC supports several types of pragmas, primarily in order to compile code originally written for other compilers. Note that in general we do not recommend the use of pragmas; See Function Attributes, for further explanation.

What is linking in GCC?

Linking is the process of collecting and combining various pieces of code and data into a single file that can be loaded (copied) into memory and executed. Linking is performed automatically by programs called linkers, which enable separate compilation.


1 Answers

The Boost Config library has some support for autolinking, using the relevant compiler-specific code for the particular compiler. However, the docs note that the GCC toolchain doesn't support autolinking:

Auto-Linking

Most Windows compilers and linkers have so-called “auto-linking support,” which eliminates the second challenge. Special code in Boost header files detects your compiler options and uses that information to encode the name of the correct library into your object files; the linker selects the library with that name from the directories you've told it to search.

The GCC toolchains (Cygwin and MinGW) are notable exceptions; GCC users should refer to the linking instructions for Unix variant OSes for the appropriate command-line options to use.

like image 72
Cheers and hth. - Alf Avatar answered Sep 19 '22 13:09

Cheers and hth. - Alf