Share via


How do I link libraries that are sitting in different directories from the command line?

Question

Friday, August 24, 2007 2:08 PM

Hi,

for my program, there are a bunch of libraries which I've built that are sitting in their own directories.  Is there a simple way to link them when I build my executable?  The help from cl/? does not seem to provide any option for this.

e.g.

for a simplified case, lets say main.cpp depends on:

C:\ab\ab1.lib
C:\ab\ab2.lib
C:\de\de1.lib
C:\de\de2.lib
C:\gh\gh4.lib

Is there something equivalent to

cl main.cpp /LC:\ab /LC:\de /LC:\gh ab1.lib ab2.lib de1.lib de2.lib gh4.lib /Fo myprog.exe

I really don't want to have

cl main.cpp C:\ab\ab1.lib C:\ab\ab2.lib C:\de\de1.lib C:\de\de2.lib C:\gh\gh4.lib /Fo myprog.exe

since I have a lot of libraries and they are sitting in a few different locations.

thanks,

kevin

All replies (2)

Friday, August 24, 2007 3:40 PM âś…Answered

Try /LIBPATH...

And /LINK to pass options to the linker from cl.exe.

 


Friday, August 24, 2007 6:55 PM | 2 votes

Hi,

thanks for the hint.  I guess the compiler has no provision for specifying a library path, this is purely the domain of the linker.

For anybody who wants to do this, the compile line which works is:

cl main.obj /Fetestmain.exe /link /LIBPATH:C:\test\ab /LIBPATH:C:\test\de /LIBPATH:C:\test\gh ab1.lib ab2.lib de1.lib de2.lib gh4.lib

or

cl main.obj ab1.lib ab2.lib de1.lib de2.lib gh4.lib /Fetestmain.exe /link /LIBPATH:C:\test\ab /LIBPATH:C:\test\de /LIBPATH:C:\test\gh

The "/link" is very important...do not use "/LINK", the uppercase LINK is not recognised.