[CMake] library usage

Mathieu Malaterre mathieu.malaterre at gmail.com
Tue May 12 02:31:58 EDT 2009


On Tue, May 12, 2009 at 3:33 AM, Simon Friedberger
<simon+cmake at a-oben.org> wrote:
> Hello listmembers,
>
> I have just spent the better part of today trying to convert my old
> Makefile to a CMakeLists.txt and failed miserably. I may have made some
> major mistakes since this is my first such effort.
>
> I could not figure out how to include libraries correctly so in the end
> I tried to create the behavior of the old Makefile with cmake and not
> even that worked.
>
> Hence I posted my old Makefile, CMakeLists.txt and linker error at
> http://pastebin.com/m15d2b496
> http://pastebin.com/m23dda234
> http://pastebin.com/m20d3aae7
>
> It would be nice if somebody could take a look at it and give me a
> pointer to what might be wrong.
>
> In the long run an example how to include shared and/or static libraries
> would be preferable of course. If you like I can also post my attempts
> in that direction.

In the cmake world you are expected to list *explicitely* all your
dependencies. Let say we have a library foo which provide foo symbol
and a main which uses it:

SET(libfoo_SRCS
 foo1.c
 foo2.c
 foo3.c
 )
ADD_LIBRARY(foo SHARED ${libfoo_SRCS})

SET(main_SRCS
 bar_main.c # main symbol
 bar1.c
 bar2.c
 bar3.c
 )
ADD_EXECUTABLE(mymain ${main_SRCS})
TARGET_LINK_LIBRARIES(mymain foo)

When linking to static library cmake will do the right thing (tm) for
you (it works for cmake generated lib file, and for properly written
cmake modules).

I am sure there are tons of such examples around (mailing list, or wiki)...

HTH
-- 
Mathieu


More information about the CMake mailing list