Handmade Hero»Forums»Code
6 posts
How does the compiler find the libraries from the command line? (Dsound.lib for example)
This question arose when I was compiling a program in Visual Studio and had linker errors because Visual Studio couldn't find the Dsound library. What I'm trying to understand is why you have to specify the location for libraries when you are compiling in Visual Studio, and don't have to do this when you are compiling from the command line. It can't possibly search the entire harddisk every time it has to compile right?

1
2
3
4
@echo off
mkdir ..\..\build
pushd ..\..\build 
cl -FC  -Zi ..\code\win32_minisynth.cpp User32.lib Dsound.lib
Mārtiņš Možeiko
2559 posts / 2 projects
How does the compiler find the libraries from the command line? (Dsound.lib for example)
Edited by Mārtiņš Možeiko on
VS IDE finds library exactly same way how command line cl finds it. There are no differences.
So if you would open project properties and add "dsound.lib" to the list in Linker->Input->Additional Dependencies it should work (because you are saying it works in commandline). As long as your VS or Windows SDK setup is not messed up.

Back to the question how does cl.exe finds it. It finds it by looking .lib files in folders that are listed in LIB environment variable. It is documented in multiple places in MSDN, for example: https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx and https://msdn.microsoft.com/en-us/library/aa278377.aspx

This variable is set up by "vcvarsall.bat". You can check contents of LIB variable by executing "echo %LIB%" on commandline.
6 posts
How does the compiler find the libraries from the command line? (Dsound.lib for example)
Cool! Thanks a lot for clearing that up Mārtiņš.