Using cmake with share libraries - c++

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

Related

main': CheckSymbolExists.c:(.text+0x1b): undefined reference to pthread_create

I am building Faunus software using cmake with command -->
$cmake . -DENABLE_OPENMP=ON -DENABLE_PYTHON=ON -DCMAKE_INSTALL_PREFIX:PATH=/home/user/localInstall/tstFaunusInstOpenMP -DPYTHON_EXECUTABLE=/home/user/anaconda3/envs/faunus-env/bin/python3.6 -DPYTHON_INCLUDE_DIR=/home/user/anaconda3/envs/faunus-env/include/python3.6m -DPYTHON_LIBRARY=/home/user/anaconda3/envs/faunus-env/lib -DCMAKE_CXX_FLAGS_DEBUG="-pthread"
I am getting build error like :
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/user/softwares/openMPfaunus-2.4.1/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_a43c8/fast"
/usr/bin/make -f CMakeFiles/cmTC_a43c8.dir/build.make CMakeFiles/cmTC_a43c8.dir/build
make[1]: Entering directory '/home/user/softwares/openMPfaunus-2.4.1/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a43c8.dir/CheckSymbolExists.c.o
/usr/bin/cc -o CMakeFiles/cmTC_a43c8.dir/CheckSymbolExists.c.o -c /home/user/softwares/openMPfaunus-2.4.1/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_a43c8
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a43c8.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_a43c8.dir/CheckSymbolExists.c.o -o cmTC_a43c8
/usr/bin/ld: CMakeFiles/cmTC_a43c8.dir/CheckSymbolExists.c.o: in function `main':
CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_a43c8.dir/build.make:87: cmTC_a43c8] Error 1
make[1]: Leaving directory '/home/user/softwares/openMPfaunus-2.4.1/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_a43c8/fast] Error 2
File /home/user/softwares/openMPfaunus-2.4.1/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
}
##############################################################
What I could understand from this is that there is section of file "CheckSymbolExists.c", which requires pthread_create. I wrote a simple code in C and ran using option: gcc example.c -lm -pthread and it's is working fine but if I run without -pthread option I am getting the same error concerning pthread_create.
Can someone help out this.

cmake returning error of "undefined reference to pthread_create"

I am trying to build webrtc project: https://github.com/mpromonet/webrtc-streamer?fbclid=IwAR2HBwWIZvRhSlmKBllQj2knaBPn6oeEvS24STPLTZHbky2Ta5sbcoPCoc8
when I run cmake . I got the following error:
WEBRTCBUILD = Release
WEBRTCROOT = /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/../webrtc
WEBRTCDESKTOPCAPTURE= ON
CMAKE_CXX_COMPILER_ID=GNU
ALSA_FOUND = FALSE
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:
WEBRTC_LIBRARY
linked by target "webrtc-streamer" in directory /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer
-- Configuring incomplete, errors occurred!
See also "/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeOutput.log".
See also "/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeError.log".
And hereafter the content of "CMakeError.log"
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_13271/fast"
/usr/bin/make -f CMakeFiles/cmTC_13271.dir/build.make CMakeFiles/cmTC_13271.dir/build
make[1]: Entering directory '/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o
/usr/bin/cc -fPIE -o CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o -c /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_13271
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_13271.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o -o cmTC_13271 -rdynamic
CMakeFiles/cmTC_13271.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_13271.dir/build.make:97: recipe for target 'cmTC_13271' failed
make[1]: *** [cmTC_13271] Error 1
make[1]: Leaving directory '/home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_13271/fast' failed
make: *** [cmTC_13271/fast] Error 2
File /home/mohamed/Desktop/upwork/SoftwareExperts/test3/webrtc-streamer/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
}
Here after the CMakeLists.txt: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
the pthread library is installed on my ubuntu PC because compiling a test file "test.c" with -lpthread is working without problem
What I am missing ?
You need to have 'pthread' added into 'target_link_libraries' section in your CMakeLists.txt.
[edit]
As suggested by #arrowd, the proper way is to use the 'FindThreads':
https://cmake.org/cmake/help/latest/module/FindThreads.html

Compile CUDA code with cmake and 3.5 compute capability

I need to compile a CUDA code that use a dynamic parallelism with cmake.
The code is:
#include <stdio.h>
__global__ void childKernel() {
printf("Hello ");
}
__global__ void parentKernel() {
childKernel<<<1,1>>>();
cudaDeviceSynchronize();
printf("World!\n");
}
int main(int argc, char **argv){
parentKernel<<<1, 1>>>();
return 0;
}
and the cmake is the following:
cmake_minimum_required(VERSION 2.8)
find_package(CUDA QUIET REQUIRED)
include_directories(/usr/include)
include_directories(/usr/local/cuda/lib)
include_directories(/usr/local/cuda-8.0/lib)
include_directories(/usr/local/cuda/include)
include_directories(/usr/local/cuda-8.0/include)
set(CUDA_SEPARABLE_COMPILATION ON)
find_package(CUDA QUIET REQUIRED)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-arch=compute_35 -rdc=true -lcudadevrt
)
cuda_add_executable(
prova
test.cu
)
I have tried to compile the code directly with nvcc passing the -arch=compute_35 -rdc=true -lcudadevrt and it compiles perfectly, but when
I try to compile with cmake it returns me the following error:
CMakeFiles/prova.dir/prova_intermediate_link.o: In function `__cudaRegisterLinkedBinary_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37':
link.stub:(.text+0xcc): undefined reference to `__fatbinwrap_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37'
link.stub:(.text+0xd0): undefined reference to `__fatbinwrap_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37'
collect2: error: ld returned 1 exit status
CMakeFiles/prova.dir/build.make:200: recipe for target 'prova' failed
make[2]: *** [prova] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/prova.dir/all' failed
make[1]: *** [CMakeFiles/prova.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The undefined symbols you're seeing are defined in libcudadevrt.a. I see that you're telling CMake to link to it, but it appears the compiler can't find it. Try this on the command line:
VERBOSE=1 make
and inspect the output to see if you're searching /usr/local/cuda/lib64 for libraries.
This may be unrelated, but I also notice that you're instructing CMake to search /usr/local/cuda/lib and /usr/local/cuda-8.0/lib for header files. This is incorrect, as these directories contain only libraries.
Thanks for the answer, I have tried to use the correct compute capability of the Tegra X2 (compute_62), and I have inspected the output of verbose make and I found the following output:
CMakeFiles/prova.dir/prova_generated_test.cu.o CMakeFiles/prova.dir/prova_intermediate_link.o -o prova -rdynamic /usr/local/cuda-8.0/lib64/libcudart_static.a -lpthread -ldl -lrt
It seems that the linker try to search /usr/local/cuda-8.0/lib64/libcudart_static.a but not libcudadevrt.a

Cmake error using cuda_add_executable command

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.

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.