Cmake error using cuda_add_executable command - c++

I am new in cuda programming, I want to build my program and there is a .cu function which is using cuda. I am joind to this project and the project is huge. The *.cpp file of project are added to project using script files.cmake
SUBDIRS(
src/ThirdParty/Matrice
)
set(SRC_CPP_FILES
Operation.cpp
Operator.cpp
ThirdParty/mt97.cpp
Mesh.cpp
...
)
...
and the CmakeList.txt of this project is written :
project(PILOT_plugin)
#set(CMAKE_MODULE_PATH
# ${${MY_PROJECT_NAME}_SOURCE_DIR}/CMake
# ${CMAKE_MODULE_PATH}
# )
MACRO_CREATE_MITK_CTK_PLUGIN(
EXPORT_DIRECTIVE PLANNING_EXPORTS
EXPORTED_INCLUDE_SUFFIXES src
#MODULE_DEPENDS QmitkExt Qmitk
MODULE_DEPENDS MitkQtWidgetsExt MitkQtWidgets MitkMapperExt MitkSceneSerialization
)
# Check the architecture and set CMAKE_LIBRARY_ARCHITECTURE accordingly
#if(UNIX)
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
# endif()
#endif()
function(echo_all_cmake_variable_values)
message(STATUS "")
get_cmake_property(vs VARIABLES)
foreach(v ${vs})
message(STATUS "${v}='${${v}}'")
endforeach(v)
message(STATUS "")
endfunction()
#echo_all_cmake_variable_values()
SET(QT_USE_QTSQL TRUE)
find_package(Boost COMPONENTS serialization filesystem system REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
set(VTK_CMAKE_DIR ${PILOT_SUPERBUILD_BINARY_DIR}/MITK-superbuild/VTK-src/CMake)
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng/Build)
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl)
include_directories(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIR} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/include /usr/include/libxml2 ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl/src)
add_dependencies(${PROJECT_NAME} ompl vtkBioeng)
#find_path(CGOGN_LIB_DIR cgogn ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#message(STATUS ${CGOGN_LIB_DIR})
#link_directories(${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CGOGN_LIB_DIR})
#list(APPEND ALL_LIBRARY_DIRS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
if(EXISTS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a z)
else()
TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng)
endif()
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} cgogn z)
#echo_all_cmake_variable_values()
add_definitions(-DBOOST_NO_CXX11_RVALUE_REFERENCES)
According to my knowledge i should add below command to .cmake file or cmakeLists.txt!
find_package(CUDA REQUIRED)
add_definitions(-D_FORCE_INLINES)
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_21 -std=c++11)
cuda_add_executable(PILOT_plugin
testcuda.cu)
the 'PILOT_plugin' is the name of project and .cu file is my cuda file. but I get '[cmake_check_build_system] Error 1'. in CmakeError.log file I dont understand anything of it.
this is the cmakeError.log
Determining if the Q_WS_WIN exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec2072448143/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec2072448143.dir/build.make CMakeFiles/cmTryCompileExec2072448143.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_WIN’ was not declared in this scope
return ((int*)(&Q_WS_WIN))[argc];
^
CMakeFiles/cmTryCompileExec2072448143.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o] Error 1
Makefile:118: recipe for target 'cmTryCompileExec2072448143/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec2072448143/fast] Error 2
File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef Q_WS_WIN
return ((int*)(&Q_WS_WIN))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the Q_WS_QWS exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec3895328539/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec3895328539.dir/build.make CMakeFiles/cmTryCompileExec3895328539.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_QWS’ was not declared in this scope
return ((int*)(&Q_WS_QWS))[argc];
^
CMakeFiles/cmTryCompileExec3895328539.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3895328539/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec3895328539/fast] Error 2
File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef Q_WS_QWS
return ((int*)(&Q_WS_QWS))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the Q_WS_MAC exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec816771383/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec816771383.dir/build.make CMakeFiles/cmTryCompileExec816771383.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o
/usr/bin/c++ -I/usr/include/qt4 -o CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_MAC’ was not declared in this scope
return ((int*)(&Q_WS_MAC))[argc];
^
CMakeFiles/cmTryCompileExec816771383.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o' failed
make[4]: *** [CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o] Error 1
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec816771383/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec816771383/fast] Error 2
File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef Q_WS_MAC
return ((int*)(&Q_WS_MAC))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec3000733177/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec3000733177.dir/build.make CMakeFiles/cmTryCompileExec3000733177.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all -o CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec3000733177
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3000733177.dir/link.txt --verbose=1
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o -o cmTryCompileExec3000733177 -rdynamic
CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x29): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec3000733177.dir/build.make:88: recipe for target 'cmTryCompileExec3000733177' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [cmTryCompileExec3000733177] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3000733177/fast' failed
make[3]: *** [cmTryCompileExec3000733177/fast] Error 2
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec2524936657/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec2524936657.dir/build.make CMakeFiles/cmTryCompileExec2524936657.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.0/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec2524936657
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec2524936657.dir/link.txt --verbose=1
/usr/bin/cc -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o -o cmTryCompileExec2524936657 -rdynamic -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec2524936657.dir/build.make:88: recipe for target 'cmTryCompileExec2524936657' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [cmTryCompileExec2524936657] Error 1
Makefile:118: recipe for target 'cmTryCompileExec2524936657/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec2524936657/fast] Error 2
Why I cannot add .cu file to the project? the main project use gcc to compile. Is there any other way that i can add .cu file to the main project and compile using nvcc ?
P.S: if I make a simple project and do the same thing as above in CmakeLists.txt is working well, but I dont understand why I cannot add .cu to this huge project
any help is much appreciated

If you're using a recent version of cmake then you shouldn't be using the cuda_add_executable extension and use the built in functionality for supporting CUDA (see https://devblogs.nvidia.com/parallelforall/building-cuda-applications-cmake/).
So what you need to do is modify your cmakelists like this:
project(PILOT_plugin LANGUAGE C CXX CUDA)
The you use the normal add_executable / add_library macros.
However I don't think that this is your issue: I think your install of Qt4 isn't setup properly.

Related

CMake fatal error: CMakeFiles/<path>.dir/main.cpp.d: No such file or directory

I am trying to compile a simple C++ program with CMake on Ubuntu 18.04, but all of my CMake projects fails when I run the make command.
Below is a minimum working example.
The directory structure looks like this:
- project directory
|-build
|-main.cpp
|-CMakeLists.txt
main.cpp
int main(void)
{
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 3.1)
project(Test-Project)
add_executable(a
main.cpp
)
target_compile_options(a
PUBLIC -Wall -o -std=c++11
)
Building
cd build
cmake ../ # this works without any error
make # this fails
Error
[ 50%] Building CXX object CMakeFiles/a.dir/main.cpp.o
cc1plus: fatal error: CMakeFiles/a.dir/main.cpp.d: No such file or directory
compilation terminated.
CMakeFiles/a.dir/build.make:75: recipe for target 'CMakeFiles/a.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/a.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/a.dir/all' failed
make[1]: *** [CMakeFiles/a.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
I get this error when try to compile any CMake based program on the system.
However, if I just used g++ directly to compile the program, it compiles without any complaints.
For example:
g++ ../main.cpp
compiles the program, and runs the program without any errors.
cmake --version: cmake version 3.22.1
g++ --version: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
g++ -print-prog-name=cc1plus: /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus
uname -a: Linux <computer name> 5.4.0-91-generic #102~18.04.1-Ubuntu SMP <date+time> x86_64 x86_64 x86_64 GNU/Linux
EDIT
Terminal output when compiled with make VERBOSE=1:
/home/kani/.local/lib/python2.7/site-packages/cmake/data/bin/cmake -S/home/kani/Documents/test -B/home/kani/Documents/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/home/kani/.local/lib/python2.7/site-packages/cmake/data/bin/cmake -E cmake_progress_start /home/kani/Documents/test/build/CMakeFiles /home/kani/Documents/test/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/kani/Documents/test/build'
make -f CMakeFiles/a.dir/build.make CMakeFiles/a.dir/depend
make[2]: Entering directory '/home/kani/Documents/test/build'
cd /home/kani/Documents/test/build && /home/kani/.local/lib/python2.7/site-packages/cmake/data/bin/cmake -E cmake_depends "Unix Makefiles" /home/kani/Documents/test /home/kani/Documents/test /home/kani/Documents/test/build /home/kani/Documents/test/build /home/kani/Documents/test/build/CMakeFiles/a.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/kani/Documents/test/build'
make -f CMakeFiles/a.dir/build.make CMakeFiles/a.dir/build
make[2]: Entering directory '/home/kani/Documents/test/build'
[ 50%] Building CXX object CMakeFiles/a.dir/main.cpp.o
/usr/bin/c++ -Wall -o -std=c++11 -MD -MT CMakeFiles/a.dir/main.cpp.o -MF CMakeFiles/a.dir/main.cpp.o.d -o CMakeFiles/a.dir/main.cpp.o -c /home/kani/Documents/test/main.cpp
cc1plus: fatal error: CMakeFiles/a.dir/main.cpp.d: No such file or directory
compilation terminated.
CMakeFiles/a.dir/build.make:75: recipe for target 'CMakeFiles/a.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/a.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/home/kani/Documents/test/build'
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/a.dir/all' failed
make[1]: *** [CMakeFiles/a.dir/all] Error 2
make[1]: Leaving directory '/home/kani/Documents/test/build'
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
Despite the error message about absent .d file seems to be internal to CMake (such files are used for collect header dependencies generated by the compiler), its usual reason is specifying some output-controlling compiler options in the CMakeLists.txt.
In your case it is -o option which damages the command line generated by CMake. CMake by itself uses this option for specify object file which will be created as a result of the compilation. So adding another -o is wrong.

CMake wont link my library, make file does

Background
I recently downloaded a lib called "RayLib" for c and c++. I added the mingw includes and libs into my project and well, now i wanna link them.
The problem
For some reason, cmake does not link the static lib. When i try to run the project, it tells me that there still undefined references to "InitWindow" and "SetTargetFPS" :
====================[ Build | Engine | Debug ]==================================
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe --build C:\Users\Lars\CLionProjects\Engine\cmake-build-debug --target Engine -- -j 9
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -SC:\Users\Lars\CLionProjects\Engine -BC:\Users\Lars\CLionProjects\Engine\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
C:/Users/Lars/Desktop/Development/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 Engine
mingw32-make.exe[1]: Entering directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -SC:\Users\Lars\CLionProjects\Engine -BC:\Users\Lars\CLionProjects\Engine\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -E cmake_progress_start C:\Users\Lars\CLionProjects\Engine\cmake-build-debug\CMakeFiles 2
C:/Users/Lars/Desktop/Development/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/Engine.dir/all
mingw32-make.exe[2]: Entering directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
C:/Users/Lars/Desktop/Development/MinGW/bin/mingw32-make.exe -f CMakeFiles\Engine.dir\build.make CMakeFiles/Engine.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -E cmake_depends "MinGW Makefiles" C:\Users\Lars\CLionProjects\Engine C:\Users\Lars\CLionProjects\Engine C:\Users\Lars\CLionProjects\Engine\cmake-build-debug C:\Users\Lars\CLionProjects\Engine\cmake-build-debug C:\Users\Lars\CLionProjects\Engine\cmake-build-debug\CMakeFiles\Engine.dir\DependInfo.cmake --color=
mingw32-make.exe[3]: Leaving directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
C:/Users/Lars/Desktop/Development/MinGW/bin/mingw32-make.exe -f CMakeFiles\Engine.dir\build.make CMakeFiles/Engine.dir/build
mingw32-make.exe[3]: Entering directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
[ 50%] Linking CXX executable Engine.exe
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -E cmake_link_script CMakeFiles\Engine.dir\link.txt --verbose=1
C:\Users\Lars\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\203.7148.70\bin\cmake\win\bin\cmake.exe -E rm -f CMakeFiles\Engine.dir/objects.a
C:\Users\Lars\Desktop\Development\MinGW\bin\ar.exe cr CMakeFiles\Engine.dir/objects.a #CMakeFiles\Engine.dir\objects1.rsp
C:\Users\Lars\Desktop\Development\MinGW\bin\g++.exe -Wall -std=c++17 -g -Wl,--whole-archive CMakeFiles\Engine.dir/objects.a -Wl,--no-whole-archive -o Engine.exe -Wl,--out-implib,libEngine.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\Engine.dir\linklibs.rsp
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\Engine.dir/objects.a(main.cpp.obj): in function `main':
C:/Users/Lars/CLionProjects/Engine/main.cpp:22: undefined reference to `InitWindow'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:24: undefined reference to `SetTargetFPS'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:28: undefined reference to `WindowShouldClose'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:37: undefined reference to `BeginDrawing'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:39: undefined reference to `ClearBackground'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:41: undefined reference to `DrawText'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:43: undefined reference to `EndDrawing'
c:/users/lars/desktop/development/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Lars/CLionProjects/Engine/main.cpp:49: undefined reference to `CloseWindow'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Engine.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Engine.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Engine.dir/rule] Error 2
mingw32-make.exe: *** [Engine] Error 2
CMakeFiles\Engine.dir\build.make:108: recipe for target 'Engine.exe' failed
mingw32-make.exe[3]: Leaving directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
CMakeFiles\Makefile2:97: recipe for target 'CMakeFiles/Engine.dir/all' failed
mingw32-make.exe[2]: Leaving directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
CMakeFiles\Makefile2:104: recipe for target 'CMakeFiles/Engine.dir/rule' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/Lars/CLionProjects/Engine/cmake-build-debug'
Makefile:140: recipe for target 'Engine' failed
My cmake file looks like this...
cmake_minimum_required(VERSION 3.17)
project(Engine)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(include)
include_directories(libs)
link_directories(libs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
add_executable(Engine main.cpp)
target_link_libraries(Engine raylib)
My own written make file, located in the root which simply adds a -I include, -L libs and -lraylib is able to compile this project.
main: main.o
g++ -I include ... -o main main.o -L libs -lraylib
main.o: main.cpp
g++ -I include ... -c main.cpp -L libs -lraylib
Question
Why exactly does target_link_libraries not work ? Why doesnt it link my .a file located in libs/ ? What am i doing wrong here ? Why isnt Cmake able to link my project, but my own makefile is able to do it ?
Any help is welcome !
From the documentation about the command link_directories():
This command is rarely necessary and should be avoided where there are other choices. Prefer to pass full absolute paths to libraries where possible, since this ensures the correct library will always be linked. The find_library() command provides the full path, which can generally be used directly in calls to target_link_libraries().
find_library() is hopefully sufficient by itself.

CMake + freeglut3: cannot find usbhid.h

System: I am using Linux Mint 17.3 as VB-Guest on a Max OS 10.11.3 system.
Problem: Id like to compile freeglut3.0.0
Issue: cmake gives me an fatal error: usbhid.h: No such file or directory
Hello,
The problem is, that even after installing all dependencies I cannot find this file on my system. After researching I found out that it has something to do with some usb-drivers. Could it be that it has something to do with The VB-System with no "actual" usb-hardware?
or is there a package that I am missing.
I installed libgl1-mesa-dev, libx11-dev, libxrandr-dev and libxi-dev
Here I attached the CMakeError.log
Determining if files usbhid.h exist failed with the following output:
Change Dir: /opt/freeglut-3.0.0/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec2451224769/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec2451224769.dir/build.make CMakeFiles/cmTryCompileExec2451224769.dir/build
make[1]: Entering directory `/opt/freeglut-3.0.0/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /opt/freeglut-3.0.0/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2451224769.dir/CheckIncludeFiles.c.o
/usr/bin/cc -Wall -pedantic -o CMakeFiles/cmTryCompileExec2451224769.dir/CheckIncludeFiles.c.o -c /opt/freeglut-3.0.0/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/opt/freeglut-3.0.0/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:2:20: fatal error: usbhid.h: No such file or directory
#include <usbhid.h>
^
compilation terminated.
make[1]: Leaving directory `/opt/freeglut-3.0.0/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec2451224769.dir/CheckIncludeFiles.c.o] Error 1
make: *** [cmTryCompileExec2451224769/fast] Error 2
Source:
/* */
#include <usbhid.h>
int main(){return 0;}
Determining if the function XParseGeometry exists failed with the following output:
Change Dir: /opt/freeglut-3.0.0/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec2875944840/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec2875944840.dir/build.make CMakeFiles/cmTryCompileExec2875944840.dir/build
make[1]: Entering directory `/opt/freeglut-3.0.0/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /opt/freeglut-3.0.0/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2875944840.dir/CheckFunctionExists.c.o
/usr/bin/cc -Wall -pedantic -DCHECK_FUNCTION_EXISTS=XParseGeometry -o CMakeFiles/cmTryCompileExec2875944840.dir/CheckFunctionExists.c.o -c /usr/share/cmake-2.8/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec2875944840
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec2875944840.dir/link.txt --verbose=1
/usr/bin/cc -Wall -pedantic -DCHECK_FUNCTION_EXISTS=XParseGeometry CMakeFiles/cmTryCompileExec2875944840.dir/CheckFunctionExists.c.o -o cmTryCompileExec2875944840 -rdynamic -lm
CMakeFiles/cmTryCompileExec2875944840.dir/CheckFunctionExists.c.o: In function `main':
CheckFunctionExists.c:(.text+0x15): undefined reference to `XParseGeometry'
collect2: error: ld returned 1 exit status
make[1]: Leaving directory `/opt/freeglut-3.0.0/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec2875944840] Error 1
make: *** [cmTryCompileExec2875944840/fast] Error 2
I don't know how to find a solution for myself so i ask it here.
Thanks in advance
usbhid.h : Please install ``libusbhid-dev´´ : $ sudo apt-get install libusbhid-dev

CMake fails compilation

I am trying to compile cocos2d-x 3.5 on openSUSE 13.2 and i get the following error in .log file:
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTryCompileExec846787943/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec846787943.dir/build.make CMakeFiles/cmTryCompileExec846787943.dir/build
gmake[1]: Entering directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o
/usr/bin/cc -fno-exceptions -std=c99 -o CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o -c /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec846787943
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec846787943.dir/link.txt --verbose=1
/usr/bin/cc -fno-exceptions -std=c99 CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o -o cmTryCompileExec846787943 -rdynamic
CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec846787943.dir/build.make:88: recipe for target 'cmTryCompileExec846787943' failed
gmake[1]: *** [cmTryCompileExec846787943] Error 1
gmake[1]: Leaving directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec846787943/fast' failed
gmake: *** [cmTryCompileExec846787943/fast] Error 2
File /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTryCompileExec3838281423/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec3838281423.dir/build.make CMakeFiles/cmTryCompileExec3838281423.dir/build
gmake[1]: Entering directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o
/usr/bin/cc -fno-exceptions -std=c99 -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec3838281423
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3838281423.dir/link.txt --verbose=1
/usr/bin/cc -fno-exceptions -std=c99 -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o -o cmTryCompileExec3838281423 -rdynamic -lpthreads
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec3838281423.dir/build.make:88: recipe for target 'cmTryCompileExec3838281423' failed
gmake[1]: *** [cmTryCompileExec3838281423] Error 1
gmake[1]: Leaving directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec3838281423/fast' failed
gmake: *** [cmTryCompileExec3838281423/fast] Error 2
I installed the dependencies and libraries manually, but I still get this error. Does anyone know whats going on?
Note: when i try to compile, the first 2 lines are:
~/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build> cmake ../..
CMake Error at CMakeLists.txt:35 (cmake_policy):
Policy "CMP0054" is not known to this version of CMake.
Thanks :D
Solved, I just did comment this lines out in the CMakeList.txt file
#if(CMAKE_VERSION VERSION_GREATER 3)
#cmake_policy(SET CMP0054 NEW)
#endif()
but now, when I use make command (No matter where, using NetBeans or terminal) it ends with this error at 98% (after about 15mins compiling)
[ 98%] Built target cocos2d
[ 98%] Built target MyGame_CORE_PRE_BUILD
MyGame_PRE_BUILD ...
[ 98%] Built target MyGame_PRE_BUILD
Linking CXX executable bin/MyGame
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: lib/libcocos2d.a(CCSpriteFrameCache.cpp.o): undefined reference to symbol '_ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_##GLIBCXX_3.4'
/usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/MyGame.dir/build.make:164: recipe for target 'bin/MyGame' failed
make[2]: *** [bin/MyGame] Error 1
CMakeFiles/Makefile2:64: recipe for target 'CMakeFiles/MyGame.dir/all' failed
make[1]: *** [CMakeFiles/MyGame.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
Any idea??
Solved, If anyone has the same problem, just use cmake with the argument -pthread and then you will be able to build using make. If you wanna build using NetBeans, u have to leave only the -G "Unix..." argument and add in the CMakefile.txt the line: set(-pthread) --I did add it at the top-- and thats all, it should be everything ok :D cheers!
This appears to be a long-standing CMake bug. Something else is going wrong, CMake gets confused, and reports this spurious problem instead of the real error.
Look for "thread" in your CMakeLists.txt file and temporarily remove that.

Using cmake with share libraries

So I'm trying to get an example poco program running running with cmake. From here.
#include <Poco/String.h>
using Poco::trim;
using Poco::trimLeft;
using Poco::trimRight;
using Poco::trimRightInPlace;
#include <iostream>
int main(int argc, char** argv)
{
std::string hello(" This is a silly string. ");
std::cout << hello << std::endl;
std::string s1(trimLeft(hello));
trimRightInPlace(s1);
std::string s2(trim(hello));
std::cout << s2 << std::endl;
return 0;
}
I can compile and run the code from this command.
g++ -o silly silly.cpp -L/usr/local/lib -lPocoFoundation -I/usr/local/include/poco
But when I try to use cmake with a file like this.
cmake_minimum_required (VERSION 2.6)
project (Silly)
ADD_DEFINITIONS(
-std=c++11
)
# the version number
set (Silly_VERSION_MAJOR 0)
set (Silly_VERSION_MINOR 1)
include_directories (${PROJECT_BINARY_DIR})
include_directories ("/usr/local/include/poco")
include_directories ("/usr/local/lib")
# add the libs
set (EXTRA_LIBS ${EXTRA_LIBS} PocoFoundation)
# add the executable
add_executable (Silly silly.cpp)
target_link_libraries (Silly ${EXTRA_LIBS})
I get this error.
CMakeFiles/Silly.dir/silly.cpp.o: In function `Poco::Ascii::properties(int)':
silly.cpp:(.text._ZN4Poco5Ascii10propertiesEi[_ZN4Poco5Ascii10propertiesEi]+0x21): undefined reference to `Poco::Ascii::CHARACTER_PROPERTIES'
collect2: error: ld returned 1 exit status
make[2]: *** [Silly] Error 1
make[1]: *** [CMakeFiles/Silly.dir/all] Error 2
make: *** [all] Error 2
Here's my verbose output
/usr/bin/c++ -I/home/matt/projects/billy/build -I/usr/local/include/poco -I/usr/local/lib -std=c++11 -o CMakeFiles/Silly.dir/silly.cpp.o -c /home/matt/projects/billy/src/silly.cpp
Linking CXX executable Silly
/usr/bin/cmake -E cmake_link_script CMakeFiles/Silly.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/Silly.dir/silly.cpp.o -o Silly -rdynamic -lPocoFoundation
CMakeFiles/Silly.dir/silly.cpp.o: In function `Poco::Ascii::properties(int)':
silly.cpp:(.text._ZN4Poco5Ascii10propertiesEi[_ZN4Poco5Ascii10propertiesEi]+0x21): undefined reference to `Poco::Ascii::CHARACTER_PROPERTIES'
collect2: error: ld returned 1 exit status
make[2]: *** [Silly] Error 1
make[2]: Leaving directory `/home/matt/projects/billy/build'
make[1]: *** [CMakeFiles/Silly.dir/all] Error 2
make[1]: Leaving directory `/home/matt/projects/billy/build'
make: *** [all] Error 2