[CMake] How to specify that a target link library is shared ?

Eric Noulard eric.noulard at gmail.com
Tue Oct 7 13:46:01 EDT 2008


2008/10/7 Andrea Borsic <Andrea.Borsic at dartmouth.edu>:
> Dear All,
>
> I am a recent user of CMake, and I cannot figure out how to tell CMake that
> a TARGET_LINK_LIBRARY is shared. I am working under Windows Xp with MS
> VisualStudio 2008, and the following is my CMakeLists file:
>
> PROJECT(Triangle)
>
> ADD_LIBRARY(triangle_lib SHARED triangle.c)
>
> ADD_EXECUTABLE(tricall tricall.c)
>
> TARGET_LINK_LIBRARIES(tricall triangle_lib)
>
> With the first target I am building a shared library 'triangle_lib.dll' and
> with the second target I'd like to build an executable 'tricall' that links
> to such library.
>
> Linking fails, as VS 2008 is looking for the static library
> 'triangle_lib.lib'.

I'm no windows expert but
as far as I know "triangle_lib.lib" is not a static lib but a lib needed
for compiling?or?linking a program which uses triangle_lib.dll.

triangle_lib.lib should be built along with triangle_lib.dll when compiling
the lib.

Is triangle_lib.dll generated properly in the build directory?

>I have been searching the forums, and came across an
> example: TARGET_LINK_LIBRARIES(tricall SHARED triangle_lib), but then the
> linker looks for SHARED.lib, so 'SHARED' in not interpreted as a keyword but
> as the name of a library.
>
> Does anybody know how I should specify that I am linking against a shared
> library ?

Normally you don't have to,
moreover in this case your lib is a CMake target of the same
project. CMake should find it without trouble.

Is your CMakeLists.txt just as you wrote it?
If you have 4 files you may post your whole project here?
Which version of CMake do you use?


-- 
Erk


More information about the CMake mailing list