[CMake] Win32: Link failure with ADD_LIBRARY SHARED

Stephen Collyer scollyer at netspinner.co.uk
Thu Nov 15 10:02:30 EST 2007


I have a trivial project that builds a single executable and
a library against which it links. The source tree looks like:

src/exe/test_prog.cpp
src/lib/Test.cpp, Test.h

When I set up the cmake files to build a static library the
test_prog exe builds and runs fine on both Linux and Win32.

When I add a SHARED specifier to the ADD_LIBRARY command for
the Test library, the exe builds and run fine on Linux, but
fails at link time when the projects are built under Visual
Studio, with a message:

LINK : fatal error LNK1104: cannot open file 'Test.lib'

Now, I'm no Windows expert but AFAIK, linking against a
DLL is done by looking at the contents of a .lib file,
which indicates the symbols exported by the DLL. However,
there's no .lib file at all in the build tree, so I'm
confused as to what's going on here. Can someone explain ?

In addition, now I've started thinking about it, I'm
confused as to how cmake know whether to link statically
or against shared libraries. Is this purely down to the
presence or absence or SHARED in the ADD_LIBRARY commands ?
i.e if a library is built shared, cmake tries to link against
that, and if built static, similarly, and there's no way
to override it.

-- 
Regards

Steve Collyer
Netspinner Ltd


More information about the CMake mailing list