Having problems with mingw32-make to make googletest - cmake

This is my current environment.
Windows 10 64bit, MinGW, CMake 3.15.2, Python 3.7.
I downloaded googletest from https://github.com/google/googletest.
I ran cmake and the following is the output.
C:\googletest-master>cd build
C:\googletest-master\build>cmake ../ -G "MinGW Makefiles"
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/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:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/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 PythonInterp: C:/Users/sangjin/AppData/Local/Programs/Python/Python37-32/python.exe (found version "3.7.4")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/googletest-master/build
But when I ran mingw32-make I got the following error message.
C:\googletest-master\build>mingw32-make
Scanning dependencies of target gtest
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from C:\googletest-master\googletest\src\gtest-all.cc:41:
C:/googletest-master/googletest/src/gtest.cc:86:11: fatal error: crtdbg.h: No such file or directory
# include <crtdbg.h> // NOLINT
^~~~~~~~~~
compilation terminated.
googletest\CMakeFiles\gtest.dir\build.make:62: recipe for target 'googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
mingw32-make[2]: *** [googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
CMakeFiles\Makefile2:171: recipe for target 'googletest/CMakeFiles/gtest.dir/all' failed
mingw32-make[1]: *** [googletest/CMakeFiles/gtest.dir/all] Error 2
Makefile:139: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
C:\googletest-master\build>
Can anyone help me fix this problem.

This version of google test doesn't have that issue, try to build it
https://github.com/google/googletest/tree/216c37f057ae0fff38062984c890df912f40ccf6

Here is a solution for
mingw32-base version 2013072200
mingw32-gcc-g++ version 6.3.0-1
gtest version 1.10.0
In ...\googletest\src\gtest.cc
first at (original) line 86, make header inclusion conditional to MSC toolchain using #ifdef _MSC_VER ... #endif preprocessor macros.
#ifdef _MSC_VER
# include <crtdbg.h> // NOLINT
# include <debugapi.h> // NOLINT
#endif // _MSC_VER
then at (original) line 4913, make assertion redirection also conditional.
#ifdef _MSC_VER
// In debug mode, the Windows CRT can crash with an assertion over invalid
// input (e.g. passing an invalid file descriptor). The default handling
// for these assertions is to pop up a dialog and wait for user input.
// Instead ask the CRT to dump such assertions to stderr non-interactively.
if (!IsDebuggerPresent()) {
(void)_CrtSetReportMode(_CRT_ASSERT,
_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
(void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
}
#endif // _MSC_VER
With theese changes, unit tests build and execute as expected.

Related

Trouble with simple CMAKE tutorial

I just followed the simple CMake tutorial on youtube
https://www.youtube.com/watch?v=V1YP7eJHDJE
As you can see through the youtube,
folder directory is
CMAKE-GOOD
-build
-CMakeLists.txt
-main.cpp
this is CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(MyProject VERSION 1.0.0)
add_executable(cmake-good main.cpp)
this is main.cpp
#include <iostream>
int main()
{
std::cout << "hello, world! \n";
}
it is the only source code that I wrote.
and from this part, this will be covered my errors that I encountered
edit) I also did the cmake .. in the build directory
the result was shown in below
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bmssa/Desktop/CMake_tutorial/CMAKE-GOOD/build
when I type cmake --build . in ~Desktop/CMake_tutorial_CMAKE_GOOD/build, it shows an Error with
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ cmake --build .
[ 50%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
as I heard cmake --build . is similar to make,
so I tried make and it shows an error like this
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ make
[ 50%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
when I type cmake --version,
cmake version 3.20.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Can you please help me how to fix it?
I couldn't do anything because I can't even solve this one simple error in the very easy tutorial.
Please HELP ME PLEASE
Thank you
ps.
Because I don't even know what is an error in CMake, could you tell me what should I type in google to solve this?
recipe for taget?
recipe for target 'all' failed?
I don't know what should I type in google....
edit2) I also did the cmake -S . -B build/foobar and cmake --build build/foobar and this also shows the similar Error like this
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD$ cmake -S . -B build/foobar
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bmssa/Desktop/CMake_tutorial/CMAKE-GOOD/build/foobar
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD$ cmake --build build/foobar
[ 50%] Building CXX object CMakeFiles/cmake-good.dir/main.cpp.o
[100%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
Here is my guess to your problem. CMake is unable to find a working toolchain (Compiler, linker, etc.)
Try helping it out by specifying the environment variables CC and CXX.
https://cmake.org/cmake/help/latest/envvar/CXX.html
https://cmake.org/cmake/help/latest/envvar/CC.html
export CC = /foobar/...../gcc
export CXX = /foobar/...../g++
For future reference here is how CMake finds compilers (according to a CMake dev)
CMAKE_TOOLCHAIN_FILE (if provided)
CMAKE_LANG_COMPILER (if provided)
The environment variables CC or CXX (if provided)
Then it searches the path environment variable to see if it can find anything.
I guess in your situation none of the above worked. So setting CC and CXX fixed it.

CMake cannot find OpenMPI head file when I Install it by using conda

I am not very familiar with installing package by conda. I install the OpenMPI by conda install -c conda-forge/label/gcc7 openmpi. After that I write the following CMakeLists.txt file
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(CUDA_MPI LANGUAGES CXX CUDA)
find_package(CUDA REQUIRED)
find_package(MPI REQUIRED)
add_library(Timer STATIC timer.h
timer.cpp)
add_library(Coll STATIC collectives.h
collectives.cu)
add_executable(CUDA_MPI ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp)
include_directories(/usr/lib/x86_64-linux-gnu/openmpi/include)
target_link_libraries(CUDA_MPI PUBLIC Timer Coll MPI::MPI_CXX ${CUDA_LIBRARIES})
My configuration log is as the following. It seems that CMake tool can find the library of OpenMPI but it cannot find the head file.
-- The CXX compiler identification is GNU 7.3.0
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Check for working CXX compiler: /home/szhangcj/.conda/envs/distributed/bin/x86_64-conda_cos6-linux-gnu-c++
-- Check for working CXX compiler: /home/szhangcj/.conda/envs/distributed/bin/x86_64-conda_cos6-linux-gnu-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 CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found version "10.0")
-- Found MPI_CXX: /home/szhangcj/.conda/envs/distributed/lib/libmpi_cxx.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/szhangcj/HPC/MPI/baidu-allreduce/build
The error message from the generating stage is as the following.
Scanning dependencies of target Timer
[ 14%] Building CXX object CMakeFiles/Timer.dir/timer.cpp.o
[ 28%] Linking CXX static library libTimer.a
[ 28%] Built target Timer
Scanning dependencies of target Coll
[ 42%] Building CUDA object CMakeFiles/Coll.dir/collectives.cu.o
/home/szhangcj/HPC/MPI/baidu-allreduce/collectives.cu:9:10: fatal error: mpi.h: No such file or directory
#include <mpi.h>
^~~~~~~
compilation terminated.
CMakeFiles/Coll.dir/build.make:62: recipe for target 'CMakeFiles/Coll.dir/collectives.cu.o' failed
make[2]: *** [CMakeFiles/Coll.dir/collectives.cu.o] Error 1
CMakeFiles/Makefile2:147: recipe for target 'CMakeFiles/Coll.dir/all' failed
make[1]: *** [CMakeFiles/Coll.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I have checked the installation directory and I found that there is no include directory under the openmpi folder. How can I fix this?
What's more, on another machine, I repeat the same process to install the Openmpi by using conda. After that, I even cannot find the MPI library.

How to use CMake

I am trying to rebuild this on my machine:
https://github.com/sfdodge/xnet
For this I needed to install xtensor and xtensor-blas. I followed the steps and successfully installed xtensor. However, I have trouble installing xtensor-blas. I create a fresh directory and run this command
cmake /home/fatima/Downloads/xtensor-blas-master
It generates the following log:
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
-- xtensor-blas v0.14.0
CMake Error at CMakeLists.txt:45 (find_package):
By not providing "Findxtensor.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "xtensor", but
CMake did not find one.
Could not find a package configuration file provided by "xtensor" with any
of the following names:
xtensorConfig.cmake
xtensor-config.cmake
Add the installation prefix of "xtensor" to CMAKE_PREFIX_PATH or set
"xtensor_DIR" to a directory containing one of the above files. If
"xtensor" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/fatima/Downloads/Untitled Folder 3/CMakeFiles/CMakeOutput.log".
What am I doing wrong?

nullability specifier cannot be applied to non-pointer type error in Foundation?

I'm trying to compile some Objective-C++ files in C++ cmake based project. I'm getting an error similar to this:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/barakat/Desktop/dummy/cmake-build-debug --target dummy -- -j 2
Scanning dependencies of target dummy
[ 50%] Building CXX object CMakeFiles/dummy.dir/main.mm.o
In file included from /Users/barakat/Desktop/dummy/main.mm:2:
In file included from /System/Library/Frameworks/Metal.framework/Headers/Metal.h:9:
In file included from /System/Library/Frameworks/Metal.framework/Headers/MTLTypes.h:8:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:128:
/System/Library/Frameworks/Foundation.framework/Headers/NSUUID.h:26:49: error: nullability specifier '_Nullable' cannot be applied to non-pointer type 'uuid_t' (aka 'unsigned char [16]')
- (instancetype)initWithUUIDBytes:(const uuid_t _Nullable)bytes;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUUID.h:29:30: error: nullability specifier '_Nonnull' cannot be applied to non-pointer type 'uuid_t' (aka 'unsigned char [16]')
- (void)getUUIDBytes:(uuid_t _Nonnull)uuid;
^
2 errors generated.
make[3]: *** [CMakeFiles/dummy.dir/main.mm.o] Error 1
make[2]: *** [CMakeFiles/dummy.dir/all] Error 2
make[1]: *** [CMakeFiles/dummy.dir/rule] Error 2
make: *** [dummy] Error 2
This is my first time working with Objective-C/C++ but the issue appears to be in some standard header? The uuid_t is defined (ultimately) as unsigned char[16].
Simplest code producing the error:
// main.mm
#import <Metal/Metal.h>
int main() {
id <MTLDevice> device = MTLCreateSystemDefaultDevice();
}
CMakeLists.txt:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(dummy)
set(CMAKE_CXX_STANDARD 11)
add_executable(dummy main.mm)
Log (Xcode? Version 8.2.1):
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/barakat/Desktop/dummy
-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Users/barakat/Desktop/dummy/cmake-build-debug
[Finished]

add_custom_command not working

I am trying to understand add_custom_command usage, I wrote a minimal make file (CMakeLists.txt)
like shown below
When I run the make file using
$cmake.
$make
I don't see perfecthash.cpp being created and the build breaks
cmake_minimum_required(VERSION 2.8)
# Call add_custom_command() with appropriate arguments for generate output file
# Note, that *gperf* will work in the build tree,
# so for file in the source tree full path should be used.
function(gperf_generate_new input output)
MESSAGE("debugging function")
add_custom_command(
OUTPUT ${output}
COMMAND gperf -L c++ ${input} > ${output}
DEPENDS ${input}
COMMENT "printing ${output}" # Just for nice message during build
)
endfunction()
# Generate *example.hpp* file ...
gperf_generate_new(command_options.new.gperf pefecthash.hpp)
# ... for use it in executable
add_custom_target(my_target
ALL # Force target to be built with default build target.
DEPENDS perfecthash.hpp
)
$cmake .
$make
give the below error
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- 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
debugging function
-- Configuring done
-- Generating done
-- Build files have been written to: /home/srinivas
Scanning dependencies of target my_target
make[2]: *** No rule to make target `perfecthash.hpp', needed by `CMakeFiles/my_target'. Stop.
make[1]: *** [CMakeFiles/my_target.dir/all] Error 2
make: *** [all] Error 2
Just a typo:
gperf_generate_new(command_options.new.gperf pefecthash.hpp)
...
DEPENDS perfecthash.hpp