[CMake] DLL and lib file

Brad King brad.king at kitware.com
Wed Dec 1 19:12:11 EST 2004


Sergio Andres wrote:
> I have a problem with DLL libraries.
> I generated a (MSVC60) project with CMake to create a DLL library.
> Then, I compiled the code and I got a new .dll and a .lib file ( import 
> lib file for the DLL)
> 
> I also used CMake to generate other project to create an executable, 
> which uses the previous library.
> The problem is that the dll is not found, unless it is in the .exe file 
> directory.

By "dll is not found" do you mean that the linker does not build your 
executable or that running your executable fails to find the dll at 
run-time?

If it is the latter, then this is just a standard feature of Windows. 
When an executable runs there is a certain set of places where Windows 
looks for its DLL's.  This typically includes something like:

- The directory containing the executable
- The current working directory
- Directories in the PATH environment variable
- The windows system directory

I'm not sure about the order or if there are more places off the top of 
my head.

There isn't much CMake can do about this on Windows.  On UNIX there is a 
notion of an "rpath", or run-time path that is a list built into the 
executable of places to look for shared libraries.  This feature is not 
provided by Windows.

If you put the directory containing the DLL into your PATH then you 
should be able to run your program without copying the DLL to the 
executable's directory.  You can also create a .BAT file that sets up 
the PATH environment variable and then executes your program.

-Brad



More information about the CMake mailing list