I have installed Intel opencl sdk for windows and opencl variable are added to the environment variables. I want to use this sdk with my Clion ide which I am unable to include it in my current project since it was CL/cl.hpp not found. How can add it to my project in Clion?
Cl/cl.hpp is located atC:\Program Files(x86)\IntelSWTools\OpenCL\sdk\include\CL
following is my CMakeLists.txt
project(tpch_framework)
# enable c++11
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE "Release")
find_package(OpenMP REQUIRED)
find_package(OpenCL REQUIRED)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# Configure required Boost libraries
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
"Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
"Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
"Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED filesystem system)
# ensure that dependant libraries not explicitly specified here
# are found by the linker:
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
#Bring the headers into the project
include_directories(include)
FILE(GLOB_RECURSE INC_ALL "include/*.hpp")
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")
add_library(tpch_framework ${SOURCES})
add_executable(framework main.cpp ${INC_ALL})
target_link_libraries(framework tpch_framework)
#target_link_libraries(framework stdc++fs)
target_link_libraries(framework ${LIBS})
You need to provide information about include directory for OpenCL headers like you provided for Boost headers. Also, you need to link OpenCL libraries with your target.
In your CMakeLists...
For include and link directories:
link_directories(${Boost_LIBRARY_DIRS} ${OpenCL_LIBRARY})
include_directories(${Boost_INCLUDE_DIRS} ${OpenCL_INCLUDE_DIRS})
For linking libraries:
set(LIBS ${LIBS} ${Boost_LIBRARIES} ${OpenCL_LIBRARY})
Related
I am modifying a C++ application to demonstrate ambient occlusion based on OpenGL, GLFW and GLAD libraries. I would like to use AntTweakBar library as well, but I don't know how to modify cMakeLists.txt to properly import it. I have tried a lot of different versions to import this library, which is in the root of the project anyway.
Below you can see my cmakelists.txt.
cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8)
project(LearnOpenGL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
link_directories(${CMAKE_SOURCE_DIR}/lib)
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# find the required packages
find_package(GLM REQUIRED)
message(STATUS "GLM included at ${GLM_INCLUDE_DIR}")
find_package(GLFW3 REQUIRED)
message(STATUS "Found GLFW3 in ${GLFW3_INCLUDE_DIR}")
find_package(ASSIMP REQUIRED)
message(STATUS "Found ASSIMP in ${ASSIMP_INCLUDE_DIR}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
find_package(OpenGL REQUIRED)
add_definitions(${OPENGL_DEFINITIONS})
find_package(X11 REQUIRED)
# note that the order is important for setting the libs
# use pkg-config --libs $(pkg-config --print-requires --print-requires-private glfw3) in a terminal to confirm
set(LIBS ${GLFW3_LIBRARY} X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL dl pthread ${ASSIMP_LIBRARY})
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
configure_file(configuration/root_directory.h.in configuration/root_directory.h)
include_directories(${CMAKE_BINARY_DIR}/configuration)
# first create relevant static libraries requried for other projects
add_library(GLAD "src/glad.c")
set(LIBS ${LIBS} GLAD)
FIND_PATH(ANT_TWEAK_BAR_INCLUDE_PATH AntTweakBar.h
PATHS
${CMAKE_BINARY_DIR}/AntTweakBar/include)
FIND_LIBRARY( ANT_TWEAK_BAR_LIBRARY AntTweakBar
PATHS
${CMAKE_BINARY_DIR}/AntTweakBar/lib
)
#reate a project file
file(GLOB SOURCE
"src/*.h"
"src/*.cpp"
"src/*.vs"
"src/*.fs"
"src/*.gs"
)
set(NAME "SSAO")
add_executable(${NAME} ${SOURCE})
target_link_libraries(${NAME} ${LIBS} ${ANT_TWEAK_BAR_LIBRARY})
set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin/")
include_directories(${CMAKE_SOURCE_DIR}/includes)
include_directories(${ANT_TWEAK_BAR_INCLUDE_PATH})
This is an example how i import static googletest libraries 'libgtest.a' and 'libgmock.a' to a project using cmake as build configuration generator.
For shared libraries you need to replace STATIC by SHARED in add_library.
cmake_minimum_required(VERSION 2.8)
project(gtest_sample1)
include_directories(../googletest/include)
include_directories(../googlemock/include)
add_library(gtest STATIC IMPORTED)
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION /home/mschmid/projects/googletest-master/gtest/libgtest.a)
add_library(gmock STATIC IMPORTED)
set_property(TARGET gmock PROPERTY IMPORTED_LOCATION /home/mschmid/projects/googletest-master/gmock/libgmock.a)
add_executable(gtest_sample1 main.cpp)
target_link_libraries(gtest_sample1 gtest gmock pthread)
For the past few days I've been searching everywhere and can't seem to fix this problem or maybe I just didn't understand some answers.
I have an application (a game to be precise) built with SFML that I managed to compile on Linux with 2.4.2 version. I want to migrate to 2.5.1 and be able to compile on Windows so I changed the CMakeLists.txt file to this:
cmake_minimum_required(VERSION 3.0)
# There is no real need for C++17 or 14, but I like to use up-to-date versions
if(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
if (WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/)
endif(WIN32)
# Includes
include_directories(include)
# Source files
set(SOURCE_FILES
source/main.cpp
source/Game.cpp
)
# Assets
set(ASSETS
assets/Fonts/xolonium.ttf
)
# Debug Mode
project(HexDebug VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE DEBUG) # This is ignored by MSVC
#SFML Package
find_package(SFML 2.5 CONFIG COMPONENTS system window graphics network audio REQUIRED)
if(SFML_FOUND)
set(SFML_STATIC_LIBRARIES TRUE)
if(WIN32)
set(SFML_USE_STATIC_STD_LIBS TRUE)
endif(WIN32)
endif(SFML_FOUND)
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Debug/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE -g -Wall -O0 -D_DEBUG)
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
#Release Mode
project(Hex VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE RELEASE) # This is ignored by MSVC
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Release/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE "-O3")
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
The cmake works and generates the VS solution, that I can build with msbuild (note that I don't want to launch Visual Studio, but only use msbuild). But once I try to run it, it asks for dlls and I don't want that.
I thought that would be solved by linking statically (I don't know much about static or dynamic linking) but it still asks for them.
In this link they say that we don't need to include the ${SFML_INCLUDE_DIR} and ${SFML_LIBRARIES} anymore: https://en.sfml-dev.org/forums/index.php?topic=24070.0
How can I avoid that? I want to be completely independant from DLL's or at least be able to include the bin directory installed from SFML compiled and installed binaries (that I compiled, not the precompiled).
Thank you.
I have C++ project which compiles using cmake.
I'm trying to link library using relative path and not absolute path. The code compiles fine, but has problem while linking the libraries.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(GMW)
cmake_policy(SET CMP0015 NEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -maes -mpclmul -fPIC")
SET (BOOST_ROOT $ENV{HOME}/boost_1_60_0/)
SET (BOOST_INCLUDEDIR $ENV{HOME}/boost_1_60_0/)
SET (BOOST_LIBRARYDIR $ENV{HOME}/boost_1_60_0/stage/lib)
find_package(Boost COMPONENTS system thread REQUIRED)
INCLUDE_DIRECTORIES($ENV{HOME} ${BOOST_INCLUDEDIR}
../../lib/OTExtensionBristol ../../lib/)
link_directories(/usr/ssl/lib/ ../../install/lib ${BOOST_LIBRARYDIR})
set(SOURCE_FILES main.cpp GMWParty.h Circuit.cpp Circuit.h MPCCommunication.cpp MPCCommunication.h GMWParty.cpp)
add_executable(GMW ${SOURCE_FILES})
add_library(gmw ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(GMW ../../scapi.a gmp
OTExtensionBristol
../../install/lib/libsimpleot.a
boost_system boost_thread pthread crypto dl ssl z)
cmake_policy(SET CMP0015 NEW) Solved the problem for link directories.
How do I solve it for link libraries?
I am new to C++ and have just started to use Cmake for linking the libraries to my project. I need to use a library:
https://github.com/Gnimuc/FastPD
Fortunately, I managed to build the library using Cmake (in my build there is no *.lib file at all), but I don't know how to link it to my project. I mean that I don't know how to add it to my cmakelists.txt :
(PS. I'm also using two other libraries ITK and VTK; but I can't link the above mentioned library to my project or main.cpp.)
################################################
cmake_minimum_required(VERSION 2.8)
project(My_project)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
add_executable(My_project MACOSX_BUNDLE main.cpp)
target_link_libraries(My_project
${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
################################################
Thanks in advance for your helps,
Assuming you installed the library and its header files, you can then search for the header files using find_path, and add the found path to the include directories. Then you can search for the library by using find_library, and add the library with the target_link_libraries command.
I tried both shared and static types for creation of the library. In the case of shared, no *.lib file was created, and in the case of static, my project couldn't link to the library. Therefore, in my project's CmakeLists.txt, I decided to add all the *.cpp and headers as libraries and then link them together (as I didn't know the dependency among them!!!), and finally, I linked them to my project. Perhaps it does not make sense but it works; hope it helps you:
CmakeLists.txt
##############################################
cmake_minimum_required(VERSION 2.6)
set(PROJ_NAME PROJECT46)
PROJECT(${PROJ_NAME})
# Prevent compilation in-source
if( ${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
Message( " " )
Message( FATAL_ERROR "Source and build directories are the same.
Create an empty build directory,
change into it and re-invoke cmake")
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.
Please use a different C++ compiler.")
endif()
##############################################
## External libraries
##############################################
list( APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)
# Blitz
find_package( Blitz++ REQUIRED )
list( APPEND PROJ_INCLUDE_DIRS
${Blitz++_INCLUDE_DIR}
)
list( APPEND
PROJ_LIB
${Blitz++_LIBRARIES}
)
# ITK and VTK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
##############################################
# FASTPD
add_library(FASTPD Fast_PD.cpp Fast_PD.h common.h block.h)
add_library(GRAPH graph.h graph.cpp)
add_library(linked LinkedBlockList.h LinkedBlockList.cpp)
add_library(MAXFLOW maxflow.cpp)
include_directories(${PROJ_INCLUDE_DIRS})
add_executable(${PROJ_NAME} main.cpp)
target_link_libraries(linked MAXFLOW)
target_link_libraries(GRAPH linked)
target_link_libraries(FASTPD GRAPH)
target_link_libraries(${PROJ_NAME} FASTPD)
target_link_libraries(${PROJ_NAME}
${PROJ_LIB} ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES}
)
I am porting a C++ project I have been working on for 2 years, to Windows, and I am facing this link issue, that I haven't seen on any google-referenced posts... :/
It is a CMake-generated project, and I get these CMake entries set by default to "\machine:x64"
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS
I tried removing the flag, which has no effect on any of the 3 last entries, but CMAKE_EXE_LINKER_FLAGS without this value gives me about 85 unresolved externals spread in my libraries.
ALL my projects / project dependencies are compiled with MSVC2015 in x64.
Linking fails both in debug & release mode (not that it matters..)
I should also probably mention that I have 6 projects in this solution, 4 libraries, 2 executables. 4 of these projects are compiling fine (1 executable & 4 libs), only the 2 last ones are failing (with the same link error for both).
The only difference in terms of dependencies are a dependency to the Point Cloud Library (pcl), and to Qt5 (Core GUI, XML, and OpenGL)
Did anyone already encountered this specific linker error?
Hope you can help =)
EDIT: Here are the 2 main CMakelists files (the one at the root of the project and the one that compiles both failing projects). I removed everything that didn't seem pertinent for this issue.
Root CMakeLists.txt:
project(SofaOR)
cmake_minimum_required(VERSION 2.4)
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR})
#Reading local file for the non automatically detected dependencies
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake")
message("Adding custom file")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake)
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(SOFA_ALL_LIBS SofaHelper SofaDefaultType)
set(SOFA_INCLUDE_DIRS ${SOFA_DIR}/include)
set(SOFA_LIBRARY_DIRS ${SOFA_DIR}/lib)
add_subdirectory(${CMAKE_SOURCE_DIR}/processOR)
the CMakelists included by the last add_subdirectory:
project(processOR)
cmake_minimum_required(VERSION 3.0.2)
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(PROCESSOR_EXEC_NAME processOR)
set(PROCESSOR_LIB_NAME processOR_lib)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(OpenCV COMPONENTS core imgproc xfeatures2d calib3d REQUIRED )
find_package(Qt5 COMPONENTS Core Gui Xml OpenGL REQUIRED )
find_package(PCL COMPONENTS common io kdtree REQUIRED )
find_package(Boost COMPONENTS program_options chrono thread REQUIRED)
find_package(OpenIGTLink REQUIRED )
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(PROCESSOR_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/src/ PARENT_SCOPE)
set(PROCESSOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/)
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${COMMON_INCLUDE_DIRS})
include_directories(${OpenIGTLink_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${QGLVIEWER_DIR})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${SOFA_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
link_directories(${COMMON_LIBRARY_DIRS})
link_directories(${OpenIGTLink_LIBRARY_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})
link_directories(${QGLVIEWER_DIR})
link_directories(${SOFA_LIBRARY_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${PROCESSOR_SRC})
set(PROCESSOR_ALL_LIBS
${PCL_LIBRARIES}
${COMMON_LIBRARIES}
OpenIGTLink
${OpenCV_LIBS}
QGLViewer
${Boost_LIBRARIES}
${SOFA_ALL_LIBS}
)
set (HEADER_FILES
${PROCESSOR_SRC}/util/Calibration.h
${PROCESSOR_SRC}/fetchers/VideoFetcher.h
[…]
${PROCESSOR_SRC}/filters/PointCloudTriangulator.h
${PROCESSOR_SRC}/filters/PointCloudSmootherMLS.h
${PROCESSOR_SRC}/filters/PointCloudSegmenter.h
${PROCESSOR_SRC}/filters/PointCloudDownSampler.h
)
set (SOURCE_FILES
${PROCESSOR_SRC}/Registrator.cpp
${PROCESSOR_SRC}/tinyxml2.cpp
[…]
${PROCESSOR_SRC}/filters/PointCloudSegmenter.cpp
${PROCESSOR_SRC}/filters/PointCloudDownSampler.cpp
)
# Library
add_library(${PROCESSOR_LIB_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROCESSOR_LIB_NAME} ${PROCESSOR_ALL_LIBS} ${CMAKE_EXE_LINKER_FLAGS} ${ADDITIONAL_LIBRARIES})
QT5_USE_MODULES(${PROCESSOR_LIB_NAME} Widgets Gui OpenGL Xml)
set(PROCESSOR_LIB ${PROCESSOR_LIB_NAME} PARENT_SCOPE)
# Main executable
set (SOURCE_FILES
${PROCESSOR_SRC}/mainRegistration.cpp
)
add_executable(${PROCESSOR_EXEC_NAME} ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROCESSOR_EXEC_NAME} ${PROCESSOR_LIB} ${Boost_LIBRARIES} ${PROCESSOR_LIB_NAME} ${CMAKE_EXE_LINKER_FLAGS})
QT5_USE_MODULES(${PROCESSOR_EXEC_NAME} Widgets Gui OpenGL Xml)
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)