[CMake] IMPORTED_LOCATION

Brad King brad.king at kitware.com
Mon Dec 1 14:56:54 EST 2008


Micha Renner wrote:
> I have two questions for the listening below.
> 
> 1. Out-commenting the line #4
> results in a linker error LINK : fatal error LNK1104: File
> "_sLib-NOTFOUND.obj" can't be opened"
> 
> What is the purpose of this command (line #4)?

When one adds a shared library that is built in the project, CMake knows 
both the dll and lib location that it will build.  It is useful in some 
cases to know both locations even for imported targets (like configuring 
an environment with the location of the dll in its PATH).

If you change the library type to UNKNOWN (2.6.2 and higher) then you 
can just set IMPORTED_LOCATION with the location of the lib and forget 
the dll.

> 2. If line #4 is active. An inspection of the project properties (link
> -> command line) shows in the implib-section the following result:
> /IMPLIB:"C:\WORK-C\ArchiveCMake\CMakeListsNeu\BuildDLL-2\TestDLL\CMake
> \Debug\TestDll2.lib" /ERRORREPORT:PROMPT kernel32.lib user32.lib
> gdi32.lib winspool.lib shell32.lib ole32.lib 
> oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  
> \WORK-C\ArchiveCMake\CMakeListsNeu\BuildDLL-2\DLL\CMake\Debug\SLib.lib
> 
> For what reason is there a TestDll2.lib?

If any object files in the executable have a __declspec(dllexport) then 
the linker will produce an import library for the executable.  This 
tells it where to put the library.  Usually it doesn't show up, but 
CMake adds the option just in case.  It is useful when exporting symbols 
from an executable for use by plugins it loads.

> 3:ADD_LIBRARY(_sLib SHARED IMPORTED)
> 4:SET_PROPERTY(TARGET _sLib PROPERTY IMPORTED_LOCATION /Path/SLib.dll) 
> 5:SET_PROPERTY(TARGET _sLib PROPERTY IMPORTED_IMPLIB /Path/SLib.lib)

As mentioned above, you can write

CMAKE_MINIMUM_REQUIRED(VERSION 2.6.2)
ADD_LIBRARY(_sLib UNKNOWN IMPORTED)
SET_PROPERTY(TARGET _sLib PROPERTY IMPORTED_LOCATION /Path/SLib.lib)

-Brad


More information about the CMake mailing list