I am getting the following error:
--Configuring incomplete, errors occurred!
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
See also "C:/Users/GyuriX/.CLion2016.1/system/cmake/generated/Projects-33418280/33418280/Debug/CMakeFiles/CMakeOutput.log".
Please set them or make sure they are set and tested correctly in the CMake files:
BSON_LIBRARY
linked by target "Projects" in directory D:/DEV/C/Projects
MONGODB_LIBRARY
linked by target "Projects" in directory D:/DEV/C/Projects
Makefile:443: recipe for target 'cmake_check_build_system' failed
mingw32-make.exe: *** [cmake_check_build_system] Error 1
When I try to compile just a simple Hello World program using the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(Projects)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
include_directories(C:/mongo-c-driver/lib)
find_library(MONGODB_LIBRARY mongoc-1.0)
find_library(BSON_LIBRARY bson-1.0)
add_executable(Projects ${SOURCE_FILES})
target_link_libraries(Projects ${MONGODB_LIBRARY} ${BSON_LIBRARY})
I have compiled the required libraries based on what the mongodb wiki said, so I have the library files:
The files I have compiled
So the question is that what am I doing wrong and what should I do to be able to use the mongodb in CLion.
Error message means that find_library fails to find requested libraries.
As you install libraries into non-default directories (according to the screenshot, it is C:\mongo-c-driver\bin), you need to hint for find_library() where it should search.
One possible way is to set CMake variable CMAKE_LIBRARY_PATH:
set(CMAKE_LIBRARY_PATH "C:\\mongo-c-driver\\bin")
# Now find_library should be able to find libraries
find_library(MONGODB_LIBRARY mongoc-1.0)
find_library(BSON_LIBRARY bson-1.0)
There are others way for hint to find_library, see its documentation about search algorithm it uses.
Related
I try to build a project on CLion with Cygwin and I got this error :
-- Found Boost: /usr/include (found version "1.66.0") found components: system thread regex iostreams chrono date_time atomic
-- Configuring done
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:
QUICKFIX_LIBRARY
linked by target "run_engine" in directory /cygdrive/c/Users/33671/Desktop/main_program
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
I try to generate the .exe fail but nothing appeared because of this error.
Any idea ?
So I changed the Path of QUICKFIX_LIBRARY in the CmakeCache.txt and then I don't have the error. But in reality it's still not finding it because once it's written in CMakeCache.txt, it doesn't check anymore if it's really include or not.
My lib is located like this : project_name/exchanges/quickfix/lib/cygquickfix-16.dll.
The lib is cygquickfix-16.dll.
I added a control message to see if he found or not the library.
I still have an ERROR at the end.
cmake_minimum_required(VERSION 3.5)
project(test)
set(CMAKE_CXX_STANDARD 14)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREAD ON)
SET(CMAKE_PREFIX_PATH /lib/)
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread regex iostreams)# 1.66.0
IF(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ENDIF(Boost_FOUND)
SET(USED_LIBS ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_IOSTREAMS_LIBRARY})
add_executable(run_engine main_poco.cpp ....)
include_directories(.)
include_directories(./exchanges/quickfix/include)
find_library(QUICKFIX_LIBRARY quickfix HINTS ./exchanges/quickfix/lib)
message("-- QUICKFIX_LIBRARY: ${QUICKFIX_LIBRARY}")
target_link_libraries(run_engine ${QUICKFIX_LIBRARY} -lPocoDataMySql -l...)
And then I get this in CMake Debug :
C:\Users\33671\AppData\Local\JetBrains\CLion2022.1\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make.exe -DCMAKE_C_COMPILER=/usr/bin/gcc.exe -DCMAKE_CXX_COMPILER=/usr/bin/c++.exe -G "CodeBlocks - Unix Makefiles" -S /cygdrive/c/Users/33671/Desktop/project -B /cygdrive/c/Users/33671/Desktop/project/cmake-build-debug
-- QUICKFIX_LIBRARY: QUICKFIX_LIBRARY-NOTFOUND
-- Configuring done
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:
QUICKFIX_LIBRARY
linked by target "run_engine" in directory /cygdrive/c/Users/33671/Desktop/project
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
I am new to C++ and want to include the boost library (specifically the filesystem part which needs to be built) in my project. I tried many solutions from other stackoverflow users but they didn't help me at all. I am using CLion with CMake.
The main.cpp is calling the other .cpp files inside the modules/ folder.
The file structure:
ProjectName
>boost
>lots of folders and .hpp files
>cmake-build-debug
>modules
encryption.cpp
encryption.h
output.cpp
output.h
CMakeLists.txt
main.cpp
The boost folder doesn't contain the entirety of boost when you download and extract it. I dragged the boost folder inside of boost_1_72_0 in my project (just so you know that there's no libs folder, etc. inside)
The CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(ProjectName)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
set(SOURCE_FILES
main.cpp
modules/encryption.cpp modules/encryption.h modules/output.cpp modules/output.h
)
set(Boost_ARCHITECTURE -x64)
set(BOOST_ROOT boost/)
set(Boost_INCLUDE_DIRS boost/filesystem)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(ProjectName ${SOURCE_FILES})
target_link_libraries(ProjectName ${Boost_LIBRARIES})
output.cpp
// some includes //
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include "../boost/filesystem.hpp"
// some code //
The Error message:
CMake Error at C:/Program Files/JetBrains/CLion 2019.1.4/bin/cmake/win/share/cmake-3.14/Modules/FindBoost.cmake:2147 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/username/Desktop/C++/ProjectName/cmake-build-debug/CMakeFiles/CMakeOutput.log".
mingw32-make.exe: *** [cmake_check_build_system] Error 1
Makefile:235: recipe for target 'cmake_check_build_system' failed
I know that it's basically telling me what I have to do but I don't know what's exactly meant by the "root directory" of boost, by the directory "containing Boost's headers" and how to put everything together.
Many thanks in advance!
I dragged the boost folder inside of boost_1_72_0 in my project
Looks like you just copied boost source into your project dir.
You have to compile boost since you need filesystem. Or you can get boost from:
vcpkg - it's the easiest way for you. I am highly recommended this way.
Sourceforge.
Conan
I don't know what's exactly meant by the "root directory"...
Since you are using boost by calling find_package(Boost) - CMake uses FindBoost module. It will try to find your boost installation inside system PATH variable or in some other "standard" places. Your boost "installation" is not common, so you have to specify where boost is with BOOST_ROOT variable. set(BOOST_ROOT boost/) is incorrect way to do this. You have to specify absolute path like set(BOOST_ROOT "C:/lib/boost/boost17.2")
or relative to current CMakeList.txt - set(BOOST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/boost}.
With right installed boost all you have to do is:
find_package(Boost REQUIRED [COMPONENTS <libs>...])
target_link_libraries(main PRIVATE ${Boost_LIBRARIES})
target_include_directories(main PRIVATE ${Boost_INCLUDE_DIRS})
Usually, you don't need to set Boost_ARCHITECTURE and Boost_INCLUDE_DIRS CMake does it for you.
When you use find_package with REQUIRED option you don't need to check whether the library found or not since CMake raises an error when a library isn't found.
BOOST_ROOT is a directory when boost installed or unpacked.
BOOST_INCLUDEDIR is a directory with boost headers (usually it's BOOST_ROOT/boost). So try to set the full path to your boost_1_72_0 directory to BOOST_ROOT CMake variable.
Also, I had a problem with COMPONENTS option. Try to remove it if errors remain.
i've tried to add PROFILE to the CMAKE_BUILD_TYPES. For this I need to add -finstrument-functionsto the CMAKE_CXX_FLAGS in the toolchain file and link the belonging library with the absolut path in the CMakeLists.txt via target_link_libraries. So far so good and unproblematic.
But when refreshing the buildinformations cmake checks if the compiler stil does it's job. And now "is not able to compile a simple test program", due to the lack of the needed library, which is linked later in the CMakeLists.
So I commented the -finstrument-functions flag and the testprogramm could be compiled.
I've tried to:
- Set librarie and path as a part of the CXX flags with -L -l:
Use the link_directories(<dir>) command as well as SET(CMAKE_LINK_DIRECTORIES_BEFORE <Path> ) and SET(CMAKE_LIBRARY_PATH <Path>)
Set variables in the toolchainfile and call them later in the cmakelists:
SET(ADDITIONAL_PROFILE_LIBRARY "$ENV{QNX_BASE}/target/qnx7/armle-v7/usr/liblibprofilingS.a")
SET(ADDITIONAL_PROFILE_FLAGS "-finstrument-functions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "${ADDITIONAL_PROFILE_FLAGS}")
add_executable(toolchainTester main.cpp)
target_link_libraries(toolchainTester ${ADDITIONAL_PROFILE_LIBRARY})
But then getting the error: mingw32-make.exe[3]: *** No rule to make target 'C:/qnx700/target/qnx7/armle-v7/usr/liblibprofilingS.a', needed by '../out/profileout'. Stop.
Got anyone any more ideas? Thanks in advance.
If there anyone out there, looking for the same workaround how to manage different flags and libraries for different profiles, this is one working way:
First set variables in the toolchainfile
SET(ADDITIONAL_PROFILE_LIBRARY "$ENV{QNX_BASE}/target/qnx7/armle-v7/usr/lib/libprofilingS.a")
SET(ADDITIONAL_CXX_FLAGS "-finstrument-functions")
The call/overright them in the CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "${ADDITIONAL_CXX_FLAGS}")
add_executable(toolchainTester main.cpp)
target_link_libraries(toolchainTester ${ADDITIONAL_PROFILE_LIBRARY})
I am trying to compile a C++ project on linux which utilizes freeglut.
I can not build the project because the libraries are not linked correctly in the CMake files. I researched and tried to apply what was mentioned in a similar answer here: How to compile GLUT + OpenGL project with CMake and Kdevelop in linux?
However build process still fails with the following exception:
/opt/JetBrains/apps/CLion/ch-0/181.4668.70/bin/cmake/bin/cmake --build /home/user/Documents/Projects/GdvProject/cmake-build-debug --target testas -- -j 2
CMake Error at CMakeLists.txt:9 (target_link_libraries):
Cannot specify link libraries for target "GdvProject" which is not built by
this project.
-- Configuring incomplete, errors occurred!
See also "/home/user/Documents/Projects/GdvProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1
My CMakeLists file looks like this:
cmake_minimum_required(VERSION 2.8)
project(GdvProject)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(GdvProject ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
How can I fix this issue?
target_link_libraries wants a target name. Targets are specified by (among others) add_executable, add_library and add_custom_target.
In other words, target_link_libraries(testas ...) should work.
While you're at it, you should consider switching your include_directories(...) to target_include_directories(testas ...) as well.
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.