Im trying to build a project which uses the Myo SDK and the LeapMotion SDK on Windows 7 with CMake, Qt Creator and MinGW 4.9.2 32bit as compiler.
The MyoSDK ist working fine but I have some problems with linking the LeapMotion SDK in CMake. I found an existing sample CMake file which says that the Windows part is not finished.
Here is my CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (MyoLeapController)
#set(THALMICLABSMYO_ROOT_DIR "C:/myo-sdk-win-0.9.0")
################## MYO
if(WIN32)
set(THALMICLABSMYO_ROOT_DIR
"${THALMICLABSMYO_ROOT_DIR}"
CACHE
PATH
"Directory to search for the Thalmic Labs Myo SDK")
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
set(_ARCH x86_64)
else()
set(_ARCH x86_32)
endif()
set(_SDKDIR Windows)
find_path(THALMICLABSMYO_INCLUDE_DIR
NAMES myo/libmyo.h
PATHS "${THALMICLABSMYO_ROOT_DIR}/include")
include(FindPackageHandleStandardArgs)
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
find_library(THALMICLABSMYO_LIBRARY
NAMES myo64
PATHS "${THALMICLABSMYO_ROOT_DIR}/lib"
PATH_SUFFIXES "${_SDKDIR}/${_ARCH}")
else()
find_library(THALMICLABSMYO_LIBRARY
NAMES myo32
PATHS "${THALMICLABSMYO_ROOT_DIR}/lib"
PATH_SUFFIXES "${_SDKDIR}/${_ARCH}")
endif()
find_package_handle_standard_args(ThalmicLabsMyo
DEFAULT_MSG
THALMICLABSMYO_LIBRARY
THALMICLABSMYO_INCLUDE_DIR
${_deps_check})
if(THALMICLABSMYO_FOUND)
set(THALMICLABSMYO_LIBRARIES "${THALMICLABSMYO_LIBRARY}")
set(THALMICLABSMYO_INCLUDE_DIRS "${THALMICLABSMYO_INCLUDE_DIR}")
mark_as_advanced(THALMICLABSMYO_ROOT_DIR)
endif()
mark_as_advanced(THALMICLABSMYO_INCLUDE_DIR THALMICLABSMYO_LIBRARY)
endif()
################## LEAP
IF(LEAP_INCLUDE_DIR AND LEAP_LIBRARY)
SET(LEAP_FIND_QUIETLY TRUE)
ENDIF(LEAP_INCLUDE_DIR AND LEAP_LIBRARY)
# Set locations to search
IF(UNIX)
SET(LEAP_INCLUDE_SEARCH_DIRS
/usr/include
/usr/local/include
/opt/leap/include
/opt/leap_sdk/include
/opt/include INTERNAL)
SET(LEAP_LIBRARY_SEARCH_DIRS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/leap/lib
/opt/leap/lib64
/opt/leap_sdk/lib
/opt/leap_sdk/lib64 INTERNAL)
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES leap)
ELSE(UNIX)
#WIN32
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES inc)
SET(LEAP_LIB_DIR_SUFFIXES PATH_SUFFIXES lib)
ENDIF(UNIX)
# Set name of the Leap library to use
IF(APPLE)
SET(LEAP_LIBRARY_NAME libLeap.dylib)
ELSE(APPLE)
IF(UNIX)
SET(LEAP_LIBRARY_NAME libLeap.so)
ELSE(UNIX)
# TODO Different libraries are provided for compile and runtime
SET(LEAP_LIBRARY_NAME libLeap.lib)
ENDIF(UNIX)
ENDIF(APPLE)
IF(NOT LEAP_FIND_QUIETLY)
MESSAGE(STATUS "Checking for Leap")
ENDIF(NOT LEAP_FIND_QUIETLY)
# Search for header files
FIND_PATH(LEAP_INCLUDE_DIR Leap.h
PATHS ${LEAP_INCLUDE_SEARCH_PATHS}
PATH_SUFFIXES ${LEAP_INC_DIR_SUFFIXES})
# Search for library
FIND_LIBRARY(LEAP_LIBRARY ${LEAP_LIBRARY_NAME}
PATHS ${LEAP_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${LEAP_LIB_DIR_SUFFIXES})
SET(LEAP_INCLUDE_DIR ${LEAP_INCLUDE_DIR} CACHE STRING
"Directory containing LEAP header files")
SET(LEAP_LIBRARY ${LEAP_LIBRARY} CACHE STRING "Library name of Leap library")
SET(LEAP_INCLUDE_DIRS ${LEAP_INCLUDE_DIR} )
SET(LEAP_LIBRARIES ${LEAP_LIBRARY} )
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Leap DEFAULT_MSG LEAP_LIBRARY LEAP_INCLUDE_DIR)
MARK_AS_ADVANCED(LEAP_INCLUDE_DIR LEAP_LIBRARY)
##################
message(${LEAP_LIBRARY})
INCLUDE_DIRECTORIES(${THALMICLABSMYO_INCLUDE_DIR} ${LEAP_INCLUDE_DIRS})
add_executable(MyoLeapController main.cpp)
target_link_libraries(MyoLeapController ${THALMICLABSMYO_LIBRARY} ${LEAP_LIBRARY})
My CMake output is:
C:/LeapSDK/lib/x86/Leap.dll
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/riecker/Documents/Masterthesis/MyoLeapController-bin
I link the found Leap library exactly the same like the Myo but I get some Linker errors.
My C++ program for testing:
#include <iostream>
#include <myo/myo.hpp>
#include <Leap.h>
int main (int argc, char *argv[])
{
//myo::Hub hub("MyoLeapController");
Leap::Controller controller;
std::cout << "hi" << std::endl;
return 0;
}
The Error Message:
[ 50%] Linking CXX executable MyoLeapController.exe
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1d): undefined reference to `Leap::Controller::Controller()'
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x51): undefined reference to `Leap::Controller::~Controller()'
CMakeFiles\MyoLeapController.dir\build.make:98: recipe for target 'MyoLeapController.exe' failed
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x61): undefined reference to `Leap::Controller::~Controller()'
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/MyoLeapController.dir/all' failed
makefile:82: recipe for target 'all' failed
C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj): bad reloc address 0x0 in section `.ctors'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [MyoLeapController.exe] Error 1
mingw32-make[1]: *** [CMakeFiles/MyoLeapController.dir/all] Error 2
mingw32-make: *** [all] Error 2
10:56:32: Der Prozess "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" wurde mit dem Rückgabewert 2 beendet.
Fehler beim Erstellen/Deployment des Projekts MyoLeapController (Kit: Desktop Qt 5.6.0 MinGW 32bit)
Bei der Ausführung von Schritt "Make"
The include of the Leap SDK is working because it can find the header files only during linking I get the problem. For including and linking I am doing the same like with the Myo SDK which is working.
Can anybody help me or have an idea about this? Thank you
Leap Motion library does not support MinGW, so the library that you are trying to link is incompatible.
However, you can try the dll in this package. It comes from this thread. It seems to be only for 32-bit, but that's apparently what you are trying to build.
From the build directory where you got the error, first see if this command line works, then you can proceed to make it work within your cmake project:
C:\Qt\Tools\mingw492_32\bin\g++.exe -Wl,--whole-archive
CMakeFiles\MyoLeapController.dir/objects.a -Wl,--no-whole-archive -o
MyoLeapController.exe -Wl,--out-implib,libMyoLeapController.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 -LC:/myo-sdk-win-0.9.0/lib/ -LpathToTheLeapDll -lLeap -lmyo32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
If it works, when you try the executable make sure the libLeap.dll is available in your path or in your execution directory.
Related
I struggle to get GLFW Windows pre-compiled binaries working within my CLion Project. Those libraries are placed in a external directory. I do not want them to be in my project library but should (of course) be shipped when releasing the application. I am new to C++ but I thought to accomplish this might be as easy as it is in Java (Intellij Idea -> dependencies -> ...).
GLFW Windows pre-compiled binaries
I use MinGW 5.0 and CMake 3.10.2;
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(Hatsudouki_core)
set(CMAKE_CXX_STANDARD 17)
link_directories(F:\\C++\\ExternalLibraries\\GLFW\\lib-mingw-w64)
include_directories(F:\\C++\\ExternalLibraries\\GLFW\\include)
add_executable(Hatsudouki_core main.cpp)
target_link_libraries(Hatsudouki_core glfw3)
Main.cpp
#include <iostream>
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit())
std::cout << "error!" << std::endl;
else
std::cout << "success!" << std::endl;
return 0;
}
Build output
"F:\C++\CLion 2018.1\bin\cmake\bin\cmake.exe" --build C:\Users\simon\CLionProjects\Hatsudouki-core\cmake-build-debug --target Hatsudouki_core -- -j 4
[ 50%] Linking CXX executable Hatsudouki_core.exe
CMakeFiles\Hatsudouki_core.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/simon/CLionProjects/Hatsudouki-core/main.cpp:5: undefined reference to `glfwInit'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Hatsudouki_core.exe] Error 1
CMakeFiles\Hatsudouki_core.dir\build.make:96: recipe for target 'Hatsudouki_core.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Hatsudouki_core.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Hatsudouki_core.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Hatsudouki_core.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Hatsudouki_core.dir/rule] Error 2
Makefile:117: recipe for target 'Hatsudouki_core' failed
mingw32-make.exe: *** [Hatsudouki_core] Error 2
I tried following solutions mentioned here:
- GLFW doc and GLFW doc2 (find package does not work, no CMake file)
- Github issue report related to Github issue report 2 which then leads to the solution to put FindGLFW.cmake into some directory? Tried to put it here GLFW\FindGLFW.cmake but does not work- Linking did not work as well as mentioned here: Stackoverflow
Image GLFW directory: GLFW Windows pre-compiled binaries
I think I just do not understand how CMake, external Libraries and C++ work together to accomplish this fairly easy task. I believe comparison to Java would help (used to work with gradle)
EDIT 1
As suggested I added following:
I put the Findglfw3.cmake into PROJECT/cmake/Modules/:
# Copyright (c) 2015 Andrew Kelley
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
find_path(GLFW_INCLUDE_DIR NAMES F:\\C++\\ExternalLibraries\\GLFW\\include\\GLFW\\glfw3.h)
find_library(GLFW_LIBRARY NAMES glfw glfw3)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW DEFAULT_MSG GLFW_LIBRARY GLFW_INCLUDE_DIR)
mark_as_advanced(GLFW_INCLUDE_DIR GLFW_LIBRARY)
And added following lines into my CMakeLists.txt:
find_package(glfw3 REQUIRED)
include_directories(${glfw3_INCLUDE_DIRS})
set(LIBS ${LIBS} ${glfw3_LIBRARIES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
target_link_libraries(hatsudouki_core ${LIBS})
I also tried in the Findglfw3.cmake:
find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3.h)
which is the same in the original file. Both do not work; error:
"F:\C++\CLion 2018.1\bin\cmake\bin\cmake.exe" --build C:\Users\simon\CLionProjects\Hatsudouki-core\cmake-build-debug --target Hatsudouki_core -- -j 4
CMake Error at CMakeLists.txt:6 (find_package):
-- Configuring incomplete, errors occurred!
By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
See also "C:/Users/simon/CLionProjects/Hatsudouki-core/cmake-build-debug/CMakeFiles/CMakeOutput.log".
asked CMake to find a package configuration file provided by "glfw3", but
CMake did not find one.
Makefile:175: recipe for target 'cmake_check_build_system' failed
Could not find a package configuration file provided by "glfw3" with any of
the following names:
glfw3Config.cmake
glfw3-config.cmake
Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
"glfw3_DIR" to a directory containing one of the above files. If "glfw3"
provides a separate development package or SDK, be sure it has been
installed.
mingw32-make.exe: *** [cmake_check_build_system] Error 1
As explained here
Make Findglfw3.cmake file in PROJECT/cmake/Modules/ which looks like
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
set(FIND_GLFW_PATHS "F:\\C++\\ExternalLibraries\\GLFW")
find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3 GLFW/glfw3.h PATH_SUFFIXES include PATHS ${FIND_GLFW_PATHS})
find_library(GLFW_LIBRARY NAMES glfw3 glfw3.a libglfw3 libglfw3.a PATH_SUFFIXES lib-mingw PATHS ${FIND_GLFW_PATHS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW DEFAULT_MSG GLFW_LIBRARY GLFW_INCLUDE_DIR)
mark_as_advanced(GLFW_INCLUDE_DIR GLFW_LIBRARY)
Define Module Path in CMakeLists.txt
#Define module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
Also Link include directory and library with project in CMakeLists.txt
#Define static GLFW libraries and header files
find_package(glfw3 REQUIRED)
include_directories(${GLFW_INCLUDE_DIR})
...
target_link_libraries(Hatsudouki_core ${GLFW_LIBRARY})
At first you need to install glfw package. If you are using MSYS2 then it can be installed using pacman -S mingw-w64-x86_64-glfw on 64-bit windows and pacman -S mingw-w64-i686-glfw on 32-bit windows. And you need to use find_package to let the cmake locate the glfw library automatically instead of manually locating them. If you are not using MSYS2 then it might be little difficult. Check out this code.
cmake_minimum_required(VERSION 3.10)
project(Hatsudouki_core)
set(CMAKE_CXX_STANDARD 17)
add_executable(Hatsudouki_core main.cpp)
find_package(glfw3 REQUIRED) # Find the GLFW library
target_link_libraries(Hatsudouki_core PRIVATE glfw) # Finally, link to them.
I suggest you to use MSYS2 If you need pre-compiled libraries. It has a very good package manager called as pacman.
this is the first time I use an external c++ library aside from OpenCV. In the code I use quite a lot of ROS functionality, but I believe my issue is not related to ROS. I want to build a project with the GTSAM library.
Therefore I cloned the repository into my /usr/lib folder and installed it as instructed.
I then wrote the CMakeLists.txt,added two includes into my - otherwise functioning .h file - and tried to compile.
The beginning of my .h file, the compile error and my CMakeLists.txt are shown below. Interestingly, if I comment out the second include and just include Pose2.h, compilation works. That should mean that the compiler at least finds some headers from the library, ergo it is correctly installed. The part of my cmake code which is supposed to link the library is extracted from an example project given here. Any help is appreciated.
car_lib.h:
#ifndef CAR_LIB_H
#define CAR_LIB_H
// GTSAM headers
#include <gtsam/geometry/Pose2.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
using namespace gtsam;
// rest of file follows....
When compiling, I get the following error:
...
[100%] Linking CXX executable /home/marc/catkin_ws/devel/lib/car/car_node
[100%] Linking CXX shared library /home/marc/catkin_ws/devel/lib/libcar_lib.so
[100%] Built target car_lib
CMakeFiles/car_node.dir/src/car_node.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
/usr/local/include/gtsam/inference/Key.h:41: undefined reference to `gtsam::_defaultKeyFormatter[abi:cxx11](unsigned long)'
/usr/local/include/gtsam/inference/Key.h:52: undefined reference to `gtsam::_multirobotKeyFormatter[abi:cxx11](unsigned long)'
collect2: error: ld returned 1 exit status
car/CMakeFiles/car_node.dir/build.make:113: recipe for target '/home/marc/catkin_ws/devel/lib/car/car_node' failed
make[2]: *** [/home/marc/catkin_ws/devel/lib/car/car_node] Error 1
CMakeFiles/Makefile2:384: recipe for target 'car/CMakeFiles/car_node.dir/all' failed
make[1]: *** [car/CMakeFiles/car_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
My CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(car)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
message_generation
nav_msgs
roscpp
sensor_msgs
std_msgs
)
###### GTSAM STUFF STARTS HERE
# Include GTSAM CMake tools
find_package(GTSAMCMakeTools)
#include(GtsamBuildTypes) # Load build type flags and default to Debug mode
#include(GtsamTesting) # Easy functions for creating unit tests and scripts
#include(GtsamMatlabWrap) # Automatic MATLAB wrapper generation
# Ensure that local folder is searched before library folders
#include_directories(BEFORE "${PROJECT_SOURCE_DIR}")
###################################################################################
# Find GTSAM components
find_package(GTSAM REQUIRED) # Uses installed package
include_directories(${GTSAM_INCLUDE_DIR})
###################################################################################
# Build static library from common sources
#set(CONVENIENCE_LIB_NAME ${PROJECT_NAME})
#add_library(${CONVENIENCE_LIB_NAME} STATIC include/car/car_lib.h src/car_lib.cpp)
#target_link_libraries(${CONVENIENCE_LIB_NAME} gtsam)
###### GTSAM STUFF ENDS HER
catkin_package(
INCLUDE_DIRS include
LIBRARIES car_lib
CATKIN_DEPENDS
geometry_msgs
message_runtime
nav_msgs
roscpp
sensor_msgs
std_msgs
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
add_library(car_lib
include/${PROJECT_NAME}/car_lib.h
src/car_lib.cpp
)
add_executable(car_node src/car_node)
target_link_libraries(car_node ${catkin_LIBRARIES})
target_link_libraries(car_lib
${catkin_LIBRARIES}
)
Try replacing the bit under ## Declare a C++ library with
## Declare a C++ library
add_library(car_lib src/car_lib.cpp)
target_link_libraries(car_lib
gtsam
${catkin_LIBRARIES}
)
add_executable(car_node src/car_node)
target_link_libraries(car_node
car_lib
gtsam
${catkin_LIBRARIES}
)
For those who are trying to do the same thing using makefile, Here is the solution. [ note this is for simple c++ program without ROS ].
all: main.cpp
#g++ main.cpp \
-std=c++11 \
-I /usr/include/eigen3 \
-lboost_system -lboost_filesystem \
-lgtsam \
-o main
clear:
#rm -rf main
I'm trying to cross compile my project to arm to use it on a raspberry pi but it can't find dbus. Which was easily find when I was compiling classically.
I'm using cmake I've added dbus-1 to target link library and I'm using arm-linux-gnueabihf to cross compile.
Any idea?
EDIT: add my CMakeLists.txt :
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
FIND_PACKAGE(glib2) # bluetooth
include_directories(${GLIB2_INCLUDE_DIRS}) # bluetooth
include_directories(${CMAKE_SOURCE_DIR}/../bluez/gdbus)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/attrib)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/src)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/src/shared)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/btio)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/lib)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/client)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/emulator)
include_directories(${CMAKE_SOURCE_DIR}/../bluez/monitor)
include_directories(${CMAKE_SOURCE_DIR}/../bluez)
include_directories(/usr/include/dbus)
set( CMAKE_CXX_FLAGS "-fpermissive" )
# Search every source files
aux_source_directory(. SRC_LIST)
include_directories (/usr)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/gdbus SRC_BLUEZ_GDBUS)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/client SRC_BLUEZ_CLIENT)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/btio SRC_BLUEZ_BTIO_LIST)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/attrib SRC_BLUEZ_ATTRIB_LIST)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/emulator SRC_BLUEZ_EMULATOR)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/lib SRC_BLUEZ_LIB)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/monitor SRC_BLUEZ_MONITOR)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/src SRC_BLUEZ_SRC)
aux_source_directory(${CMAKE_SOURCE_DIR}/../bluez/src/shared SRC_BLUEZ_SRC_SHARED)
add_executable(${PROJECT_NAME} ${SRC_LIST})
# Library used in test
add_library(${PROJECT_NAME}-lib
Thread.cpp
NetworkThread.cpp
UdpSocket.cpp)
add_library(MyBluezLib-lib
${SRC_BLUEZ_SRC} ${SRC_BLUEZ_LIB}
${SRC_BLUEZ_GDBUS} ${SRC_BLUEZ_CLIENT} ${SRC_BLUEZ_BTIO_LIST} ${SRC_BLUEZ_ATTRIB_LIST} ${SRC_BLUEZ_EMULATOR}
${SRC_BLUEZ_SRC_SHARED} ${SRC_BLUEZ_MONITOR})
# Link libraries
TARGET_LINK_LIBRARIES (${PROJECT_NAME}
pthread
glog
bluetooth
${GLIB2_LIBRARIES} #bluetooth
readline
expat
dbus-1
dl
MyBluezLib-lib
)
And this is my make call and his answear :
Scanning dependencies of target MyBluezLib-lib
[ 1%] Building C object src/CMakeFiles/MyBluezLib-lib.dir/home/grosalex/job/stageING3/bluez/src/rfkill.c.obj
In file included from /home/grosalex/job/stageING3/bluez/src/rfkill.c:39:0:
/home/grosalex/job/stageING3/bluez/src/adapter.h:29:23: erreur fatale: dbus/dbus.h: Aucun fichier ou dossier de ce type
#include <dbus/dbus.h>
^
compilation terminée.
As far as I can see, you have wrong include directory for dbus. You have include_directories(/usr/include/dbus) and in my host Linux I have following include flags, if I issue pkg-config --cflags dbus-glib-1:
-pthread -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
Try to configure this include:
include_directories(/usr/include/dbus-1.0)
I have a cmake project where I want to add a class containing the matlab engine. For compiling it I need to include two libraries eng and mx, which I do by adding
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)
to my CMakeLists.txt file.
However there are also lots of other old versions of libraries in /usr/local/MATLAB/R2013b/bin/glnxa64/, which seem
to be automatically added to the path as well when calling the above command. I think this causes the compiler to not find my
normal libraries anymore and produces an error.
How can I include only the two above libraries, and not all the others in the glnxa64 folder?
The warning shown after running cmake . :
CMake Warning at CMakeLists.txt:23 (add_executable):
Cannot generate a safe runtime search path for target CCDWidget because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libboost_program_options.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_system.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_filesystem.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_regex.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
Some of these libraries may not be found correctly.
And the error message during linking:
Linking CXX executable CCDWidget
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Face_GetCharVariantIndex'
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Get_Advance'
collect2: error: ld returned 1 exit status
make[2]: *** [CCDWidget] Error 1
make[1]: *** [CMakeFiles/CCDWidget.dir/all] Error 2
make: *** [all] Error 2
Below is my full CMakeLists.txt file. Lines commented out with two ## are alternatives that I tried before and didn't solve my problem.
I also added LINK_PRIVATE to the target_link_libraries command as shown in the code below, which didn't make a difference.
The option PRIVATE alone seems to be not accepted by my cmake version, as it changed the error meassage to
/usr/bin/ld: cannot find -lPRIVATE
collect2: error: ld returned 1 exit status
When the #eng line is commented out, the compilation and linking works without errors
(when calling the matlab engine is also commented out in Readout.cpp), so the error must be produced by that line.
#Specify the version being used as well as the language
cmake_minimum_required(VERSION 2.6)
##cmake_policy(SET CMP0003 NEW)
#Name your project here
project(CCDWidget)
set(TARGET CCDWidget)
set(MAIN_SOURCES CCDWidget.cpp main.cc CCDControl.cpp VideoWindow.cpp ImageWindow.cpp ThisMeasurement.cpp KineticSeries.cpp FastKinetics.cpp Readout.cpp)
##SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set_source_files_properties(Readout.cpp PROPERTIES COMPILE_FLAGS "-I/usr/local/MATLAB/R2013b/extern/include -I/usr/local/MATLAB/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -I/usr/local/MATLAB/R2013b/extern/include/cpp -I/usr/local/MATLAB/R2013b/extern/include -DGLNXA64 -DGCC -DMX_COMPAT_32 -DNDEBUG -Wno-effc++")
find_package(Boost COMPONENTS program_options system filesystem regex REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories( ${GTKMM_INCLUDE_DIRS} )
include_directories( ${Boost_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR} )
##link_directories(/usr/local/MATLAB/R2013b/bin/glnxa64)
##target_link_libraries( ${TARGET} eng)
##target_link_libraries( ${TARGET} mx)
set(CMAKE_CXX_FLAGS "--std=c++11")
add_executable( ${TARGET} ${MAIN_SOURCES} )
target_link_libraries( ${TARGET} ${GTKMM_LIBRARIES} )
target_link_libraries( ${TARGET} ${Boost_LIBRARIES} )
target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so) # eng
#target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so ) # mx
target_link_libraries( ${TARGET} andor )
You could try using an imported target:
add_library(eng SHARED IMPORTED)
set_property(TARGET eng PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
...
add_executable( ${TARGET} ${MAIN_SOURCES} )
...
target_link_libraries(${TARGET} eng)
For debugging you could try to build with "make VERBOSE=1".
This will show you the used gcc command line.
CMake probably transforms your target_link_libraries command to something like:
g++ ... -L/usr/local/MATLAB/R2013b/bin/glnxa64 -leng ...
gcc then finds some boost libraries in this folder.
I'm using cmake verison 2.8.11.2 to build a project using some external libraries and packages. However since I tried adding the library spglib I have been unable to compile the code. Despite CMake adding the correct .so file the resulting makefile does not correctly link to it.
I use the following CMake code in src/main/CMakeLists.txt to include the spglib .so file:
ADD_EXECUTABLE(PotFit ${SourceFiles})
SET_TARGET_PROPERTIES(PotFit PROPERTIES COMPILE_DEFINITIONS "${POTFIT_COMPILE_DEFINITIONS}")
TARGET_LINK_LIBRARIES(PotFit PotFitLibrary boost_timer boost_system)
set(CMAKE_PREFIX_PATH [path to]/src/.libs)
find_library(SPGLIBRARY NAMES spg spglib libsymspg symspg PATHS /home/staffana /CS/trunk/spglib-1.6.0/src/.libs [path to]/spglib-1.6.0/src)
target_link_libraries(PotFit "${SPGLIBRARY}")
Which seems to work. I check that CMake actually finds the library using
message("The value of SPGLibrary is")
message("${SPGLIBRARY}")
which correctly returns the path to libsymspg.so. However the compiler returns the error
CMakeFiles/PotFit.dir/Main.cpp.o: In function `main':
Main.cpp:(.text.startup+0x11a): undefined reference to `spg_get_spacegroup_type(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [main/PotFit] Error 1
make[1]: *** [main/CMakeFiles/PotFit.dir/all] Error 2
make: *** [all] Error 2
*** Failure: Exit code 2 ***
I make sure that the libsymspg.so does contain this symbol by using
nm libsymspg.so | grep get_spacegroup_type
which returns
0000ad30 T spgdb_get_spacegroup_type
0000c240 T spg_get_spacegroup_type
So between Cmake and linking something is wrong. As far as I know I am using the "normal" way of doing things, so I am not sure where to begin looking for what is causing this problem. I have appended all whole CMakeLists.txt below since that might be useful and I can add the CMakeCache if needed (it's p. long...).
Full Cmake source
src/CMake.txt :
PROJECT(FitPot CXX C Fortran)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
OPTION(USE_OPENMP "Use OpenMP parallelization" "ON")
OPTION(ENABLE_DEBUG_CHECKS "Enable sanity checks in the code." "ON")
# Find and set up Qt4 library.
SET(QT_USE_QTOPENGL FALSE)
SET(QT_USE_QTGUI FALSE)
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTXMLPATTERNS FALSE)
SET(QT_MIN_VERSION "4.6.0")
# Use the Q_SIGNALS and Q_SLOTS macros to avoid name conflicts with Python.
ADD_DEFINITIONS(-DQT_NO_KEYWORDS)
FIND_PACKAGE(Qt4)
IF(NOT QT4_FOUND)
IF(QT4_INSTALLED_VERSION_TOO_OLD)
MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required.")
ELSE(QT4_INSTALLED_VERSION_TOO_OLD)
MESSAGE(FATAL_ERROR "The Qt library or the qmake program was not found! Please install Qt manually and specify the path to the 'qmake' program by setting the QT_QMAKE_EXECUTABLE setting in CMake. You need at least version ${QT_MIN_VERSION}.")
ENDIF(QT4_INSTALLED_VERSION_TOO_OLD)
ENDIF(NOT QT4_FOUND)
INCLUDE(${QT_USE_FILE})
# Find Boost library.
#SET(BOOST_ROOT "/usr/local/boost_1_50_0/") # Might want to use this line, a modified version. !!MODIFYME
FIND_PACKAGE(Boost REQUIRED)
IF(NOT Boost_FOUND)
MESSAGE(FATAL_ERROR "Boost library not found. Reason: ${Boost_ERROR_REASON}")
ENDIF()
# Modify this line to point to the directory where the boost libraries are. !!MODIFYME
SET(Boost_LIBRARY_DIRS "/usr/local/boost_1_50_0/stage/lib")
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
MESSAGE("boost lib dirs: ${Boost_LIBRARY_DIRS}")
MESSAGE("boost include dirs: ${Boost_INCLUDE_DIRS}")
# Choose compiler flags for Fortran compiler.
GET_FILENAME_COMPONENT(Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
IF(Fortran_COMPILER_NAME MATCHES "gfortran")
# gfortran:
SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -funroll-all-loops -fno-f2c -O3")
SET(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fno-f2c -O0 -g")
ELSEIF(Fortran_COMPILER_NAME STREQUAL "ifort")
# ifort:
# The '-fltconsistency' flag forces the compiler to "maintain floating point precision";
# replaces -mp option in older ifort versions.
# This is necessary to avoid hangups in the 'dpmeps' function in lbfgs.f on some systems.
SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -fltconsistency -f77rtl -O3")
SET(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fltconsistency -f77rtl -O0 -g")
ELSEIF(Fortran_COMPILER_NAME STREQUAL "g77")
# g77:
SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -funroll-all-loops -fno-f2c -O3 -m32")
SET(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fno-f2c -O0 -g -m32")
ELSE()
MESSAGE("Unknown Fortran compiler (${Fortran_COMPILER_NAME}), using default flags")
SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O2")
SET(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -g")
ENDIF()
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_RELEASE}")
MESSAGE("Fortran flags: ${CMAKE_Fortran_FLAGS}")
# Code files will reference header files relative to the root source directory.
INCLUDE_DIRECTORIES(".")
IF(ENABLE_DEBUG_CHECKS)
SET(POTFIT_COMPILE_DEFINITIONS "DEBUG_FITPOT")
ENDIF()
# Creates a sub CMakeList.txt in those two subdirectories where source files are defined.
ADD_SUBDIRECTORY(potfitlib)
ADD_SUBDIRECTORY(main)
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
MESSAGE("cxx flags: ${CMAKE_CXX_FLAGS}")
MESSAGE("cxx linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
MESSAGE("Library path is : ${CMAKE_LIBRARY_PATH}")
src/potfitlib/CMakeLists.txt
# List of source files that need to be compiled:
SET(SourceFiles
util/linalg/LinAlg.cpp
util/Debug.cpp
util/Dijkstra.cpp
job/FitJob.cpp
job/Fitting.cpp
job/Validation.cpp
potentials/Potential.cpp
potentials/TabulatedEAMPotential.cpp
potentials/SplineMEAMPotential.cpp
potentials/LennardJonesPotential.cpp
potentials/CDIPotential.cpp
potentials/HarmonicModelFullPhi.cpp
potentials/HarmonicModel.cpp
potentials/PairPotential.cpp
potentials/FourthOrderModel.cpp
potentials/functions/CubicSpline.cpp
potentials/functions/GridCubicSpline.cpp
potentials/functions/Functions.cpp
potentials/fourthOrderHelpers/Bond.cpp
potentials/fourthOrderHelpers/TupleFinder.cpp
potentials/fourthOrderHelpers/SymmetryOperator.cpp
potentials/fourthOrderHelpers/GeneralizedDirection.cpp
potentials/fourthOrderHelpers/ForceTuple.cpp
potentials/fourthOrderHelpers/OldEnergyAndForces.cpp
potentials/fourthOrderHelpers/ForceComputation.cpp
properties/FitProperty.cpp
properties/AtomVectorProperty.cpp
dof/DegreeOfFreedom.cpp
dof/AtomCoordinatesDOF.cpp
structures/FitObject.cpp
structures/StructureGroup.cpp
structures/AtomicStructure.cpp
structures/UserStructure.cpp
structures/NeighborList.cpp
structures/LatticeStructures.cpp
minimizer/SplitBregmanFunctionEvaluator.cpp
minimizer/Minimizer.cpp
minimizer/SplitBregmanMinimizer.cpp
minimizer/MinimizerParameters.cpp
minimizer/lbfgsb.f
util/xml/XMLParserUtilities.cpp
util/xml/XMLWriterUtilities.cpp
)
# Include a resource file in the library.
QT4_ADD_RESOURCES(ResourceFiles resources/resources.qrc)
ADD_LIBRARY(PotFitLibrary STATIC ${SourceFiles} ${ResourceFiles})
SET_TARGET_PROPERTIES(PotFitLibrary PROPERTIES COMPILE_DEFINITIONS "${POTFIT_COMPILE_DEFINITIONS}")
# Link with the Qt libraries.
TARGET_LINK_LIBRARIES(PotFitLibrary ${QT_LIBRARIES})
# Enable OpenMP parallelization when using a GNU C++ compiler.
IF(CMAKE_COMPILER_IS_GNUCXX AND USE_OPENMP)
SET_TARGET_PROPERTIES(PotFitLibrary PROPERTIES COMPILE_FLAGS "-fopenmp")
SET_TARGET_PROPERTIES(PotFitLibrary PROPERTIES LINK_FLAGS "-fopenmp")
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND USE_OPENMP)
src/main/CMakeLists.txt
# List of source files that need to be compiled:
SET(SourceFiles
Main.cpp
)
INCLUDE_DIRECTORIES([path to]/spglib-1.6.0/src)
INCLUDE_DIRECTORIES([path to]/spglib-1.6.0/src/.libs)
LINK_DIRECTORIES([path to]/spglib-1.6.0/src/.libs )
ADD_EXECUTABLE(PotFit ${SourceFiles})
SET_TARGET_PROPERTIES(PotFit PROPERTIES COMPILE_DEFINITIONS "${POTFIT_COMPILE_DEFINITIONS}")
TARGET_LINK_LIBRARIES(PotFit PotFitLibrary boost_timer boost_system)
set(CMAKE_PREFIX_PATH [path_to]/spglib-1.6.0/src/.libs)
find_library(SPGLIBRARY NAMES spg spglib libsymspg symspg PATHS [path_to]/spglib-1.6.0/src/.libs [path_to]/spglib-1.6.0/src)
target_link_libraries(PotFit "${SPGLIBRARY}")
message("The value of SPGLibrary is")
message("${SPGLIBRARY}")
MESSAGE("Spglib link flags: ${SPGLIB_LINK_FLAGS}")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
MESSAGE("cxx flags: ${CMAKE_CXX_FLAGS}")
MESSAGE("cxx linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
MESSAGE("Library path is : ${CMAKE_LIBRARY_PATH}")
Add to the include
extern "C"
{
#include "symspg.h" // or whatever
}