ORB SLAM2 build error with eigen3 - eigen3

I am trying to build ORBSLAM2 but i always get some errors. I don't know the reason. I am pasting command line output. How can I solve the errors? has someone done this before?
orbslam#essafius-Latitude-E6430:~$ cd ORB_SLAM2
orbslam#essafius-Latitude-E6430:~/ORB_SLAM2$ chmod +x build.sh
orbslam#essafius-Latitude-E6430:~/ORB_SLAM2$ ./build.sh
Configuring and building Thirdparty/DBoW2 ...
mkdir: cannot create directory ‘build’: File exists
-- Configuring done
-- Generating done
-- Build files have been written to: /home/orbslam/ORB_SLAM2/Thirdparty/DBoW2/build
[100%] Built target DBoW2
Configuring and building Thirdparty/g2o ...
mkdir: cannot create directory ‘build’: File exists
-- BUILD TYPE:Release
-- Compiling on Unix
-- Configuring done
-- Generating done
-- Build files have been written to: /home/orbslam/ORB_SLAM2/Thirdparty/g2o/build
[100%] Built target g2o
Uncompress vocabulary ...
Configuring and building ORB_SLAM2 ...
mkdir: cannot create directory ‘build’: File exists
Build type: Release
-- Using flag -std=c++11.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/orbslam/ORB_SLAM2/build
[ 3%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o
[ 6%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o
[ 9%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o
[ 12%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/System.cc.o
[ 15%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o
In file included from /home/orbslam/ORB_SLAM2/Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h:34:0,
from /home/orbslam/ORB_SLAM2/include/LoopClosing.h:34,
from /home/orbslam/ORB_SLAM2/include/LocalMapping.h:26,
from /home/orbslam/ORB_SLAM2/include/Tracking.h:31,
from /home/orbslam/ORB_SLAM2/include/FrameDrawer.h:24,
from /home/orbslam/ORB_SLAM2/include/Viewer.h:25,
from /home/orbslam/ORB_SLAM2/src/Viewer.cc:21:
/home/orbslam/ORB_SLAM2/Thirdparty/g2o/g2o/types/../core/base_vertex.h:62:74: warning: ‘Eigen::AlignedBit’ is deprecated [-Wdeprecated-declarations]
typedef Eigen::Map<Matrix<double, D, D>, Matrix<double,D,D>::Flags & AlignedBit ? Aligned : Unaligned > HessianBlockType;

https://github.com/raulmur/ORB_SLAM2/issues/317
^Their github log is good for solving common issues, It seems you are having an issue with your Eigen version, get an older one and recompile everything.

Related

Not able to compile C source files using make. CMake error Cannot find source files but they are there

Im trying to compile the posest C++ library
posest : A C/C++ Library for Robust 6DoF Pose Estimation from 3D-2D Correspondences
with make. But when run the make I got the following error
make
-- LEVMAR_INCLUDE_DIR = /usr/local/levmar-2.6
-- LEVMAR_BINARY_DIR = /usr/local/levmar-2.6/w32
-- LAPACKBLAS_DIR = /usr/lib
-- demos will be linked against posest;levmar;lapack;blas;f2c
-- Configuring done
CMake Error at CMakeLists.txt:24 (ADD_LIBRARY):
Cannot find source file:
mlsl/mlsl.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Warning (dev) at CMakeLists.txt:65 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "binocposest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:64 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "posest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error: Cannot determine link language for target "posest".
CMake Error: CMake can not determine linker language for target: posest
-- Generating done
-- Build files have been written to: /home/admini/posest-1.2
Makefile:714: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
But the source file mlsl.c is already there
Here is the contents of the CMakeList.txt file
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(POSEST)
# levmar library
SET(LEVMAR_INCLUDE_DIR "/usr/local/levmar-2.6" CACHE PATH "Path to LEVMAR library header")
#ADD_SUBDIRECTORY(${LEVMAR_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LEVMAR_INCLUDE_DIR})
MESSAGE(STATUS "LEVMAR_INCLUDE_DIR = ${LEVMAR_INCLUDE_DIR}")
IF(MSVC)
ADD_DEFINITIONS(/arch:SSE2)
# get rid of CRT warnings
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC)
INCLUDE_DIRECTORIES(mlsl)
ADD_LIBRARY(posest buckets.c lqs.c ransac.c rngs.c prosac.c deal.c p3p.c p4pf.c planep4p.c svd3.c polysolve.c
poseproj.c posest.c align.c lhm.c sam.c compiler.h lqs.h ransac.h prosac.h p3p.h p4pf.h planep4p.h svd3.h
polysolve.h poseproj.h posest.h util.h rngs.h sam.h
mlsl/mlsl.c mlsl/mt19937ar.c mlsl/redblack.c mlsl/sobolseq.c
)
OPTION(BUILD_DEMOS "Build demo programs?" TRUE)
# demo program
IF(BUILD_DEMOS)
# paths to levmar & lapack/blas libraries
SET(LEVMAR_BINARY_DIR "${LEVMAR_INCLUDE_DIR}/w32" CACHE PATH "Path to levmar library")
MESSAGE(STATUS "LEVMAR_BINARY_DIR = ${LEVMAR_BINARY_DIR}")
SET(LAPACKBLAS_DIR "/usr/lib" CACHE PATH "Path to lapack/blas libraries")
MESSAGE(STATUS "LAPACKBLAS_DIR = ${LAPACKBLAS_DIR}")
# actual names for the lapack/blas/f2c libraries
SET(LAPACKBLAS_LIB_NAMES "lapack;blas" CACHE STRING "The name of the lapack & blas libraries")
SET(F2C_LIB_NAME f2c CACHE STRING "The name of the f2c or F77/I77 library")
# f2c is sometimes equivalent to libF77 & libI77
#SET(F2C_LIB_NAME "libF77;libI77" CACHE STRING "The name of the f2c or F77/I77 library")
SET(LIBS posest levmar)
SET(LIBS ${LIBS} ${LAPACKBLAS_LIB_NAMES} ${F2C_LIB_NAME})
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) # location of the posest library
LINK_DIRECTORIES(${LEVMAR_BINARY_DIR}) # location of the levmar library
LINK_DIRECTORIES(${LAPACKBLAS_DIR})
ADD_EXECUTABLE(posest_demo posest_demo.c)
TARGET_LINK_LIBRARIES(posest_demo ${LIBS})
ADD_EXECUTABLE(binocposest_demo binocposest_demo.c)
TARGET_LINK_LIBRARIES(binocposest_demo ${LIBS})
MESSAGE(STATUS "demos will be linked against ${LIBS}")
# make sure that the libraries are built before the demos
ADD_DEPENDENCIES(posest_demo posest levmar)
ADD_DEPENDENCIES(binocposest_demo posest levmar)
ENDIF(BUILD_DEMOS)
Here the Project Directory screenshot.
And the content of the mlsl directory
/home/posest-1.2/mlsl/mlsl.c
/home/posest-1.2/mlsl/mlsl.h
/home/posest-1.2/mlsl/mt19937ar.c
/home/posest-1.2/mlsl/mt19937ar.h
/home/posest-1.2/mlsl/redblack.c
/home/posest-1.2/mlsl/redblack.h
/home/posest-1.2/mlsl/sobol.h
/home/posest-1.2/mlsl/soboldata.h
/home/posest-1.2/mlsl/sobolseq.c
Im not sure what is the problem. Any help?
I had to download the tar file from the website. It is malformed and won't work.
~/swdev/posest-1.2$ ls -ld mlsl/
drw-r--r-- 2 XXX XXXX 4096 Oct 6 2014 mlsl/
~/swdev/posest-1.2$ chmod u+x mlsl/
~/swdev/posest-1.2$ cmake .
The sources and directories are required to be readable. In this case mlsl has incorrect permissions and CMake cannot read the file. Use the chmod command to fix the permissions on the directory.

C cross compile for raspberry pi with cmake fails to find header file

I'm trying to port a program that runs fine in x86 architecture (Linux Mint 17.1) to a Raspberry Pi (Raspbian Jessie Lite). I'm using CMake, so I just followed the nice guide in Crafty Bytes.
My toolchain-raspberrypi.cmake looks like this:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# Specify the cross compiler
SET(CMAKE_C_COMPILER $ENV{HOME}/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)
#SET(CMAKE_C_FLAGS "-L$ENV{HOME}/rpi/rootfs/usr/lib/arm-linux-gnueabihf -I$ENV{HOME}$ENV{HOME}/rpi/rootfs/usr/include")
# Where is the target environment
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/rpi/rootfs)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
# Search for programs only in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers only in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
CMake generates the Makefiles and seems to find all the required libraries:
$ cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_TOOLCHAIN_FILE=/home/unknown/rpi/toolchain-raspberrypi.cmake ..
-- The C compiler identification is GNU 4.8.3
-- Check for working C compiler: /home/unknown/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/unknown/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of intmax_t
-- Check size of intmax_t - done
-- Check size of uintmax_t
-- Check size of uintmax_t - done
-- Check size of pid_t
-- Check size of pid_t - done
-- Found Lua51: /home/unknown/rpi/rootfs/usr/lib/arm-linux-gnueabihf/liblua5.1.so;/home/unknown/rpi/rootfs/usr/lib/arm-linux-gnueabihf/libm.so (found version "5.1.5")
-- Luaudio_INCLUDE_DIRS: /home/unknown/rpi/rootfs/usr/include/lua5.1
-- LUA_LIBRARIES: /home/unknown/rpi/rootfs/usr/lib/arm-linux-gnueabihf/liblua5.1.so;/home/unknown/rpi/rootfs/usr/lib/arm-linux-gnueabihf/libm.so
-- Found libusb-1.0:
-- - Includes: /home/unknown/rpi/rootfs/usr/include/libusb-1.0
-- - Libraries: /home/unknown/rpi/rootfs/usr/lib/libusb-1.0.a
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- checking for one of the modules 'check'
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found libusb-1.0:
-- - Includes: /home/unknown/rpi/rootfs/usr/include/libusb-1.0
-- - Libraries: /home/unknown/rpi/rootfs/usr/lib/libusb-1.0.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/unknown/projects/ha/workspace/ha/build-rpi
But when I run make I get an error trying to locate a library header:
$ make
Scanning dependencies of target ha
[ 2%] Building C object src/CMakeFiles/ha.dir/log.c.o
[ 5%] Building C object src/CMakeFiles/ha.dir/cm.c.o
/home/unknown/projects/ha/workspace/ha/src/cm.c:13:31: fatal error: libusb-1.0/libusb.h: No such file or directory
#include <libusb-1.0/libusb.h>
^
compilation terminated.
make[2]: *** [src/CMakeFiles/ha.dir/cm.c.o] Error 1
make[1]: *** [src/CMakeFiles/ha.dir/all] Error 2
make: *** [all] Error 2
I'm totally stuck here. The files are there:
$ ls ~/rpi/rootfs/usr/include/libusb-1.0/ -l
total 72
-rw-r--r-- 1 unknown unknown 70156 jun 22 2014 libusb.h
$ ls ~/rpi/rootfs/usr/lib/libusb-1.0.a -l
-rw-r--r-- 1 unknown unknown 109920 jun 22 2014 /home/unknown/rpi/rootfs/usr/lib/libusb-1.0.a
And when running CMake with the --trace flag, it seems to find libusb related files:
/home/unknown/projectes/ha/workspace/ha/src/CMakeLists.txt(8): find_package(libusb-1.0 REQUIRED )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(46): if(LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(49): else(LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(50): find_path(LIBUSB_1_INCLUDE_DIR NAMES libusb.h PATHS /usr/include /usr/local/include /opt/local/include /sw/include PATH_SUFFIXES libusb-1.0 )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(62): find_library(LIBUSB_1_LIBRARY NAMES usb-1.0 usb PATHS /usr/lib /usr/local/lib /opt/local/lib /sw/lib )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(72): set(LIBUSB_1_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIR} )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(75): set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY} )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(79): if(LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(80): set(LIBUSB_1_FOUND TRUE )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(83): if(LIBUSB_1_FOUND )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(84): if(NOT libusb_1_FIND_QUIETLY )
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(85): message(STATUS Found libusb-1.0: )
-- Found libusb-1.0:
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(86): message(STATUS - Includes: ${LIBUSB_1_INCLUDE_DIRS} )
-- - Includes: /home/unknown/rpi/rootfs/usr/include/libusb-1.0
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(87): message(STATUS - Libraries: ${LIBUSB_1_LIBRARIES} )
-- - Libraries: /home/unknown/rpi/rootfs/usr/lib/libusb-1.0.a
/usr/share/cmake-2.8/Modules/Findlibusb-1.0.cmake(96): mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES )
/home/unknown/projectes/ha/workspace/ha/src/CMakeLists.txt(10): INCLUDE_DIRECTORIES(${LIBUSB_1_INCLUDE_DIRS} )
I'm a newcomer to CMake and so far I've not been able to find any helpful entry in this site nor anywhere else regarding this same problem.
Any clue?
Problem
From the cmake --trace output one can see, that Findlibusb-1.0.cmake script, which search libusb-1.0 library, detects include directory for the library's headers via
find_path(LIBUSB_1_INCLUDE_DIR NAMES libusb.h ...)
This means, that the script expects libusb.h header to be included as
#include <libusb.h>
(The same conclusion can be deduced from the output of cmake call: line
- Includes: /home/unknown/rpi/rootfs/usr/include/libusb-1.0
already includes libusb-1.0 suffix for the include path.)
But error message shows, that cm.c file actually includes the header as
#include <libusb-1.0/libusb.h>
This means, that Findlibusb-1.0.cmake script you use (which is shipped with CMake itself) is not compatible with actual usage of the library in you project.
Ideal solution
You need to ship your project with compatible Findlibusb-1.0.cmake script, which uses
find_path(LIBUSB_1_INCLUDE_DIR NAMES libusb-1.0/libusb.h ...)
for detect include path. E.g., the one from PCL library. (At the beginning of your project's CMakeLists.txt you need to adjust CMAKE_MODULE_PATH variable for find the script.)
As fast workaround
You may replace path /home/unknown/rpi/rootfs/usr/include/libusb-1.0 with /home/unknown/rpi/rootfs/usr/include in the CMake cache. (After modification of the cache you need to rerun cmake).
Because cached value is likely used in include_directories() call from your project, proper directory will be used instead.
I'm wondering why find_package works differently when cross compiling.
More likely that find_package works identical on PC and when cross-compiling, but on PC you get path /usr/include being included by other means (e.g., it is included by default).

Unable to build GLFW with CMake errors

I downloaded the latest GLFW source (3.1.1) from its site, uncompressed it to the desktop, and tried to build it with cmake. Some dependency errors popped up, but was quickly fixed. Until I got stuck on this one:
alex#alex-AMD:~/Desktop/glfw-3.1.1$ cmake .
-- The C compiler identification is Clang 3.6.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Found OpenGL: /usr/lib/libGL.so
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.6")
-- Using X11 for window creation
-- Using GLX for context creation
-- Looking for glXGetProcAddress
-- Looking for glXGetProcAddress - found
-- Looking for glXGetProcAddressARB
-- Looking for glXGetProcAddressARB - found
-- Looking for glXGetProcAddressEXT
-- Looking for glXGetProcAddressEXT - not found
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENGL_glu_LIBRARY (ADVANCED)
linked by target "boing" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "gears" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "heightmap" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "particles" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "simple" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "splitview" in directory /home/alex/Desktop/glfw-3.1.1/examples
linked by target "wave" in directory /home/alex/Desktop/glfw-3.1.1/examples
-- Configuring incomplete, errors occurred!
I'm totally lost as to what this means, and how to proceed
I'm on Ubuntu 14.04 64 bit, with proprietary AMD Radeon 7950 drivers
One of the error outputs was Looking for glXGetProcAddressEXT - not found, and the log files indicated that there was a linking error with libGL.
I then tried running apt-get install glfw to print out the list of dependencies. Even though it was an older version in apt-get, it still listed some dependencies that had to be installed.
GLFW compiled after installing libglu1-mesa-dev and libgl1-mesa-dev
The last error message CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENGL_glu_LIBRARY (ADVANCED) was the one that threw me off. I thought it was a problem with paths and environment variables

Using talloc in an embedded project

I would like to be able to use talloc in an embedded project I am working on, but have been unable to determine how I go about incorporating it into my development environment. The environment in question is a vendor-supplied Windows IDE that uses ARM GCC 4.4.1, and I am using it to target an ARM7 device.
I have gotten to the stage where the compiler is complaining about conflicting types:
In file included from .\talloc-2.0.8\talloc.c:33:
.\talloc-2.0.8\lib\replace/replace.h:626: error: conflicting types for 'ptrdiff_t'
c:\program files (x86)\cypress\psoc creator\2.2\psoc creator\import\gnu_cs\arm\4.4.1\bin\../lib/gcc/arm-none-eabi/4.4.1/include/stddef.h:149: note: previous declaration of 'ptrdiff_t' was here
.\talloc-2.0.8\lib\replace/replace.h:848: error: conflicting types for 'useconds_t'
c:\program files (x86)\cypress\psoc creator\2.2\psoc creator\import\gnu_cs\arm\4.4.1\bin\../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/include/sys/types.h:253: note: previous declaration of 'useconds_t' was here
.\talloc-2.0.8\talloc.c:123: error: expected specifier-qualifier-list before 'uint8_t'
I noticed that replace.h tries to include a file called config.h that does not exist in the talloc source tree - a problem I got around by creating a blank file by that name. Is the idea to use config.h to inform talloc what functions are already defined by the system? Is this just a matter of using the #define directive to prevent replace.h from trying to replace existing types?
Given that this is the first time I have attempted to use code that I did not write myself in a project, I am somewhat confused as to how to go about reconciling these conflicts.
config.h should be generated automatically. For tmalloc, it's done by waf (python-based build system).
$ python ./buildtools/bin/waf configure
Checking for program gcc or cc : /usr/lib/ccache/gcc
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for gcc : ok
Checking for program git : /usr/bin/git
Check for -MD : yes
....
$ python ./buildtools/bin/waf build
.....

How do you export a system library using cmake?

How can I export the libraries that a cmake library depends on, such that an executable depending on that library does not have to manually depend on the dependencies of that library?
That's a bit of a mouthful, so here's an example:
dummy (application) ----> depends on liba
liba ----> depends on libpng
Compiling dummy generates errors:
-- Found LIBPNG
-- Found LIBA
-- Configuring done
-- Generating done
-- Build files have been written to: /home/doug/projects/dummy/build
Linking C executable dummy
../deps/liba/build/liba.a(a.c.o): In function `a_dummy':
/home/doug/projects/dummy/deps/liba/src/a.c:6: undefined reference to `png_sig_cmp'
collect2: ld returned 1 exit status
make[2]: *** [dummy] Error 1
make[1]: *** [CMakeFiles/dummy.dir/all] Error 2
make: *** [all] Error 2
I can fix that by adding this into CMakeLists.txt for dummy:
TARGET_LINK_LIBRARIES(dummy png)
However, dummy has no knowledge of how liba implements its api. At some point that may change to being libjpg, or something else, which will break the dummy application.
After getting some help from the cmake mailing list I've been directed to this example for exporting things:
http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
However, following that approach leaves me stuck at this line:
export(TARGETS ${LIBPNG_LIBRARY} FILE "${PROJECT_BINARY_DIR}/ALibraryDepends.cmake")
Clearly I'm missing something here; this 'export' command looks like its designed to export sub-projects to a high level; ie. nested projects inside liba.
However, that is not the problem here.
When configuring liba (or any cmake library) I will always generate a list of dependencies which are not part of that project.
How can I export those so they appear as part of LIBA_LIBRARY when I use find_package() to resolve liba?
Using static libraries is not an option (static library for something that links to opengl? no.)
Given your comment to arrowdodger's answer about the fear of
installing something would mess up your system I chose to give
a conceptional comment in form of an answer because of its
length.
Chaining cmake project works via find_package, which looks for
*Config.cmake and *-config.cmake files.
Project A's CMakeLists.txt:
#CMakeLists.txt
project(A)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/AConfig.cmake share/A/cmake
)
#AConfig.cmake
message("Yepp, you've found me.")
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/test-install ..
$ make install
Project B's CMakeLists.txt:
project(B)
find_package(A)
Then
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/test-install ..
$ make install
results in
...
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Yepp, you've found me.
B found A because it installed AConfig.cmake into a location
where cmake will find it 'share/A/cmake' AND was given the same
value for CMAKE_INSTALL_PREFIX.
Now this is that. Lets think about what you can do in
AConfig.cmake: AFAIK everything you want to. But the most common
task is to pull information about the targets of A via include(),
do some additional find_package invoctions for 3rd party
packages (HINT HINT) and create the variables
A_LIBRARIES
A_INCLUDE_DIRS
What you want to include is a file that was created by
install(EXPORT A-targets
DESTINATION share/A/cmake
)
in A's CMakeLists.txt , where A-targets refers to a global cmake
variable that accumulated all target informations when used in
install(TARGETS ...
EXPORT A-targets
...
)
statments. What is created at make install is
/tmp/test-install/share/A/cmake/A-targets.cmake
which then resides alongside AConfig.cmake in the same directory.
Please take another look at the wiki page on how to use this file
within AConfig.cmake.
Regarding the export() command: This comes handy if your
projects have gotten HUGE and it takes a considerable amount of
time to install them. To speed things up, you want to use what's
in A's build/ directory directly. It's an optimization and also
explained in the wiki. It still works via find_package(), see
http://cmake.org/cmake/help/cmake-2-8-docs.html#command:export
But I strongly suggest that you go for the usual make install
route for now.
I found my own solution to this problem using the accepted solution above, which I leave here for others:
In liba/CMakeLists.txt:
# Self
set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/include")
set(A_LIBRARIES ${A_LIBRARIES} "${PROJECT_BINARY_DIR}/liba.a")
# Libpng
FIND_PACKAGE(libpng REQUIRED)
set(A_INCLUDE_DIRS ${A_INCLUDE_DIRS} ${LIBPNG_INCLUDE_DIRS})
set(A_LIBRARIES ${A_LIBRARIES} ${LIBPNG_LIBRARIES})
ADD_LIBRARY(a ${SOURCES})
# Includes
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})
# Allow other projects to use this
configure_file(AConfig.cmake.in "${PROJECT_BINARY_DIR}/AConfig.cmake")
In liba/AConfig.cmake:
set(A_LIBRARIES #A_LIBRARIES#)
set(A_INCLUDE_DIRS #A_INCLUDE_DIRS#)
In dummy/CMakeLists.txt:
FIND_PACKAGE(A REQUIRED)
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(dummy ${A_LIBRARIES})
This yields an AConfig.cmake that reads:
set(A_LIBRARIES /home/doug/projects/dummy/deps/liba/build/liba.a;/usr/lib/libpng.so)
set(A_INCLUDE_DIRS /home/doug/projects/dummy/deps/liba/include;/usr/include)
And a verbose compile that reads:
/usr/bin/gcc -std=c99 -g CMakeFiles/dummy.dir/src/main.c.o -o dummy -rdynamic ../deps/liba/build/liba.a -lpng
Which is exactly what I was looking for.
If liba doesn't provide any means to determine it's dependencies, you can't do anything.
If liba is library developed by you and you are using CMake to build it, then you should install libaConfig.cmake file with liba itself, which would contain necessary definitions. Then you include libaConfig in dummy's CMakeLists.txt to obtain information about how liba have been built.
You can look how it's done in LLVM project, relevant files have cmake.in extension
http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/
In the end, in dummy project you should use
target_link_libraries( ${LIBA_LIBRARIES} )
include_directories( ${LIBA_INCLUDE_DIR} )
link_directories( ${LIBA_LIBRARY_DIR} )
If that liba is used only by dummy, you can build it from single CMake project. This is more convenient, since you don't need to install liba each time you recompile it and it will be rebuilt and relinked with dummy automatically every time you run make.
If you liked this approach, the only thing you should do - define in liba' CMakeLists.txt variables you need with PARENT_SCOPE option (see set() command manual).
Finally, you can use shared libs, .so's don't have such problem.

Resources