I'm importing admesh library to my cmake project, I've followed the INSTALL instructions from the file in root directory of admesh and it was copied in usr/local/include / usr/local/lib. So, I've added this in my CMakeList:
find_path(ADMESH_INCLUDE_DIR stl.h HINTS "/usr/local/include/admesh")
FIND_LIBRARY(ADMESH_LIBRARY NAMES admesh)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ADMESH DEFAULT_MSG ADMESH_LIBRARY ADMESH_INCLUDE_DIR)
IF(ADMESH_FOUND)
message("admesh found")
SET( ADMESH_LIBRARIES ${ADMESH_LIBRARY} )
ENDIF(ADMESH_FOUND)
include_directories(${ADMESH_INCLUDE_DIR})
target_link_libraries(project PRIVATE admesh ${ADMESH_LIBRARIES})
but when I tried to build it give me this error:
fatal error: 'admesh/stl.h' file not found
#include <admesh/stl.h>
^~~~~~~~~~~~~~
1 error generated.
It prints admesh found so I think that there is something wrong in my CMakeList. How can I fix it?
Should be
find_path(ADMESH_INCLUDE_DIR admesh/stl.h HINTS "/usr/local/include")
or
find_path(ADMESH_INCLUDE_DIR admesh HINTS "/usr/local/include")
Usually /usr/local/include is in the system search include paths, thus all lines until arget_link_libraries(project PRIVATE admesh) can be removed.
Related
I need to compile a C++ project using CMake and MinGW-w64. The project depends on zlib, so CMakeLists.txt contains:
find_package(ZLIB REQUIRED)
CMake will fail on ZLIB unless I add the following path to CMAKE_PREFIX_PATH:
C:/Dev/mingw64-8.1.0/x86_64-w64-mingw32/include
With this path added, CMake runs fine. But, I get the following compile error:
#include_next <stdlib.h>
^~~~~~~~~~
C:/Dev/mingw64-8.1.0/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/cstdlib:75:15:
fatal error: stdlib.h: No such file or directory
After some search about this last error, I found I can fix it by editing the CMake includes_CXX.rsp and either:
Remove -isystem C:/Dev/mingw64-8.1.0/x86_64-w64-mingw32/include
Or change -isystem to -I
So basically I have to pass the include path to CMake so that it finds zlib.h, and remove this path from the files generated by CMake... Is there a proper solution?
Thanks!
I am somewhat new to cmake and completely new to glew, glfw, and the like. I'm following a youtube channel to learn more about game engines and programming.
My problem is linking the static glew library in my project using cmake.
First, I start with the glew source code from http://mcs.une.edu.au/doc/glew-devel/index.html.
I compile it by:
cd build; cmake ./cmake; make glew_s
This adds a lib directory into the build directory with libGLEW.a
A shortened version of my CMakeLists.txt looks like:
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
project (TestProject CXX)
set(CMAKE_CXX_FLAGS "-std=c++11")
###########################
# GLEW
###########################
add_subdirectory(${CMAKE_SOURCE_DIR}/Dependencies/GLEW)
target_link_libraries(${PROJECT_NAME} glew)
and in Dependencies/GLEW I have another CMakeLists.txt:
# Add glew source and header files
file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*)
file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
add_library(glew ${glew-lib} ${glew-headers})
target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/GL")
I put a copy of the libGLEW.a file into the lib directory and the include directory is copied from the glew source code include directory. It holds the GL directory, which contains the header files glew.h, wglew.h, eglew.h, and glxew.h.
When I run cmake I get the error:
CMake Error: Cannot determine link language for target "glew".
CMake Error: CMake can not determine linker language for target: glew
The glew source code also has a src directory with glew.c in it, but if I put it in the libs directory and include it in the Dependencies/GLEW/CMakeLists.txt like:
# Add glew source and header files
file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.c)
file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
add_library(glew ${glew-lib} ${glew-headers})
target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
I get the error:
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is: CMAKE_C_COMPILE_OBJECT
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is: CMAKE_C_CREATE_STATIC_LIBRARY
Lastly, I have tried just including the glew.c and headers in the root CMakeLists.txt like:
#########################
# GLEW
#########################
include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/lib/")
include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include/GL/")
Here cmake will finish, but it won't be able to compile, saying classes do not name a type and/or are not declared in this scope.
Any help would be appreciated. I was under the impression that the libGLEW.a was the static library, and all I would have to do is link and compile it along with the headers, but that did not work.
First of all, I forgot to use
make install
after using make the first time, so I was using the incorrect libGLEW.a file.
After including the proper libGLEW.a file, my directory structure had
./Dependencies/GLEW/include/GL/*.h //header files
./Dependencies/GLEW/lib/libGLEW.a //source file
Finally, the TopLevel CMakeLists.txt is changed to include:
add_library(glew STATIC IMPORTED GLOBAL)
set_target_properties(glew PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Dependencies/GLEW/lib/libGLEW.a )
set_target_properties(glew PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include )
If I want to include the library from a lower CMakeLists.txt such as /Dependencies/GLEW/CMakeLists.txt Then I would have to first export the library from there and then import it at the topLevel CMakeLists.txt file.
Now, in order to use glew headers in my project I can just use #include .
I encounter an issue when trying to build a little bit of code. (I'm on linux)
To make it simple:
Here is what I've got in my Position.h file (at the really begining, I think the next isn't necessary to solve that issue):
#include <Eigen/Dense>
And Here is my CMakeLists.txt:
project(p)
include_directories("./Eigen")
add_executable(
p
Eigen/Dense
Position.h # wich requires Eigen/Dense
Position.cpp
#other files
)
In the project directory there is two directories: build and Eigen
To create the Makefile, I go in the build directory, then, type cmake ... A Makefile is created, but when I try to make i got the error:
/path/to/Position.h:30:23: fatal error: Eigen/Dense: no such file or directory.
Position.h is from a code picked up from github (I can give you the link if wanted).
Please, can you give me a direction to search or maybe if you see what is wrong, what is my mistake
Thanks!
You can't give a header dependency as source files in add_executable(). And if Position.h does search Eigen/Dense you probably just need include_directories(.).
project(p)
include_directories(.)
add_executable(
p
Position.cpp
Position.h
#other files
)
But why don't you use find_module()?
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
Reference
Unable to find Eigen3 with CMake
I'm working on a Cmake based C++ project in QtCreator. I am trying to use mlpack in my project, but as soon as I include the line #include <mlpack/core.hpp> to my only source file, I get an error pertaining to some libxml files that are included by mlpack/core.hpp:
In file included from /usr/local/include/mlpack/core/util/save_restore_utility.hpp:26:0,
from /usr/local/include/mlpack/core.hpp:171,
from /home/revinci/code/workspaces/qt_ws/Semantic_Perception/src/features_slic.cpp:18:
/usr/include/libxml2/libxml/parser.h:15:31: fatal error: libxml/xmlversion.h: No such file or directory
#include <libxml/xmlversion.h>
Now, I went into /usr/include/libxml2/libxml/ and found parser.h with the line #include <libxml/xmlversion.h> in it.
So, I saw that xmlversion.h and parser.h are in the same folder and tried a hack: I changed the #include <libxml/xmlversion.h> in parser.h to #include "xmlversion.h" only to get the following error:
In file included from /usr/include/libxml2/libxml/parser.h:15:0,
from /usr/local/include/mlpack/core/util/save_restore_utility.hpp:26,
from /usr/local/include/mlpack/core.hpp:171,
from /home/revinci/code/workspaces/qt_ws/Semantic_Perception/src/features_slic.cpp:18:
/usr/include/libxml2/libxml/xmlversion.h:13:31: fatal error: libxml/xmlexports.h: No such file or directory
#include <libxml/xmlexports.h>
Which is basically telling me that it can't find xmlexports.h (included by xmlversion.h). More importantly, xmlexports.h is in the same directory as xmlversion.h and parser.h!
I tried the solution mentioned here and installed libxml2-dev (again) and libxslt1-dev, but my problem wasn't solved.
I think this may have something to do with specifying my include paths correctly. I've tried to add /usr/include/libxml2 to the various path environment variables (PATH, INCLUDE_PATH and CPATH) that are present in my build environment in QtCreator, but to no avail. My CMakeLists.txt looks like this:
project(Semantic_Perception)
cmake_minimum_required(VERSION 2.8)
#Vigra Headers
include_directories(
include
)
file(GLOB_RECURSE VigraImpex include/impex/)
add_library(VigraImpex ${VigraImpex})
#LibXml2 Headers
find_package(LibXml2 REQUIRED)
#Armadillo Headedrs
find_package(Armadillo REQUIRED)
include_directories(${ARMADILLO_INCLUDE_DIRS})
#Boost Headers
find_package(Boost 1.54.0 REQUIRED)
add_executable(features_slic src/features_slic.cpp)
target_link_libraries(features_slic
VigraImpex
${ARMADILLO_LIBRARIES}
)
BTW: LibXml2, Armadillo and Boost are all dependencies of the library I am trying to use - mlpack. The command find_pakcage(mlpack) won't work because there is no Findmlpack.cmake file on my system anywhere, and I couldn't find one on the internet either.
I am trying to link log4cpp to my project. I use CMake and i can't figure out a way to do so.
Log4cpp is install on projectfolder/log4cpp/ (with bin/ include/ lib/ ... in it)
I use the following Findlog4cpp.cmake :
IF (LOG4CPP_FOUND)
SET(LOG4CPP_FIND_QUIETLY TRUE)
ENDIF (LOG4CPP_FOUND)
FIND_PATH(LOG4CPP_INCLUDE_DIR log4cpp/FileAppender.hh
"./log4cpp/include/"
)
FIND_LIBRARY(LOG4CPP_LIBRARIES
NAMES liblog4cpp.so
PATHS "./log4cpp/lib"
)
SET(LOG4CPP_FOUND 0)
IF(LOG4CPP_INCLUDE_DIR)
IF(LOG4CPP_LIBRARIES)
SET(LOG4CPP_FOUND 1 CACHE INTERNAL "log4cpp found")
IF (NOT LOG4CPP_FIND_QUIETLY)
MESSAGE(STATUS "Found Log4CPP")
ENDIF (NOT LOG4CPP_FIND_QUIETLY)
ENDIF(LOG4CPP_LIBRARIES)
ENDIF(LOG4CPP_INCLUDE_DIR)
MARK_AS_ADVANCED(
LOG4CPP_INCLUDE_DIR
LOG4CPP_LIBRARIES
)
and in my CMakeLists.txt i call it :
...
FIND_PACKAGE(log4cpp REQUIRED)
INCLUDE_DIRECTORIES(${LOG4CPP_INCLUDE_DIR})
SET(LIBS ${LOG4CPP_LIBRARIES} ${LIBS})
MESSAGE("############################# ${LOG4CPP_LIBRARIES}")
MESSAGE("############################# ${LOG4CPP_INCLUDE_DIR}")
...
The output :
-- Found Log4CPP
############################# /SOMEPATH/projectfolder/log4cpp/lib/liblog4cpp.so
############################# /SOMEPATH/projectfolder/log4cpp/include
-- Configuring done
-- Generating done
-- Build files have been written to: /SOMEPATH/projectfolder/
Then when i run make i have the folowing errors :
/SOMEPATH/projectfolder/common/Common.h:24:31: error: log4cpp/Category.hh: No such file or directory
/SOMEPATH/projectfolder/common/Common.h:25:35: error: log4cpp/FileAppender.hh: No such file or directory
/SOMEPATH/projectfolder/common/Common.h:26:34: error: log4cpp/BasicLayout.hh: No such file or directory
i just included the headers in common.h ( #include "log4cpp/xxx.hh" )
I add that all the build and compile works fine (with cmake then make) without log4cpp
Any help would be greatly appreciated
If you're adding your common directory as a subdirectory with its own CMakeLists.txt, you need to call INCLUDE_DIRECTORIES before you call ADD_SUBDIRECTORY if you want the directories already included to be passed down.