cmake: Targets may link only to libraries [solved]

13,291 views
Skip to first unread message

Dustin Lang

unread,
Sep 18, 2013, 10:28:32 PM9/18/13
to ceres-...@googlegroups.com
While writing this post I figured out the answer; posting anyway for posterity.

I'm trying to get ceres built on a linux box with libraries installed in ~/software.

Suitesparse in particular has mostly .a libraries.

I am running:

```
export CC=gcc
export CXX=g++
SSlib=/home/dstn/software/suitesparse-4.1.2/lib
SSinc=/home/dstn/software/suitesparse-4.1.2/include

mkdir ceres-build
cd ceres-build
cmake ../ceres-solver-1.7.0 -DCMAKE_INCLUDE_PATH="${HOME}/software/eigen" -DGFLAGS_LIB="${HOME}/software/gflags-2.0/lib/libgflags.a" -DGFLAGS_INCLUDE=~/software/gflags-2.0/include -DGLOG_LIB=~/software/glog-0.3.3/lib/libglog.a -DGLOG_INCLUDE=~/software/glog-0.3.3/include -DLAPACK_LIBRARIES=${ATLAS_DIR}/lib/libatlas.a -DBLAS_LIBRARIES=${ATLAS_DIR}/lib/libcblas.a -DAMD_LIB=$SSlib/libamd.a -DAMD_INCLUDE=$SSinc -DCAMD_LIB=$SSlib/libcamd.a -DCAMD_INCLUDE=$SSinc -DCOLAMD_LIB=$SSlib/libcolamd.a -DCOLAMD_INCLUDE=$SSinc -DCCOLAMD_LIB=$SSlib/ccolamd.a -DCCOLAMD_INCLUDE=$SSinc -DCHOLMOD_LIB=$SSlib/libcholmod.a -DCHOLMOD_INCLUDE=$SSinc -DSUITESPARSEQR_LIB=$SSlib/libspqr.a -DSUITESPARSEQR_INCLUDE=$SSinc -DSUITESPARSE_CONFIG_LIB=$SSlib/libsuitesparseconfig.a -DSUITESPARSE_CONFIG_INCLUDE=$SSinc -DMETIS_LIB=$SSlib/libmetis.a
```

Note that you have to include the full path to the .a files; if you just give the path to the "lib" directory, cmake will succeed with warnings like:

```
...
-- Found AMD library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found AMD header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found CAMD library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found CAMD header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found COLAMD library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found COLAMD header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found CCOLAMD library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found CCOLAMD header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found CHOLMOD library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found CHOLMOD header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found SUITESPARSEQR library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found SUITESPARSEQR header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found SuiteSparse_config library: /home/dstn/software/suitesparse-4.1.2/lib
-- Found SuiteSparse_config header in: /home/dstn/software/suitesparse-4.1.2/include
-- Found METIS library: /home/dstn/software/suitesparse-4.1.2/lib
...
-- Configuring done
WARNING: Target "ceres" requests linking to directory "/home/dstn/software/glog-0.3.3/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "ceres" requests linking to directory "/home/dstn/software/gflags-2.0/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "ceres" requests linking to directory "/home/dstn/software/suitesparse-4.1.2/lib".  Targets may link only to libraries.  CMake is dropping the item.
```

The build of libceres.a then succeeds, except it seems not to link against the libraries (as you might guess from the warnings).

If you specify the full paths to the .a files, cmake finishes without warning and the build succeeds... almost.

I am getting:

```
Linking CXX executable ../../bin/c_api_test
cd /home/dstn/software/ceres-build/internal/ceres && /home/dstn/software/cmake-2.8.11.2/bin/cmake -E cmake_link_script CMakeFiles/c_api_test.dir/link.txt --verbose=1
/clusterfs/riemann/software/gcc/4.7.2/bin/g++    -fopenmp -Werror -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -O3 -DNDEBUG  -march=native -mtune=native    CMakeFiles/c_api_test.dir/c_api_test.cc.o  -o ../../bin/c_api_test -rdynamic ../../lib/libtest_util.a ../../lib/libceres.a ../../lib/libgtest.a -Wl,-Bstatic -latlas -lcblas -Wl,-Bdynamic -lgomp /home/dstn/software/gflags-2.0/lib/libgflags.a /home/dstn/software/glog-0.3.3/lib/libglog.a
../../lib/libceres.a(lapack.cc.o): In function `ceres::internal::LAPACK::SolveInPlaceUsingCholesky(int, double const*, double*)':
lapack.cc:(.text+0x3d): undefined reference to `dpotrf_'
lapack.cc:(.text+0xca): undefined reference to `dpotrs_'
../../lib/libceres.a(lapack.cc.o): In function `ceres::internal::LAPACK::SolveUsingQR(int, int, double const*, int, double*, double*)':
lapack.cc:(.text+0x1c1): undefined reference to `dgels_'
../../lib/libceres.a(lapack.cc.o): In function `ceres::internal::LAPACK::EstimateWorkSizeForQR(int, int)':
lapack.cc:(.text+0x245): undefined reference to `dgels_'
../../lib/libceres.a(blas.cc.o): In function `ceres::internal::BLAS::SymmetricRankKUpdate(int, int, double const*, bool, double, double, double*)':
blas.cc:(.text+0x6d): undefined reference to `dsyrk_'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/c_api_test] Error 1
```

which looks like it's assuming "-latlas -lcblas", rather than whatever cmake figured out is the way to link the (static, in my case) ATLAS libraries.

cheers,
--dustin

Sameer Agarwal

unread,
Sep 19, 2013, 1:19:32 AM9/19/13
to ceres-...@googlegroups.com
Nice debugging Dustin. Once you are done installing, instead of just keeping this in the mailinglist, maybe I can convince you to add to the section in the documentation on building and installing ceres.
Sameer



--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/7bc47f76-9920-4fa7-ac38-4bcce568143d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages