[CMake] import library

Brad King brad.king at kitware.com
Fri Jun 12 13:04:04 EDT 2009


Tyler Roscoe wrote:
> On Fri, Jun 12, 2009 at 05:46:39PM +0200, Leon Aronson (DT) wrote:
>> I'm not generating dll's (at least I intend to); it should
>> all be static linking.
> 
> Static libraries are also controlled by ARCHIVE_OUTPUT_DIRECTORY.
> 
> If you are using static libraries then you don't get (or need) an import
> library, so I guess I don't understand your question. Static libraries
> have the extension .lib on Windows (unfortunately, the same as import
> libraries).  If you are getting a .dll out of your build process, you
> are not producing static libraries.

Executables can produce import libraries too if one of the object files
marks a symbol with __declspec(dllexport).

I've reproduced the problem like this:

   # CMakeLists.txt
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
   add_executable(foo foo.c)

   /* foo.c */
   __declspec(dllexport) void foo(void) {}
   int main() { return 0; }

I get the error

   1>Linking...
   1>   Creating library C:\...\Debug\foo.lib and object C:\...\Debug\foo.exp
   1>LINK : fatal error LNK1104: cannot open file 'C:\...\Debug\foo.lib'

VS is not complaining that it cannot *find* the .lib file...it's
complaining that it cannot *create* it.  The reason is that the
directory does not exist.  If I make the directory by hand before
building then it works.

I'm investigating CMake internals to find the cause.

-Brad


More information about the CMake mailing list