Home > database >  What's the syntax for LIBS environment variable?
What's the syntax for LIBS environment variable?

Time:11-05

There is a LIBS environment variable for mpicxx. But the man page only says

Libraries added when invoking the linker

I wish to know detailed syntax for this variable, for example, should we prefix -L before directory, should we just write the directory name or the lib filename, should we separate multiple libraries by space or comma or something else, etc.? I tried to google the syntax but could find no information about it. So I ask here. Thanks for your help.

CodePudding user response:

I wish to know detailed syntax for this variable

The LIBS variable recognized by MPI compiler wrappers is not specific to those programs, and it does not have a syntax of its own. The variable is just expanded (unquoted) to form part of the link command line, at a position among the arguments appropriate for the designation of libraries to include in the link. The general syntax is a subset of the syntax of shell commands, and the specific significance of the contents is governed by linker.

Do note that to the extent that it matters, "the linker" is probably not ld directly, but rather (for mpicxx) a C compiler front-end such as g . You specify libraries and library search path entries in the same form that you would do when linking your program with a non-MPI C compiler.

should we prefix -L before directory

If you want to add directories to the library search path then yes, you would use -L options.

should we just write [...] the lib filename

Most conventional would be to use -l options, so to link libfoo.so, you would use -lfoo. Alternatively, you should also be able to specify a relative or absolute path to the library file (without -l), in which case the search path is irrelevant. Specifying libraries via a specific path is normally used only for libraries built as part of the same project.

should we separate multiple libraries by space or comma or something else

You are specifying options and arguments that are expanded to be part of a shell command. Multiple arguments must be separated by whitespace.

etc.

The details all follow from the manner in which the variable is used, as already described. Some available features (but not usually anything described above) may vary from system to system, depending on the options recognized by the underlying linker.

  • Related