[CMake] CMake with cminpack, link libraries
mhertling at online.de
Sat Nov 26 19:27:25 EST 2011
On 11/25/2011 05:02 PM, Fabian Torres wrote:
> I'm trying to use cminpack. I've downloaded cminpack 1.1.3 and configure it
> with cmake to create a Xcode 3.2 project. After building the xcode project
> successfully I found that it generates a debug directory which contains the
> library or if the shared_libs option in cmake was on or off respectively.
> The examples works fine.
> Know I'm creating an Xcode project with Cmake in which I'm going to use the
> cminpack function lmdif1 I attach the CMakelist.txt which I'm using. I have
> no problems in generating the xcode project with CMake, but when I build
> the project I get the next errors
> "_dpmpar", referenced from _main ProbeClaibration.o
> "_lmdif1", referenced from _main ProbeCalibration.o
> Symbol(s) not found
> After some research I found that it may be a problem linking the cminpack
> library.I'm new using CMake and I'm not sure if I`m using the correct
> method to link the cminpack libraries with
No, you don't. LINK_DIRECTORIES() just provides the linker with a
hint where it should look for libraries, but it neither specifies
the actual libraries to link against nor performs any link action
by itself. Instead, you need to mention the CMinpack library in
TARGET_LINK_LIBRARIES() as you do with the VTK/ITK ones.
However, you shouldn't use LINK_DIRECTORIES() at all, see [1,2].
Instead, use FIND_LIBRARY(CMinpack_LIBRARY cminpack), so you can
give CMake a hint where to search via CMAKE_PREFIX_PATH et al. or
preset CMinpack_LIBRARY on the command line or the GUI. If you're
just doing so, do the same for the include directories, too, e.g.
FIND_PATH(CMinpack_INCLUDE_DIR cminpack.h PATH_SUFFIXES cminpack-1)
and because you're just doing so - ;-) - combine these actions in a
FindCMinpack.cmake module to use with FIND_PACKAGE(), see  for
Anyway, since CMinpack can already be built by means of CMake, the
premier solution is, IMO, to ask the CMinpack people to provide a
configuration file cminpack-config.cmake or the like. The latter
would be installed along with the other files of the package, so
using CMinpack in an own project would roughly read as follows:
> I wonder if you can help me figure it out. And also want to know which
> library do you recomend mi to use, the static libcminpack.a lib or the
> dynamic libcminpack.dlyb lib.
Usually, one prefers shared libraries unless one has a reason to choose
the static ones. FIND_LIBRARY() also prefers shared to static libraries
if it's not told otherwise, e.g. as FIND_LIBRARY(... libcminpack.a).
> Thanks for your help. I`m really stuck on this and I need to solve my
> problem as soon as possible.
'hope that helps, and feel free to ask anew if things still don't work.
More information about the CMake