System include directory is not added by CMake 3.16.5 - c++

I have observed the below detailed behaviour when compiling a C++ program with 2 different CMake versions:
3.10.2 (installed from default APT repository for Ubuntu 18.04); and
3.16.5 (installed together with CLion).
In the project the /usr/local/include folder is added to the include path (as a system include directory if it matters), through the ODB package:
include_directories(SYSTEM ${ODB_INCLUDE_DIRS})
Where ${ODB_INCLUDE_DIRS} is /usr/local/include for me.
When I use the CMake version 3.10.2 (from APT repository), the /usr/local/include directory is added to the include path correctly.
When I use the CMake version 3.16.5 (installed with CLion), the /usr/local/include directory is not added to the include path at all.
I could easily verify this difference by running make VERBOSE=1 and examining the compilation commands. This difference raised a compilation error for the project and I would be interested why do I experience this discrepancy between the mentioned 2 CMake versions? Was some default configuration changed between them?
I have created a MWE:
cmake_minimum_required(VERSION 3.4.3)
project(mwe)
include_directories(SYSTEM /usr/local/include)
add_executable(mwe main.cpp)
Where main.cpp is just a classic Hello World application.
Here are the interesting compilation commands (below I attach the complete logs):
with CMake 3.10.2 (/usr/local/include added correctly):
/usr/bin/c++ -isystem /usr/local/include -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
with CMake 3.16.5 (/usr/local/include missing):
/usr/bin/c++ -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
Running CMake 3.10.2:
>> cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mate/Temp/mwe/build_3-10-2
>> make VERBOSE=1
/usr/bin/cmake -H/home/mate/Temp/mwe -B/home/mate/Temp/mwe/build_3-10-2 --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-10-2/CMakeFiles /home/mate/Temp/mwe/build_3-10-2/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/depend
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
cd /home/mate/Temp/mwe/build_3-10-2 && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mate/Temp/mwe /home/mate/Temp/mwe /home/mate/Temp/mwe/build_3-10-2 /home/mate/Temp/mwe/build_3-10-2 /home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/DependInfo.cmake --color=
Dependee "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/DependInfo.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/depend.internal".
Dependee "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/depend.internal".
Scanning dependencies of target mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/build
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
[ 50%] Building CXX object CMakeFiles/mwe.dir/main.cpp.o
/usr/bin/c++ -isystem /usr/local/include -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
[100%] Linking CXX executable mwe
/usr/bin/cmake -E cmake_link_script CMakeFiles/mwe.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/mwe.dir/main.cpp.o -o mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
[100%] Built target mwe
make[1]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
/usr/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-10-2/CMakeFiles 0
Running CMake 3.16.5:
>> /opt/CLion/bin/cmake/linux/bin/cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mate/Temp/mwe/build_3-16-5
>> make VERBOSE=1
/opt/CLion/bin/cmake/linux/bin/cmake -S/home/mate/Temp/mwe -B/home/mate/Temp/mwe/build_3-16-5 --check-build-system CMakeFiles/Makefile.cmake 0
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-16-5/CMakeFiles /home/mate/Temp/mwe/build_3-16-5/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/depend
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
cd /home/mate/Temp/mwe/build_3-16-5 && /opt/CLion/bin/cmake/linux/bin/cmake -E cmake_depends "Unix Makefiles" /home/mate/Temp/mwe /home/mate/Temp/mwe /home/mate/Temp/mwe/build_3-16-5 /home/mate/Temp/mwe/build_3-16-5 /home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/DependInfo.cmake --color=
Dependee "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/DependInfo.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/depend.internal".
Dependee "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/depend.internal".
Scanning dependencies of target mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/build
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
[ 50%] Building CXX object CMakeFiles/mwe.dir/main.cpp.o
/usr/bin/c++ -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
[100%] Linking CXX executable mwe
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/mwe.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/mwe.dir/main.cpp.o -o mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
[100%] Built target mwe
make[1]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-16-5/CMakeFiles 0

Related

Build issues with shared_mutex and MinGW-w64

I'm currently working on a C++14 project, using MinGW-w64 and a CMake configuration (MinGW Makefile generator). I'm having a hard time building it due to compatibility issues with the shared_mutex library. To circumnavigate such problems, I'm using a custom header-only library called mingw-std-threads. After following all the instructions of the library's mark-down file, I still have errors with shared_mutex.
Here's a minimal reproducible example of the error I am getting. Source file:
#include <shared_mutex>
int main()
{
return 0;
}
The CMake configuration for the test:
# CMake 3.9 or newer
cmake_minimum_required(VERSION 3.9)
# project name, version and description
project(test)
# C++14 or higher
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# library target
add_executable(test test.cpp)
# include directories
target_include_directories(test PRIVATE .)
#MinGW threads
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
add_subdirectory(./mingw-std-threads-master)
target_link_libraries(test PRIVATE mingw_stdthreads)
# defining install rules
include(GNUInstallDirs)
install(TARGETS test
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
The project generation log:
PS C:\Users\luigi\Desktop\test> cmake --version
cmake version 3.18.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\luigi\Desktop\test> cmake -G "MinGW Makefiles" -S ./ -B build/
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw-w64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw-w64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
cmake_stdheaders_generator: output_include_path set to C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator
cmake_stdheaders_generator: MINGW_STDTHREADS_DIR: C:/Users/luigi/Desktop/test/mingw-std-threads-master
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/condition_variable>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/future>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/thread>
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/luigi/Desktop/test/build
PS C:\Users\luigi\Desktop\test>
The resulting build log with the error:
PS C:\Users\luigi\Desktop\test> cmake --build ./build -v
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\luigi\Desktop\test -BC:\Users\luigi\Desktop\test\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\luigi\Desktop\test\build\CMakeFiles C:\Users\luigi\Desktop\test\build\\CMakeFiles\progress.marks
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake --color=
Dependee "C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Dependee "C:/Users/luigi/Desktop/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
C:\mingw-w64\mingw64\bin\g++.exe -DMINGW_STDTHREADS_GENERATED_STDHEADERS #CMakeFiles/test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles\test.dir\test.cpp.obj -c C:\Users\luigi\Desktop\test\test.cpp
In file included from C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.condition_variable.h:53,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/condition_variable:10,
from C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex:37,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/shared_mutex:9,
from C:\Users\luigi\Desktop\test\test.cpp:1:
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:306:12: error: 'std::shared_lock' has not been declared
using std::shared_lock;
^~~~~~~~~~~
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:492:24: error: 'mingw_stdthread::shared_lock' has not been declared
using mingw_stdthread::shared_lock;
^~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\test.dir\build.make:82: CMakeFiles/test.dir/test.cpp.obj] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe: *** [Makefile:148: all] Error 2
PS C:\Users\luigi\Desktop\test>
These are the versions of the tools I'm using:
Windows 10 Pro x64
MinGW-w64 8.1.0
CMake 3.18.3 (using 3.9 for the configuration)
mingw-std-threads 1.0.0
Thanks for helping!

Undefined reference to 'cudaRegisterLinkedBinary' - linking error in CMake?

I'm running CentOS 7.8 via dual-boot on a 64-bit 2013 Mac with a GT 650M GPU. I'm using CMake 3.17, CUDA 10.0, and GCC 4.8.5. All CUDA samples have been tested and work fine, and I'm able to compile other standard C++ code perfectly.
I've reduced my full project to a simple test case as follows, where the CMakeLists file is:
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(test LANGUAGES CUDA CXX C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
MESSAGE(STATUS "Setting to Release mode")
SET(CMAKE_BUILD_TYPE "Release")
# Set CUDA flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_30 -rdc=true")
# Set flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -ffast-math")
MESSAGE(STATUS "Setting g++ flags for Release configuration")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") ## Optimize
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ") ## Strip binary
ADD_SUBDIRECTORY( src )
In the /src folder I have another CMake file to gather the source files:
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
SET(test_SRCS
rsmain.cu
SGP4.cu
SGP4.cuh
)
function(my_add_executable TargetName)
set(Files ${ARGV})
list(REMOVE_AT Files 0)
add_executable(${TargetName} ${Files})
set_target_properties(${TargetName} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_SOURCE_DIR}/build")
endfunction()
my_add_executable(test ${test_SRCS})
INSTALL( TARGETS test DESTINATION bin)
As shown, there are three main source files - both SGP4.cu and SGP4.cuh are empty, while rsmain.cu is simply:
/// Main function
int main(int argc, char *argv[])
{
return 0;
}
When trying to build, I get the following output:
[me#localhost build]$ cmake3 ..
-- The CUDA compiler identification is NVIDIA 10.0.130
-- The CXX compiler identification is GNU 4.8.5
-- The C compiler identification is GNU 4.8.5
-- Check for working CUDA compiler: /usr/local/cuda-10.0/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-10.0/bin/nvcc - works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- No build configuration specified, defaulting to Release
-- Setting general compiler flags for detected compiler: gnu-g++
-- Setting g++ flags for Release configuration
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/Documents/test/build
[me#localhost build]$ make
/usr/bin/cmake3 -S/home/me/Documents/test -B/home/me/Documents/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /home/me/Documents/test/build/CMakeFiles /home/me/Documents/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/me/Documents/test/build'
make -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/depend
make[2]: Entering directory `/home/me/Documents/test/build'
cd /home/me/Documents/test/build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /home/me/Documents/test /home/me/Documents/test/src /home/me/Documents/test/build /home/me/Documents/test/build/src /home/me/Documents/test/build/src/CMakeFiles/test.dir/DependInfo.cmake --color=
Scanning dependencies of target test
make[2]: Leaving directory `/home/me/Documents/test/build'
make -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/build
make[2]: Entering directory `/home/me/Documents/test/build'
[ 33%] Building CUDA object src/CMakeFiles/test.dir/rsmain.cu.o
cd /home/me/Documents/test/build/src && /usr/local/cuda-10.0/bin/nvcc -I/home/me/Documents/test/src -I/home/me/Documents/test/build/src -I/home/me/Documents/test/build -arch=sm_30 -rdc=true -O3 -DNDEBUG -std=c++03 -x cu -c /home/me/Documents/test/src/rsmain.cu -o CMakeFiles/test.dir/rsmain.cu.o
[ 66%] Building CUDA object src/CMakeFiles/test.dir/SGP4.cu.o
cd /home/me/Documents/test/build/src && /usr/local/cuda-10.0/bin/nvcc -I/home/me/Documents/test/src -I/home/me/Documents/test/build/src -I/home/me/Documents/test/build -arch=sm_30 -rdc=true -O3 -DNDEBUG -std=c++03 -x cu -c /home/me/Documents/test/src/SGP4.cu -o CMakeFiles/test.dir/SGP4.cu.o
[100%] Linking CUDA executable ../test
cd /home/me/Documents/test/build/src && /usr/bin/cmake3 -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/g++ -s CMakeFiles/test.dir/rsmain.cu.o CMakeFiles/test.dir/SGP4.cu.o -o ../test -lcudadevrt -lcudart_static -L"/usr/local/cuda-10.0/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda-10.0/targets/x86_64-linux/lib" -lcudadevrt -lcudart_static -lrt -lpthread -ldl
CMakeFiles/test.dir/rsmain.cu.o: In function `__sti____cudaRegisterAll()':
tmpxft_00004eed_00000000-5_rsmain.cudafe1.cpp:(.text.startup+0x25): undefined reference to `__cudaRegisterLinkedBinary_41_tmpxft_00004eed_00000000_6_rsmain_cpp1_ii_main'
CMakeFiles/test.dir/SGP4.cu.o: In function `__sti____cudaRegisterAll()':
tmpxft_00004f02_00000000-5_SGP4.cudafe1.cpp:(.text.startup+0x15): undefined reference to `__cudaRegisterLinkedBinary_39_tmpxft_00004f02_00000000_6_SGP4_cpp1_ii_71922fcb'
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[2]: Leaving directory `/home/me/Documents/test/build'
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make[1]: Leaving directory `/home/me/Documents/test/build'
make: *** [all] Error 2
Could anyone please explain what this 'cudaRegisterLinkedBinary' stuff is all about? I've tried a bunch of things in trying to solve it but nothing has worked so far. Is there an issue with any of the package versions? A problem in CMakeLists? Compatibility issues with CUDA and my hardware?
It's worth noting that the full code compiled and ran perfectly when I tested it on a HPC server (also running CentOS 7 and Cuda 10.0) - but on my personal PC it fails at the linking step. I've even confirmed that the .bashrc files are the same across both installations, but it hasn't fixed anything. I'm also currently able to compile NVIDIA's OptiX software (which also uses CUDA) without any problems.
Any advice would be appreciated. Please let me know if I missed any required details.
EDIT: Answer added below. Resolved.
Finally sorted this out. This was my main CMakeLists file:
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(test LANGUAGES C CXX CUDA)
SET(CMAKE_BUILD_TYPE "Release")
# Set CUDA flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_30 -rdc=true")
# Set flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -ffast-math -O3")
MESSAGE(STATUS "Setting g++ flags for Release configuration")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") ## Strip binary
ADD_SUBDIRECTORY( src )
And in the /src CMakeLists file, I had to make the change:
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
SET(test_SRCS
rsmain.cu
SGP4.cu
SGP4.cuh
)
function(my_add_executable TargetName)
set(Files ${ARGV})
list(REMOVE_AT Files 0)
add_executable(${TargetName} ${Files})
set_target_properties(${TargetName} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_SOURCE_DIR}/build")
endfunction()
my_add_executable(test ${test_SRCS})
INSTALL( TARGETS test DESTINATION bin)
Setting CUDA_RESOLVE_DEVICE_SYMBOLS to ON is the change. In my main project, I also had to repeat this for every target involving any CUDA files. Everything compiles and runs perfectly now.

OpenCV makefile doesn't generate exectuable

I'm new to C++ and I'm trying to recreate the openCV tutorial with Cmake https://docs.opencv.org/master/db/df5/tutorial_linux_gcc_cmake.html
I downloaded the .exe for windows, built the sources with cmake via
cmake.exe -G "MinGW Makefiles"
Then, I tried to use the make command in the project folder with the debug flag. I received this output:
GNU Make 4.2.1
Built for i686-pc-msys
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
Considering target file 'Makefile'.
Looking for an implicit rule for 'Makefile'.
No implicit rule found for 'Makefile'.
Finished prerequisites of target file 'Makefile'.
No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'default_target'.
File 'default_target' does not exist.
Considering target file 'all'.
File 'all' does not exist.
Considering target file 'cmake_check_build_system'.
File 'cmake_check_build_system' does not exist.
Finished prerequisites of target file 'cmake_check_build_system'.
Must remake target 'cmake_check_build_system'.
Putting child 0x2004f248 (cmake_check_build_system) PID 22640 on the chain.
Live child 0x2004f248 (cmake_check_build_system) PID 22640
Microsoft Windows [Version 10.0.18362.836]
(c) 2019 Microsoft Corporation. All rights reserved.
I don't quite understand the output and googling for this didn't prove to be helpful. Since I don't have an executable file at the end (as mentioned in the tutorial), there seems to be some problem. What am I missing?
The CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR "C:/Users/XXX/opencv/opencv")
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
CMake output:
cmake.exe -G "MinGW Makefiles"
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: C:/Rtools/mingw_64/bin/gcc.exe
-- Check for working C compiler: C:/Rtools/mingw_64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Rtools/mingw_64/bin/g++.exe
-- Check for working CXX compiler: C:/Rtools/mingw_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/Users/XXX/opencv/opencv (found version "4.3.0")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/XXX/Documents/C++
make output (minGW-32)
mingw32-make.exe VERBOSE=1
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\XXX\Documents\C++ -BC:\Users\XXX\Documents\C++ --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\XXX\Documents\C++\CMakeFiles C:\Users\XXX\Documents\C++\CMakeFiles\progress.marks
mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe -f CMakeFiles\DisplayImage.dir\build.make CMakeFiles/DisplayImage.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/XXX/Documents/C++'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++\CMakeFiles\DisplayImage.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe -f CMakeFiles\DisplayImage.dir\build.make CMakeFiles/DisplayImage.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe[2]: *** No rule to make target 'C:/Users/XXX/opencv_mingw/sources/build_mingw/lib/libopencv_dnn430.dll.a', needed by 'DisplayImage.exe'. Stop.
mingw32-make.exe[2]: Leaving directory 'C:/Users/XXX/Documents/C++'
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/XXX/Documents/C++'
makefile:102: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

static linking with cmake fails [duplicate]

This question already has answers here:
cmake and libpthread
(4 answers)
Closed 3 years ago.
I am trying to link to a static c++ Library with cmake on ubuntu.
the library is installed here: /usr/local/lib/libfrnetlib.a and headers are located here: /usr/local/include/frnetlib
Thanks for any help!
my cmakelists.txt looks like this:
###### setup
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
###### names + sources
project(ws_server)
set(SOURCE_FILES ws_server.cpp TcpListener.h WebFrame.h WebSocket.h)
###### include
include_directories(/usr/local/lib)
include_directories(/usr/local/include/frnetlib)
link_directories(/usr/local/lib/libfrnetlib.a)
###### library
find_library(frnetlib NAMES libfrnetlib.a HINTS /usr/local/lib)
if(NOT frnetlib)
message([status] "
frnetlib library not found
")
else(frnetlib)
message([status] "---------------frnetlib library found :-)")
endif()
###### executable + linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${frnetlib})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
and the output of cmake like this:
> Executing task: if [ -d build ]; then rm -Rf build; fi && mkdir build && cd build && cmake -v -DCMAKE_BUILD_TYPE=release .. && cmake --build . -v <
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
[status]--------------------------------------frnetlib library found :-)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pandapc/vscode/own_ws_server/build
/usr/local/bin/cmake -S/home/pandapc/vscode/own_ws_server -B/home/pandapc/vscode/own_ws_server/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/pandapc/vscode/own_ws_server/build/CMakeFiles /home/pandapc/vscode/own_ws_server/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
/usr/bin/make -f CMakeFiles/ws_server.dir/build.make CMakeFiles/ws_server.dir/depend
make[2]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
cd /home/pandapc/vscode/own_ws_server/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/pandapc/vscode/own_ws_server /home/pandapc/vscode/own_ws_server /home/pandapc/vscode/own_ws_server/build /home/pandapc/vscode/own_ws_server/build /home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/DependInfo.cmake --color=
Dependee "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/DependInfo.cmake" is newer than depender "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/depend.internal".
Dependee "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/depend.internal".
Scanning dependencies of target ws_server
make[2]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
/usr/bin/make -f CMakeFiles/ws_server.dir/build.make CMakeFiles/ws_server.dir/build
make[2]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
[ 50%] Building CXX object CMakeFiles/ws_server.dir/ws_server.cpp.o
/usr/bin/c++ -I/usr/local/lib -I/usr/local/include/frnetlib -std=c++11 -O3 -DNDEBUG -std=gnu++11 -o CMakeFiles/ws_server.dir/ws_server.cpp.o -c /home/pandapc/vscode/own_ws_server/ws_server.cpp
[100%] Linking CXX executable ws_server
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/ws_server.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -O3 -DNDEBUG -rdynamic CMakeFiles/ws_server.dir/ws_server.cpp.o -o ws_server -L/usr/local/lib/libfrnetlib.a -Wl,-rpath,/usr/local/lib/libfrnetlib.a: /usr/local/lib/libfrnetlib.a
CMakeFiles/ws_server.dir/ws_server.cpp.o: In function `main':
ws_server.cpp:(.text.startup+0x18e): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/ws_server.dir/build.make:84: recipe for target 'ws_server' failed
make[2]: *** [ws_server] Error 1
make[2]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ws_server.dir/all' failed
make[1]: *** [CMakeFiles/ws_server.dir/all] Error 2
make[1]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
The terminal process terminated with exit code: 2
Terminal will be reused by tasks, press any key to close it.
thanks some programmer dude,
the solution is either to set this flag:
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
or use this cmakelists.txt
###### setup
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
###### names + sources
project(ws_server)
set(SOURCE_FILES ws_server.cpp TcpListener.h WebFrame.h WebSocket.h)
###### library
find_library(frnetlib NAMES libfrnetlib.a HINTS /usr/local/lib)
find_package( Threads )
if(NOT frnetlib)
message([status] "
frnetlib library not found!
")
else(frnetlib)
message([status] "--------------------------------------frnetlib library found :-)")
endif()
###### executable + linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${frnetlib} ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

CMake Error: Could not create named generator CodeLite - Unix Makefiles

Using Ubuntu LTS 14.04.
Trying to set up codelite to develop in c++ following this tutorial TheChernoProject How to Setup C++ on Linux
CMakeLists.txt:
cmake_minimum_required (VERSION 3.5)
project (HelloWorld)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14")
set (source_dir "${PROJECT_SOURCE_DIR}/src/")
file (GLOB source_files "${source_dir}/*.cpp")
add_executable (HelloWorld ${source_files})
build.sh:
#!/bin/sh
cmake -G "CodeLite - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
EDIT:
After consulting the Documentation https://github.com/eranif/codelite I modified build.sh to:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
and it worked. and gave the output:
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
However the HelloWorld workspace was not generated
I created a fresh project from scratch purely using CodeLite and it generated the CMake file for me. Everything worked flawlessly.