Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the LIB and LIBPATH environment variables for MS Visual C/C++?

I've been working on some build scripts, and this is bugging me. I want to be sure that we're independent of environment settings, but in order to be sure of that I feel a need to understand how/where the settings are used by the tools.

The Visual Studio command prompt and/or vcvarsall.bat file set up two distinct environment variables: LIB and LIBPATH. The values are different, but partially overlapping. Here are the values from my system:

LIB=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Windows Kits\8.0\lib\win8\um\x86;  LIBPATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v3.5;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral;\Microsoft.VCLibs\11.0\References\CommonConfiguration\neutral; 

I'd just like to understand the rationale for having two different variables -- a little more than the obvious fact that LIBPATH brings in more libs. I've tried looking it up, but I haven't found a clear definition of when each is used by the linker and/or the dev environment.

like image 960
Richard Schwartz Avatar asked Dec 10 '13 00:12

Richard Schwartz


People also ask

What is LIB environment variable?

The LIB environment-variable is passed to the linker, and helps it to find and import . lib files. And that, no matter if . lib file belongs to dynamic or static library. The LIBPATH environment-variable is passed to the compiler, and helps it to find meta-data files.

What are the types of environment variables?

There are two types of environment variables: user environment variables (set for each user) and system environment variables (set for everyone).

What is Lib path?

The LIBPATH environment variable tells the shell on AIX® systems which directories to search for dynamic-link libraries for the INTERSOLV DataDirect ODBC Driver. You must specify the full path name for the directory where you installed the product.

How do I add a path to environment variable in Visual Studio?

In the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.


1 Answers

LIB is for the linker, helps it find import and static libraries.

LIBPATH is for the compiler, helps it find metadata files. Like type libraries, .NET assemblies, WinRT .winmd files.

like image 122
Hans Passant Avatar answered Nov 04 '22 00:11

Hans Passant