I am having problems compiling simple example code taken from the official website here https://graphviz.gitlab.io/_pages/dot.demo/demo.c .The problem is undefined reference to Graphviz functions. I know there is a related question asked here Qt Creator cannot resolve gvContext on Ubuntu, but it didn't help.
I have included libgvc libcgraph libcdt in my CMakeLists.txt and that did't help. I have made sure that these packages are present on my machine.
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(name)
set(CMAKE_CXX_STANDARD 14)
add_executable(name main.cpp)
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(gvc REQUIRED libgvc libcgraph libcdt)
LINK_DIRECTORIES(${gvc_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${gvc_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gvc_LIBRARIES})
Please if someone linked the library or knows how to link correctly, let me know.
Did you install the libgraphviz-dev package? That contains the libgvc pkg-config file your CMakeLists.txt needs.
Related
I am a complete beginner in C++ programming and have been advised to use CLion. I am trying to get the Boost package to work.
I found many posts and tutorials online, however they all skip the basics not known to someone who is not a programmer. Namely, there is no explanation of how to get from the moment you open a new project to using some function from the Boost package?
This is what I found to be lacking from previous answers:
Here we are advised to use live incboost live template, however there is no explanation on where to find it or how to use it.
Here seems like a clear tutorial, however it is aimed at Visual Studio, not CLion.
Here I am not sure what each of those files are and how to adjust them to match my case.
I have downloaded boost_1_70_0 from https://www.boost.org/users/download/ and it is now unzipped and saved in C:\...\boost_1_70_0.
Could someone please explain really simply how to get from a blank project to being able to use functions stored in boost?
Considering you are using CLion and it supports only CMake at this time and you have installed BOOST library in the default directory, then your CMakeLists.txt file should look like this. I have used it in linux operating system but it should be able in Windows too.
cmake_minimum_required(VERSION 3.13)
project(LaserCV)
set(CMAKE_CXX_STANDARD 17)
#local
file(GLOB SOURCES
*.hpp
*.cpp
)
add_executable(LaserCV ${SOURCE_FILES} ${SOURCES})
#add_executable(LaserCV main.cpp)
SET(CMAKE_CXX_FLAGS -pthread)
#boost
find_package(Boost REQUIRED)
target_link_libraries(LaserCV ${Boost_LIBRARIES})
include_directories(${Boost_INCLUDE_DIR})
Then simply include a header file for your wanted boost function, for example:
#include <boost/random.hpp>
So I'm trying to use OpenCV on windows (my ubunut is broken) and I can't configure my Clion to compile my openCV code.
first; i'm completely new to OpenCV so this question might be an easy one but I did all I could to find the problem to no avail.
I used MinGW and Clion and my codes run with no problem if I don't use OpenCv which indicates there's no problem with MinGW installation.
I downloaded OpenCv files and extracted them, then added them to System path.
after that I configured my Cmakelists.txt (my first time modifying it, so I was an amateur) like this.
After that I got this error:
Error:By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided
by "OpenCV", but CMake did not find one. Could not find a package
configuration file provided by "OpenCV" with any of the following
names: OpenCVConfig.cmake opencv-config.cmake Add the installation
prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a
directory containing one of the above files. If "OpenCV" provides a
separate development package or SDK, be sure it has been installed.
I know I'm doing something wrong or missing a step but I can't figure out why. is there any guide or tutorial for my scenario or can anyone point me towards a correct direction?
thanks in advance and any help appreciated.
I managed to make those errors go away with changing my
CMakeLists.txt to:
cmake_minimum_required(VERSION 3.5)
project(something)
set(OpenCV_DIR "E:/Programs/programming/opencv/build2") find_package( OpenCV REQUIRED )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp) add_executable(something ${SOURCE_FILES})
add_executable( {SOURCE_FILES} DisplayImage ) target_link_libraries( ${OpenCV_LIBS} DisplayImage )
and building the libraries on my own by minGW and Cmake.
This question already has answers here:
CMake link to external library
(6 answers)
Closed 5 years ago.
I am trying to link to a shared library using CMake. I understand that this can bee achieved using the target_link_libraries() command. I have been able to get this working but not quite in the way that I would like.
Using the below CMakeLists.txt, I've been able to link to the shared library.
cmake_minimum_required(VERSION 3.7)
project(DylibTest)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(DylibTest ${SOURCE_FILES})
target_link_libraries(DylibTest
${CMAKE_SOURCE_DIR}/Resources/libDynamicTest.dylib)
This seems to tell the linker to look in the directory that the project is located in. This is fine for development, but how would I distribute this project? End-users will clearly not have this same folder.
I've tried to pass in a relative path like so:
cmake_minimum_required(VERSION 3.7)
project(DylibTest)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(DylibTest ${SOURCE_FILES})
target_link_libraries(DylibTest /Resources/libDynamicTest.dylib)
When doing this, I get the following error:
No rule to make target `/Resources/libDynamicTest.dylib', needed by `DylibTest'. Stop.
I've looked at the documentation for target_link_directories() but it has not been helpful. I've also looked at numerous other questions here.
In case it's not clear, my intention is to distribute the executable with a folder named "Resources" that contains the shared library. How should my CMakeLists.txt file look in order to do this?
EDIT: In response to this question being marked as a possible duplicated of this question, I do concede that that question is basically asking the same thing, the answers there do not work for me.
Here's how my CMakeLists.txt looks after trying a accepted answer on the other question:
cmake_minimum_required(VERSION 3.7)
project(DylibTest)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(DylibTest ${SOURCE_FILES})
link_directories(${CMAKE_BINARY_DIR}/Resources)
target_link_libraries(DylibTest DynamicTest)
This unfortunately does not work an results in an error stating that the library could not be found.
Have a look at https://cmake.org/cmake/help/v3.0/command/find_library.html.
You can specify one or more alternative search folder for cmake to look for the library. It also looks in the default library folder for your OS as well.
find_library(YOURLIB
NAMES your // without the lib
PATHS ${CUSTOM_LIB_PATH})
You can then link the library with
target_link_library(targetname ${YOURLIB})
You might be looking for Creating packages with CPack? This lets you describe how your project shall be packaged into a setup routine and what the file layout after installing looks like.
I have learned the basics of C++ programming and thought of ways how I could proceed, in order to practise. One thing that caught my interest was Web Scraping. Since I only knew BeautifulSoup, I searched for an alternative for C++ and found libXML for C++, however I'm trying to install it but don't seem to get it to work, since I barely have an idea on how to configure a CMake file. I'm using CLion as an IDE and Windows as my operating system, if it matters. My project folder is
C:\Users\Laurenz\Documents\Programming\untitled10
and the place where I've put the libXML library is
C:\Users\Laurenz\Documents\Programming\untitled10\libXML
however, I think the "main" directory is the one below (since it contains most of the Source files), but I'm not sure which of both I need to include.
C:\Users\Laurenz\Documents\Programming\untitled10\libXML\libxml++
I've searched around in the internet and found dozens of methods on how people include libraries, so I'm not sure which I need to use. What I currently have:
cmake_minimum_required(VERSION 3.6)
project(untitled10)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(untitled10 ${SOURCE_FILES})
set(CMAKE_PREFIX_PATH "C:\\Users\\Laurenz\\Documents\\Programming\\untitled10\\libXML\\libxml++")
find_package(LibXML++ REQUIRED)
include_directories(${LibXML++_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LibXML++_LIBRARIES})
target_link_libraries(untitled10 ${LIBS})
However, I get the following error message:
Error:By not providing "FindLibXML++.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "LibXML++", but CMake did not find one.
Could not find a package configuration file provided by "LibXML++" with any of the following names:
LibXML++Config.cmake libxml++-config.cmake
Add the installation prefix of "LibXML++" to CMAKE_PREFIX_PATH or set "LibXML++_DIR" to a directory containing one of the above files. If "LibXML++" provides a separate development package or SDK, be sure it has been installed.
Could someone tell me how to properly configure LibXML? And maybe someone knows some resources where I can learn how CMake files work, because it confuses me a bit.
Thanks!
How can I link shared object to my own code in cmake ?
I'd like to link OpenCV, I mean libopencv_***.so.3.1 or something like that to my own software package.
In that case, I believe the following lines are the answer of this question.
...
find_package(OpenCV 3.1)
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})
...
target_link_libraries(my_node ${OpenCV_LIBRARIES})
But, here's this problem.
I've installed OpenCV 2.4.8 under /usr/include and /usr/lib/x86_64-linux-gnu before, and now I'd like to use OpenCV 3.1.0 installed in local directory "~/Libs/opencv" from code.
So when compiling the codes, OpenCV 2.4.8 takes priority and is used.
In this case, how should I describe CMakeLists.txt ?
Currently I'm writing as the follow.
...
set(CMAKE_PREFIX_PATH ${HOME}/Libs/opencv)
include(${HOME}/Libs/opencv/share/OpenCV/OpenCVConfig.cmake)
find_package(OpenCV 3.1)
set(OpenCV_INCLUDE_DIRS ${HOME}/Libs/opencv/include)
include_directories(${OpenCV_INCLUDE_DIRS)
set(OpenCV_LIBRARY_DIRS ${HOME}/Libs/opencv/lib)
link_directories(${OpenCV_LIBRARY_DIRS})
...
The above CMakeLists.txt kind of helped me.
If executable file is copied to the same directory where libopencv_***.so.3.1 is, the above CMakeLists.txt works.
Otherwise, "make" fails.
But I'd like to make it independent on the directory which contains executable file.
How should I do for this problem ?
Thanks in advance.
See cmake's doc of find_library.
Some predefined paths are used to search for libs. (Platform dependent). It is possible to disable this by options.
Try
find_package(OpenCV 3.1 PATHS ~/Libs/opencv NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH)