Build issues with shared_mutex and MinGW-w64 - c++

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!

Related

Why do I get an error about a dummy variable when building googletest v1.10 with GCC 11?

I want to add unit tests to my project with FetchContent_Declare.
I have an example test like:
#include <gtest/gtest.h>
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
TEST(Example, One)
{
ASSERT_TRUE(true);
}
I configure and build my tests using a CMakeLists.txt file:
cmake_minimum_required(VERSION 3.26)
project(unittest_test)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
SYSTEM
)
FetchContent_MakeAvailable(googletest)
set(CMAKE_CXX_STANDARD 17)
enable_testing()
file(GLOB_RECURSE unittests_src CONFIGURE_DEPENDS "*.cpp")
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set_target_properties(gtest gtest_main PROPERTIES COMPILE_WARING_AS_ERROR OFF)
add_executable(
unittests
${unittests_src}
)
target_link_libraries(
unittests
PUBLIC
gtest
gtest_main
)
add_test(
NAME
unittests
COMMAND
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests
)
I have set to use SYSTEM headers in FetchContent_Declare and turned of COMPILE_WARNING_AS_ERROR however, my project wont build because it is still setting warnings as errors:
CMake configure output:
[proc] Executing command: /usr/local/bin/cmake --version
[proc] Executing command: /usr/bin/gcc -v
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[main] Configuring project: CMakeGTest
[proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -S/home/tom/src/CMakeGTest -B/home/tom/src/CMakeGTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 11.3.0
[cmake] -- The CXX compiler identification is GNU 11.3.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: /usr/bin/gcc - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: /usr/bin/g++ - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
and CMake Build output:
[main] Building folder: CMakeGTest
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /home/tom/src/CMakeGTest/build --config Debug --target all -j 22 --
[build] [ 8%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[build] In file included from /home/tom/src/CMakeGTest/build/_deps/googletest-src/googletest/src/gtest-all.cc:42:
[build] /home/tom/src/CMakeGTest/build/_deps/googletest-src/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
[build] /home/tom/src/CMakeGTest/build/_deps/googletest-src/googletest/src/gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
[build] 1301 | StackLowerThanAddress(&dummy, &result);
[build] | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
[build] /home/tom/src/CMakeGTest/build/_deps/googletest-src/googletest/src/gtest-death-test.cc:1290:13: note: by argument 1 of type ‘const void*’ to ‘void testing::internal::StackLowerThanAddress(const void*, bool*)’ declared here
[build] 1290 | static void StackLowerThanAddress(const void* ptr, bool* result) {
[build] | ^~~~~~~~~~~~~~~~~~~~~
[build] /home/tom/src/CMakeGTest/build/_deps/googletest-src/googletest/src/gtest-death-test.cc:1299:7: note: ‘dummy’ declared here
[build] 1299 | int dummy;
[build] | ^~~~~
[build] cc1plus: all warnings being treated as errors
[build] gmake[2]: *** [_deps/googletest-build/googletest/CMakeFiles/gtest.dir/build.make:76: _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
[build] gmake[1]: *** [CMakeFiles/Makefile2:216: _deps/googletest-build/googletest/CMakeFiles/gtest.dir/all] Error 2
[build] gmake: *** [Makefile:146: all] Error 2
[proc] The command: /usr/local/bin/cmake --build /home/tom/src/CMakeGTest/build --config Debug --target all -j 22 -- exited with code: 2
[build] Build finished with exit code 2
My compiler is GCC 11.3.0 x86_64-linux-gnu
My CMake version 3.26.0-rc1
It looks like you have the same problem as the one in this issue on the googletest GitHub repo: Compile error in 1.10.0 while using GCC 11 #3219: You're using GCC 11 and googletest v1.10. That issue got fixed by this PR: https://github.com/google/googletest/pull/3024, and is available in v1.11.0.
You can workaround the issue by inhibiting warnings for the gtest target with target_compile_options(gtest PRIVATE "-w"). In GCC and other compilers, -W inhibits all warnings and the last warning-related compile flag overrides other related ones, so it overrides all warning flags to inhibit them for the gtest target.
Or if you're allowed by whoever leads your project to upgrade the version of googletest you use, just ugrade to version 1.11 or higher. (Update the GIT_TAG argument of your FetchContent_Declare call). Note that the naming convention of their git tags is a little wonky in this version range due to a convention change.
For more general cases of trying to disable warnings that get turned into errors,
Use the COMPILE_WARNING_AS_ERROR target property to specify whether warnings should be errors instead of using -Werror. It's cross platform, and you can control it per target. You can set a default value using the corresponding CMake variable, and then override the default on the test target to turn it off just for that target. If you go this route, you'll still get warnings, but they won't be errors.
See the docs for set_target_properties() and set_property() for how to set target properties.
In cases where the error / warning comes from usage of a library (and not from building the library itself), what you probably really want is to make the include directories for what you fetch using FetchContent to be treated as SYSTEM headers. If that's the case, see Is there a way to get -isystem for FetchContent targets?.

System include directory is not added by CMake 3.16.5

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

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)

C++ cmake & boost & arm cross compilation

I have a problem with compiling my program with boost and cmake. I use cross-compilation with using gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++ compiler.
And now I have cmake file like:
cmake_minimum_required (VERSION 2.6.2)
project (xxx)
SET(CMAKE_CXX_COMPILER /home/kamil/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Dtypeof=__typeof__ -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Werror -Wextra -Wno-error=array-bounds")
if(DEFINED ENV{SDKTARGETSYSROOT})
set(CMAKE_FIND_ROOT_PATH $ENV{SDKTARGETSYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endif(DEFINED ENV{SDKTARGETSYSROOT})
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories("/usr/local/include")
include_directories(${Boost_INCLUDE_DIRS})
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} )
add_subdirectory(src)
add_subdirectory(test EXCLUDE_FROM_ALL)
and
add_executable(xxxx
main.cpp
...cpp
...cpp
...cpp
...cpp
)
target_link_libraries(xxxx
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
)
install(TARGETS xxxx
DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
And now when use commands in linux(Ubuntu):
cmake ..
make
I have response at:
kamil#kamil:~/test/build$ rm -rf *
kamil#kamil:~/test/build$ cmake ..
-- 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
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- Found GTest: /usr/local/lib/libgtest.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kamil/test/build
kamil#kamil:~/test/build$ make
Scanning dependencies of target xxxx
[ 12%] Building CXX object src/CMakeFiles/test.dir/main.cpp.o
In file included from /home/test/src/test/utils/logger.hpp:4:0,
from /home/kamil/test/src/main.cpp:9:
/home/kamil/test/src/test/utils/singleton.hpp:5:33: fatal error: boost/noncopyable.hpp: No such file or directory
#include <boost/noncopyable.hpp>
^
compilation terminated.
make[2]: *** [src/CMakeFiles/test.dir/main.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
Error:
fatal error: boost/noncopyable.hpp: No such file or directory
#include <boost/noncopyable.hpp>
When I comment on the following line in cmake:
SET(CMAKE_CXX_COMPILER /home/kamil/toradex/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)
then everything is ok.
I install boost in Ubuntu with command: sudo apt-get install libboost1.55-all-dev
What is wrong with compiling with linux-gnueabihf-g++ and how to fix it.
Compiling boost with gcc-linaro-arm-linux-gnueabihf-4.9 worked.
Helps link: http://www.cnx-software.com/2011/10/03/cross-compiling-boost-c-libraries-for-arm/