Host Environment
OS: [Windows 11 using WSL (Ubuntu-22.04)]
Compiler: Clang 14.0.0
The issue
Firstly, I did vcpkg install fmt --triplet x64-Linux and everything worked properly. After that, I wrote some configurations in the top-level CMakeLists.txt to find the FMT package. Then, I linked FMT to my executable, and it was built successfully. However, when I include fmt, an error immediately occured.
Top-level CMakeLists.txt
CMakeLists.txt in the app subdirectory
Main.cpp, the executable that will be generated from; it also shows the error of including FMT
Even the IDE managed to suggest FMT, meaning that it knows it exists
Further evidence of the package already installed
The zip file if you want to inspect
hp_bot.zip
I tried to modify my include directories in the c_cpp_properties.json but found no luck.
There is nothing wrong with your vcpkg installation or CMake file. You are just including the wrong headers.
Instead of
#include <fmt>
(which is a directory)
you should include some of the files within that directory:
#include <fmt/core.h>
Related
I have a project where I want to use etcd-cpp-apiv3 library(https://github.com/etcd-cpp-apiv3/etcd-cpp-apiv3), so I installed with vcpkg. But when I run it, fails.
I installed it with vcpkg: 'vcpkg install etcd-cpp-apiv3:x64-windows' and included it with these cmake commands:
set(VCPKG_ROOT "C:/vcpkg")
set(VCPKG_TARGET_TRIPLET "x64-windows")
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_PREFIX_PATH "${VCPKG_ROOT}/installed/x64-windows")
include_directories(${CMAKE_PREFIX_PATH}/include)
find_package(etcd-cpp-api CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE etcd-cpp-api)
It recognizes the include statement: #include <etcd/Client.hpp> But when I run the project I get so many errors on pplx header files located in vcpkg installation folder: C:/vcpkg/installed/x64-windows/include/pplx Examples of these errors
C:/vcpkg/installed/x64-windows/include/pplx/pplxtasks.h:2877:21: error: '_ASSERTE' was not declared in this scopeIn main
C:/vcpkg/installed/x64-windows/include/pplx/pplxtasks.h:222:104: note: in definition of macro 'PPLX_CAPTURE_CALLSTACK' 222 | #define PPLX_CAPTURE_CALLSTACK() ::pplx::details::_TaskCreationCallstack::_CaptureSingleFrameCallstack(_ReturnAddress())
C:/vcpkg/installed/x64-windows/include/pplx/pplxtasks.h: In instantiation of 'pplx::details::_Task_completion_event_impl<_ResultType>::~_Task_completion_event_impl() [with _ResultType = unsigned char]':
Apparently the library uses pplx
I have tried to add manually pplx library with target_include_libraries but I dont know if that makes any sense. I have also tried to remove output cmake folder, reinstall all vcpkg, make sure the the vcpkg paths and environtment variables are set up correctly, make sure that I was dowloading x64 bits libraries etc but none worked.
Im using windows 64 bit, with clion.
If someone could help me or give a clue about what is going on, I would be very pleased
I found the error.
Etcd-clientv3 library uses cpprest library which only supports Microsoft's C++ compiler, MSVC. As I was using Clion's default compiler, Mingw, there were lot of errors when compiling cpprest.
The solution was to change clion's compiler to MSVC
Unfortunately, i have some problems adding the headers only Eigen 3.3.7 Library to my Makefile with Cmake on my Ubuntu 18.04.4 LTS system.
I can compile my code using the library by just copying the library folder in the include directory and using
include_directories(./include/eigen3) in the CMakeLists.txt file. However, i would much prefer not having the library path hard-coded but being able set it dynamically in the CMakeLists.txt file to make sharing the project with other people easier. Unfortunately, none of the instructions i found worked for me.
I prepared the following minimum code example:
main.cpp:
#include <eigen3/Eigen/Dense>
#include <iostream>
int main()
{
Eigen::Vector3d test_vec(1.0f, 2.0f, 3.0f);
std::cout << test_vec << std::endl;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(Eigen-Cmake-Test VERSION 1.0) # set the project name
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${EIGEN_INCLUDE_DIR})
# add the executable
add_executable("${PROJECT_NAME}" ./main.cpp)
target_link_libraries("${PROJECT_NAME}" Eigen3::Eigen)
I downloaded the headers only Eigen 3.3.7 Library and renamed the folder to eigen3. The folder was then moved to:
/usr/local/share/eigen3
when i run cmake CMakeLists.txt i get the following error:
CMake Error at CMakeLists.txt:5 (find_package):
Could not find a package configuration file provided by "Eigen3" (requested
version 3.3) with any of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
"Eigen3_DIR" to a directory containing one of the above files. If "Eigen3"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
As i checked the Eigen library folder i realized that /usr/local/share/eigen3/cmake only contained a file named Eigen3Config.cmake.in instead of Eigen3Config.cmake which was required. Why is this the case?
I tried renaming the file to Eigen3Config.cmake. Here the error was the following:
CMake Error at CMakeLists.txt:5 (find_package):
Could not find a configuration file for package "Eigen3" that is compatible
with requested version "3.3".
The following configuration files were considered but not accepted:
/usr/local/share/eigen3/cmake/Eigen3Config.cmake, version: unknown
-- Configuring incomplete, errors occurred!
Furthermore, i also tried the solutions explained stackoverflow: CMake find_package not working for Eigen? without success.
How can i make this work properly? Also i think i do not quite understand the underlying system yet. Any explanation would be appreciated.
The problems you are running into are caused by downloading the Eigen source code but not actually building the project. You may think since its a header only library that there is no build step. Well there is; it builds the package config .pc and Eigen3Config.cmake files. One of which you are trying to use.
From my previous comment the file Eigen3Config.cmake.in is a template and will be used to generate the Eigen3Config.cmake which then would be usable.
Its probably easier to install the libeigen3-dev package, it is packaged with /usr/lib/cmake/eigen3/Eigen3Config.cmake. If you insist on using Eigen from source then build and install it
If you DO want to download and install as source maybe take a look at the INSTALL file which has a "Method 2" suggesting how to use it in cmake.
I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.
Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.
After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:
However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>
Where should I further investigate?
As others have said vcpkg integrate install and vcpkg.cmake don't work together the reason being:
set_target_properties(${name} PROPERTIES VS_USER_PROPS do_not_import_user.props)
set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
this deactivates the integration. The reason to deactivate the integration is so that you don't write an incomplete CMakeLists.txt (e.g. missing the include directory or not linking all required libraries).
As such replace find_library(GDAL gdal) with find_package(GDAL REQUIRED) and target_link_libraries against the target GDAL::GDAL (https://cmake.org/cmake/help/v3.17/module/FindGDAL.html)
I'm attempting to build an application using the AWS IOT device sdk for C++.
I was able to clone, build and install the library with CMake and Visual Studio. Now I'm trying to include the IotShadow library into my test application through CMake.
I've included the package in my CMakeLists.txt file as follows and included the path the library install through the CMAKE_PREFIX_PATH variable.
find_package(IotShadow-cpp REQUIRED)
target_link_libraries(TestApp IotShadow-cpp)
CMake runs fine and things seem to be setup. However when I attempt to build, the IotShadow header files are not found. I've confirmed that IotShadow-cpp_DIR is correct and that the header files do exist. I'm not sure where to go from here. Has anyone successfully used the SDK on windows?
Looks like the target for find_package is correct but the target for target_link_libraries needs to be AWS::IotShadow-cpp.
The following seemed to work for me:
find_package(IotShadow-cpp REQUIRED)
target_link_libraries(TestApp AWS::IotShadow-cpp)
I have a CLion C++ project that has the following structure:
project
---->my_includes
| ----> my_own.hpp
---->source
----> my_app
----> my_src.cpp
The first line of my_src.cpp is
#include "my_includes/my_own.hpp"
I use an external build system that requires this inclusion format. The problem is if I use a function in my source file defined in the included header, CLion says "Cannot find my_own.hpp" if I try to hover over the inclusion.
I tried marking the include directory as containing Project Source or Headers but this didn't fix it. Any ideas?
You need to create a CMakeLists.txt for CLion to be happy. It is enough to declare all the source files, you don't have to convert your scons (or any other build system) to cmake.
You don't even have to write the CMakeLists.txt by hand, you can ask CLion to do it:
File | New CMake Project from Sources... (since CLion 2019.2)
File | Import project ... | (older CLion)
and then point at the directory containing your project.
Now edit the generated CMakeLists.txt and add a cmake command to tell CLion where to find the includes (actually to tell the compiler, and CLion will reuse that information).
Since your source files use the include as #include "my_includes/my_own.hpp", you need to tell cmake the base directory containing directory my_includes:
include_directories(.)
Where the dot means the same directory as the one containing the CMakeLists.txt.
I tested with a project reproducing your layout and from my_src.cpp I can navigate to my_own.hpp.
Then to build you still have to use scons in a console. It is also possible to add a cmake command, add_custom_target() that will call your scons (or your make, or whatever), so that you can also navigate from CLion to the build errors.
This should be a CMake-based project to open correctly in CLion.
Check CMake basics tutorial if you are new to CMake: https://www.jetbrains.com/help/clion/2016.1/quick-cmake-tutorial.html
And for MakeFile + gcc (g++) projects, you can add the flag -I /Dir/To/Your/Project.
If CLion still shows errors with #include after recompiling the make file, delete the .idea folder and restart CLion.