[CMake] how to use external gnu make library
kdsfinger at gmail.com
kdsfinger at gmail.com
Tue Mar 14 01:01:27 EST 2006
With the FindGSL.cmake copy to the CMake module dir, Here is my
CMakeLists.txt (with TARGET_LINK_LIBRARIES)
*PROJECT*(test1)*FIND_PACKAGE*(GSL)*ADD_DEFINITIONS*(-Wall -O2)*#list
all source files here**ADD_EXECUTABLE*(test1
main.cpp)*TARGET_LINK_LIBRARIES*(test1 gsl_sf_bessel_j0)
but still got the error
Linking CXX executable test1
/usr/local/bin/cmake -E remove -f test1
c++ -fPIC "CMakeFiles/test1.dir/main.o" -o test1 -rdynamic
-lgsl_sf_bessel_j0
/usr/bin/ld: cannot find -lgsl_sf_bessel_j0
collect2: ld returned 1 exit status
for the gsl sample program
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
What should I do to make it work? I am using linux so it should work
somehow. Many thanks.
zl2k
On 3/13/06, Jan Woetzel <jw at woetzelweb.de> wrote:
>
> kdsfinger at gmail.com wrote:
>
> > I am trying to use the gnu gsl package in vtk. The gsl is make
> > installed by gnu, not cmake. How can I use the library in my vtk
> > project? I put something like
> > FIND_PACKAGE(GSL)
>
> Does a "FindGSL.cmake" script exist and does cmake find it?
> See the cmake FIND_PACKAGE help.
>
> As far as I know CMake does not come with a "standard" find script for
> GSL, thus you have to write one yourself .
> The CMake "Modules" directory contains examples.
>
> We already created our own simple GSL find, see teh attached file.
> It is simply based on "gsl-config", actually and works only on Linux.
>
> Jan.
>
> --
>
> Dipl.-Ing. Jan Woetzel
> --------------------------------------------------
> Uni Kiel
> Institut f. Informatik und Praktische Mathematik
> Hermann-Rodewaldstr. 3 [Raum 310]
> 24098 Kiel/Germany
> --------------------------------------------------
> Tel +49-431-880-4477
> Fax +49-431-880-4054
> Privat +49-431-802872
> Mob. +49-179-2937346
> --------------------------------------------------
> Url www.mip.informatik.uni-kiel.de/~jw
> Email jw at mip.informatik.uni-kiel.de
> Privat jw at WoetzelWeb.de
>
>
>
> ##
> ## Try to find gnu scientific library GSL
> ## (see http://www.gnu.org/software/gsl/)
> ## Once run this will define:
> ##
> ## GSL_FOUND = system has GSL lib
> ##
> ## GSL_LIBRARIES = full path to the libraries
> ## on Unix/Linux with additional linker flags from "gsl-config --libs"
> ##
> ## CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially
> "`gsl-config --cxxflags`"
> ##
> ## GSL_INCLUDE_DIR = where to find headers
> ##
> ## GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
> ## GSL_EXE_LINKER_FLAGS = rpath on Unix
> ##
> ## Felix Woelk 07/2004
> ## minor corrections Jan Woetzel
> ##
> ## www.mip.informatik.uni-kiel.de
> ## --------------------------------
>
> IF(WIN32)
> MESSAGE(SEND_ERROR "FindGSL.cmake: gnu scientific library GSL not (yet)
> supported on WIN32")
>
> ELSE(WIN32)
> IF(UNIX)
> SET(GSL_CONFIG_PREFER_PATH "$ENV{GSL_HOME}/bin" CACHE STRING
> "preferred path to OpenSG (osg-config)")
> FIND_PROGRAM(GSL_CONFIG gsl-config
> ${GSL_CONFIG_PREFER_PATH}
> /usr/bin/
> )
> # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}")
>
> IF (GSL_CONFIG)
> # set CXXFLAGS to be fed into CXX_FLAGS by the user:
> SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`")
>
> # set INCLUDE_DIRS to prefix+include
> EXEC_PROGRAM(${GSL_CONFIG}
> ARGS --prefix
> OUTPUT_VARIABLE GSL_PREFIX)
> SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL)
>
> # set link libraries and link flags
> SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`")
>
> ## extract link dirs for rpath
> EXEC_PROGRAM(${GSL_CONFIG}
> ARGS --libs
> OUTPUT_VARIABLE GSL_CONFIG_LIBS )
>
> ## split off the link dirs (for rpath)
> ## use regular expression to match wildcard equivalent
> "-L*<endchar>"
> ## with <endchar> is a space or a semicolon
> STRING(REGEX MATCHALL "[-][L]([^ ;])+"
> GSL_LINK_DIRECTORIES_WITH_PREFIX
> "${GSL_CONFIG_LIBS}" )
>
> # MESSAGE("DBG GSL_LINK_DIRECTORIES_WITH_PREFIX=${GSL_LINK_DIRECTORIES_WITH_PREFIX}")
>
> ## remove prefix -L because we need the pure directory for
> LINK_DIRECTORIES
>
> IF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
> STRING(REGEX REPLACE "[-][L]" "" GSL_LINK_DIRECTORIES
> ${GSL_LINK_DIRECTORIES_WITH_PREFIX} )
> ENDIF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
> SET(GSL_EXE_LINKER_FLAGS "-Wl,-rpath,${GSL_LINK_DIRECTORIES}" CACHE
> STRING INTERNAL)
> # MESSAGE("DBG GSL_LINK_DIRECTORIES=${GSL_LINK_DIRECTORIES}")
> # MESSAGE("DBG GSL_EXE_LINKER_FLAGS=${GSL_EXE_LINKER_FLAGS}")
>
> # ADD_DEFINITIONS("-DHAVE_GSL")
> # SET(GSL_DEFINITIONS "-DHAVE_GSL")
> MARK_AS_ADVANCED(
> GSL_CXX_FLAGS
> GSL_INCLUDE_DIR
> GSL_LIBRARIES
> GSL_LINK_DIRECTORIES
> GSL_DEFINITIONS
> )
> MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
>
> ELSE(GSL_CONFIG)
> MESSAGE("FindGSL.cmake: gsl-config not found. Please set it
> manually. GSL_CONFIG=${GSL_CONFIG}")
> ENDIF(GSL_CONFIG)
>
> ENDIF(UNIX)
> ENDIF(WIN32)
>
>
> IF(GSL_LIBRARIES)
> IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
>
> SET(GSL_FOUND 1)
>
> ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
> ENDIF(GSL_LIBRARIES)
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20060314/fc8d5c2e/attachment.htm
More information about the CMake
mailing list