How to include library in cmake.
The path for the glew header files is"
C:\VizPlugins_Library\Library\glew\glew-2.1.0\include\GL"
The path for library is
C:\VizPlugins_Library\Library\glew\glew-2.1.0\lib\Release\x64
with the lib file having name
"glew32.lib"
The path for dll file
C:\VizPlugins_Library\Library\glew\glew-2.1.0\bin\Release\x64
The name of the file is
glew32.dll
How to include the glew package path in the cmake file.
This is the cmake file.
make_minimum_required(VERSION 3.0)
project(ocean)
include_directories(include)
link_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_BINARY_DIR}/include)
set(ENGINE_NAME engine)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "-O4")
set(BUILD_SHARED_LIBS True)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_BUILD_TYPE Release)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLM REQUIRED)
find_package(GLFW3 REQUIRED)
set(LIBS glfw3 gdi32 opengl32 glew32)
include_directories(
"${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/include"
)
file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${LIBS})
Related
I have the following project structure:
utils
include
utils
image_utils.h
CMakelists.txt
package.xml
graph
src
graph.cpp
CMakelists.txt
package.xml
I am trying to use image_utils.h in graph.cpp.
The CMakelists inside utils looks like this:
cmake_minimum_required(VERSION 3.0.2)
project(utils)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS roscpp
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_library(${PROJECT_NAME} INTERFACE)
target_link_libraries(${PROJECT_NAME} INTERFACE ${catkin_LIBRARIES} )
install(
DIRECTORY include/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
And in the CMakelists inside graph i call find_package(catkin REQUIRED COMPONENTS roscpp) as seen below:
cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs cv_bridge utils)
find_package(OpenCV 3.4 REQUIRED)
include_directories(${catkin_INCLUDE_DIRS} )
catkin_package(CATKIN_DEPENDS utils)
add_executable(graph src/graph.cpp)
target_link_libraries(graph ${catkin_LIBRARIES} ${OpenCV_LIBS} utils)
The package.xml of graph has the following relevant tag:
<depend>utils</depend>
My error message is:
graph.cpp:12:10: fatal error: utils/image_utils.h: No such file or directory
#include "utils/image_utils.h"
^~~~~~~~~~~~~~~~~~~~~
Any idea what I am doing wrong here?
You need to rearrange your folder structure to utils/include/utils/image_utils.h and then also add an add_library(...) call in your CMakeLists.txt file.
Finally figured it out. Here are my CMakelists files:
utils:
cmake_minimum_required(VERSION 3.0.2)
project(utils)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
graph:
cmake_minimum_required(VERSION 3.0.2)
project(pose_graph)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs cv_bridge utils)
find_package(OpenCV 3.4 REQUIRED)
catkin_package(CATKIN_DEPENDS utils)
include_directories(${catkin_INCLUDE_DIRS} )
add_executable(graph src/graph.cpp)
target_link_libraries(graph ${catkin_LIBRARIES} ${OpenCV_LIBS})
I am building a cross-platform project using cmake in Visual Studios 2022 Community Edition.
I am unable to include library headers files and linker files.
Error
1> [CMake] Could NOT find Boost (missing: Boost_INCLUDE_DIR)
Top-level CMake project file
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
# Set vcpkg library path
set(CMAKE_TOOLCHAIN_FILE C:/vcpkg/scripts/buildsystems/vcpkg.cmake)
project ("Test")
# Include sub-projects.
add_subdirectory ("Test")
CMake project for Test
# CMakeList.txt : CMake project for Test, include source and define
# project specific logic here.
#
# Set to C++20 standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_BUILD_TYPE debug)
# Set to C17 standard
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
#add library packages
set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
set(Boost_USE_RELEASE_LIBS ON) # only find release libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_INCLUDEDIR "C:\\vcpkg\\installed\\x64-windows-static\\include\\boost")
find_package(Boost REQUIRED)
if(Boost_FOUND)
message(${Boost_VERSION_STRING})
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(Test ${Boost_LIBRARIES})
endif()
find_package(pystring REQUIRED)
find_package(plog REQUIRED)
# Add source to this project's executable.
add_executable (Test main.cpp common.cpp MqttClient.cpp Protocol.cpp SerialPort.cpp)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET Test PROPERTY CXX_STANDARD 20)
endif()
# TODO: Add s and install targets if needed.
All,
I am trying change QT pro file to cmake ,and found a error.
got a error
CMake Error at CMakeLists.txt:60 (target_link_libraries):
Target "opencvTest" links to:
Qt5::network
but the target was not found.
here is CMakeLists.txt
`
cmake_minimum_required(VERSION 3.5)
project(opencvTest VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "I:/Qt515/5.15.2/mingw81_64/lib/cmake")
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets network)
find_package(Qt5Network REQUIRED)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(opencvTest
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET opencvTest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(opencvTest SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(opencvTest
${PROJECT_SOURCES}
)
endif()
endif()
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../../b")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(opencvTest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::network)
target_link_libraries(opencvTest PRIVATE ${OpenCV_LIBS})
set_target_properties(opencvTest PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
install(TARGETS opencvTest
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(opencvTest)
endif()
`
win10 + QT 5.15.2 + mingw81_64
did I miss somethings?
if I replace Qt${QT_VERSION_MAJOR}::network to Qt${QT_VERSION_MAJOR}::Core or Gui , it works.
and also fail with Qt${QT_VERSION_MAJOR}::Multimedia.
If I remove Qt${QT_VERSION_MAJOR}::network, I will get a header file lost error.
fatal error: QCameraInfo: No such file or directory
#include <QCameraInfo>
I am building a python extension from c++ shared library.
This library is using some openmp pragma.
I would like to know how to configure CMakeLists.txt in order to include openmp ?
I have added the openmp flag -fopenmp
But I still have this error : undefined symbol: GOMP_critical_end
here is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.10)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++lastest -pthread -fopenmp")
project (py_interface)
#find_library('gomp')
find_package(OpenMP REQUIRED)
find_package(Boost REQUIRED)
include_directories(/usr/include/python3.6/)
link_directories(/usr/local/lib)
set(SRC interface.cpp)
add_library(py_interface SHARED ${SRC})
target_link_libraries(py_interface PRIVATE OpenMP::OpenMP_CXX ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
set_property(TARGET py_interface PROPERTY POSITION_INDEPENDENT_CODE ON)
I am trying to add sfml to my cmake project.
sfml-network and sfml-system are working correctly but when i add sfml-graphics or
sfml-window or sfml-audio i am getting errors:
Error: sfml found but some of its dependencies are missing FreeType OpanAl VorbisFile VorbisEnc Vorbis Ogg FLAC
My CmakeList file
cmake_minimum_required(VERSION 3.0)
project(Glitter)
option(GLFW_BUILD_DOCS OFF)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)
add_subdirectory(Glitter/Vendor/glfw)
option(ASSIMP_BUILD_ASSIMP_TOOLS OFF)
option(ASSIMP_BUILD_SAMPLES OFF)
option(ASSIMP_BUILD_TESTS OFF)
add_subdirectory(Glitter/Vendor/assimp)
option(BUILD_BULLET2_DEMOS OFF)
option(BUILD_CPU_DEMOS OFF)
option(BUILD_EXTRAS OFF)
option(BUILD_OPENGL3_DEMOS OFF)
option(BUILD_UNIT_TESTS OFF)
add_subdirectory(Glitter/Vendor/bullet)
add_subdirectory(Glitter/Vendor/SFML)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++11")
if(NOT WIN32)
set(GLAD_LIBRARIES dl)
endif()
endif()
include_directories(Glitter/Headers/
Glitter/Vendor/assimp/include/
Glitter/Vendor/bullet/src/
Glitter/Vendor/glad/include/
Glitter/Vendor/glfw/include/
Glitter/Vendor/glm/
Glitter/Vendor/stb/
Glitter/Vendor/SFML/inlcude/
)
file(GLOB VENDORS_SOURCES Glitter/Vendor/glad/src/glad.c)
file(GLOB PROJECT_HEADERS Glitter/Headers/*.hpp)
file(GLOB PROJECT_SOURCES Glitter/Sources/*.cpp)
file(GLOB PROJECT_SHADERS Glitter/Shaders/*.comp
Glitter/Shaders/*.frag
Glitter/Shaders/*.geom
Glitter/Shaders/*.vert)
file(GLOB PROJECT_CONFIGS CMakeLists.txt
Readme.md
.gitattributes
.gitignore
.gitmodules)
source_group("Headers" FILES ${PROJECT_HEADERS})
source_group("Shaders" FILES ${PROJECT_SHADERS})
source_group("Sources" FILES ${PROJECT_SOURCES})
source_group("Vendors" FILES ${VENDORS_SOURCES})
set(SFML_DIR "Glitter/Vendor/SFML/")
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML COMPONENTS network system audio window graphics REQUIRED)
add_definitions(-DGLFW_INCLUDE_NONE
-DPROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\")
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${PROJECT_HEADERS}
${PROJECT_SHADERS} ${PROJECT_CONFIGS}
${VENDORS_SOURCES})
target_link_libraries(${PROJECT_NAME} assimp glfw
${GLFW_LIBRARIES} ${GLAD_LIBRARIES}
BulletDynamics BulletCollision LinearMath sfml-network sfml-system sfml-window sfml-graphic sfml-window)
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
When using the static version of SFML you'll also have to allow CMake to find the listed dependencies. For Windows, these should appear where you've installed/unpacked SFML. For other operating systems, you'll have to install them manually.
You can also look in your CMakeCache.txt file and look for the entries for those libraries, setting those paths manually.