Simple cmake project, build with nmake on windows has no debug symbols - c++

I'm trying to lear using CMAKE to create builds. I've been experimenting but can't get debugging to work on my resulting projects. To test this, I've setup a basic hello world project like this:
SimpleProject
--Include
--Main.cpp
--CMakeLists.txt
This is the contents of Main.cpp.
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
std::getchar();
return 0;
}
and this is the content of CMakeLists.txt:
cmake_minimum_required(VERSION 3.15.3)
project(CleanProject LANGUAGES CXX C)
add_executable(CleanProject Include/Main.cpp)
I now run cmake with the following command, in the developer console:
D:\Development\SimpleProject\Build>cmake -DCMAKE_BUILD_TYPE=Debug ..
-- Building for: NMake Makefiles
-- The CXX compiler identification is MSVC 19.23.28105.4
-- The C compiler identification is MSVC 19.23.28105.4
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe --
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: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe --
works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Development/SimpleProject/Build
Lastly, I build using nmake
Microsoft (R) Program Maintenance Utility Version 14.23.28105.4
Copyright (C) Microsoft Corporation. All rights reserved.
Scanning dependencies of target CleanProject
[ 50%] Building CXX object CMakeFiles/CleanProject.dir/Include/Main.cpp.obj
Main.cpp
[100%] Linking CXX executable CleanProject.exe
[100%] Built target CleanProject
If I now try to debug this program, be it in an IDE like eclipse or by using gdb from the command line, I'll get the no debugging symbols found error as seen below.
D:\Development\SimpleProject\Build>C:\MinGW\bin\gdb.exe CleanProject.exe
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 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. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from D:\Development\SimpleProject\Build\CleanProject.exe...(no debugging symbols found)...done.
I can't seem to find a fix for this. I've tried adding several different vars to my cmakelist file or as extra options for cmake with no success.
Any help would be greatly appreciated as this is the only roadblock left as of now. My bigger projects also build successfully but without debugging it's kinda hard to continue.
Thanks!

Reading your CMake output:
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe -- works
It seems like you are using the Visual Studio compiler.
The way it compiles is incompatible with the GDB debugger, you'll have to use the MSVC debugger instead, which can be run within the visual studio debugger.

Related

make: *** makefile. stop

I am new to cmake, and when I compile the makefile using "make -j10" after cmake, it failed and turned out "make: *** makefile. stop." I am really confused. Thanks in advance for precious suggestions!
G:\code\c++\assignment2\code\test>mkdir build
G:\code\c++\assignment2\code\test>cd build
G:\code\c++\assignment2\code\test\build>cmake ..
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.28.29912.0
-- The CXX compiler identification is MSVC 19.28.29912.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: G:/vs/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.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: G:/vs/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Found Boost: G:/boost_1_75_0/ (found version "1.75.0") found components: timer chrono
-- Configuring done
-- Generating done
-- Build files have been written to: G:/code/c++/assignment2/code/test/build
G:\code\c++\assignment2\code\test\build>make -j10
make: *** makefile. stop.
Run cmake --build . -j 10 under your build directory.
You didn't build makefiles, you built Visual Studio project files, as can be seen from this line:
Building for: Visual Studio 16 2019
To instruct CMake to generate makefiles instead, use cmake's -G flag:
cmake .. -G "Unix Makefiles"
Or if you didn't intend to build makefiles, you can compile using the generated build system (in this case Visual Studio) as shown in aleck099's answer.

Visual Studio to build C++/CMake project hosted in GitHub

I am an "emacs/[c]make/ninja/clang/bash/linux/macOs" kind of C++ developer who is not used to IDEs like Visual Studio. I'm not claiming either approach is better or worse, just that I do not know how to work with IDEs.
I am now in need to develop a C++ project for a Windows-based client who strongly relies on Visual Studio.
My understanding is that Visual Studio 2017 has built-in support for CMake, Ninja, and Google Test. However, I am unable to come up with a workflow that would allow me to simply code as usual, commit my code to, say, GitHub, and have my client simply "refresh the repo and rebuild the solution".
Here is my question: what is the absolute simplest way in which you would clone a C++/CMake GitHub repository and build it in Visual Studio?
As a reference, I created the following repository:
https://github.com/arrieta/visual-studio-cmake-test
This is how I build it using my normal approach:
$ git clone https://github.com/arrieta/visual-studio-cmake-test.git
$ cd visual-studio-cmake-test
$ mkdir build
$ cd build
$ cmake -G Ninja ../
$ ninja
$ ./app
Welcome to app v0.0.1
Hello, world!
For the life of me, I cannot come up with such simple approach in Visual Studio (not that the tool is bad, it is simply my ignorance). I create a "Solution", then a "Project", then a "Repo", and I have so many options that I am at a loss.
Any help is appreciated.
vre's Solution
User vre provided the following approach, which works exactly as intended. Here, C:\> denotes my Windows Developer Command Prompt.
C:\> git clone https://github.com/arrieta/visual-studio-cmake-test.git
Cloning into 'visual-studio-cmake-test'...
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 20 (delta 3), reused 20 (delta 3), pack-reused 0Unpacking objects: 5% (1/20)
Unpacking objects: 100% (20/20), done.
C:> cd visual-studio-cmake-test
C:> mkdir build
C:> cd build
C:> cmake -G "Visual Studio 15 2017" ..\
-- The C compiler identification is MSVC 19.13.26129.0
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- 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: C:[...]/visual-studio-cmake-test/build
C:> cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
[uninteresting output]
C:> cd Debug
C:> app.exe
Welcome to app v0.0.1
Hello, world!
You can target the Visual Studio generator from CMake and then use the build tool mode of CMake. E.g
cmake -G "Visual Studio 15 2017" ..\
and
cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
all from your build directory. This uses MSBuild as the native build tool and builds your entire solution from the command line.
See this post for further arguments to CMake build tool mode for installing or testing. CMake + MSVC build tools 2015 - what to do after invoking cmake?
And see the CMake Documentation for the build tool mode https://cmake.org/cmake/help/v3.10/manual/cmake.1.html
Working Example
C:\> git clone https://github.com/arrieta/visual-studio-cmake-test.git
Cloning into 'visual-studio-cmake-test'...
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 20 (delta 3), reused 20 (delta 3), pack-reused 0Unpacking objects: 5% (1/20)
Unpacking objects: 100% (20/20), done.
C:> cd visual-studio-cmake-test
C:> mkdir build
C:> cd build
C:> cmake -G "Visual Studio 15 2017" ..\
-- The C compiler identification is MSVC 19.13.26129.0
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- 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: C:[...]/visual-studio-cmake-test/build
C:> cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
[uninteresting output]
C:> cd Debug
C:> app.exe
Welcome to app v0.0.1
Hello, world!

BLAS should automatically detected by CMake-GUI 3.10.1

I have a project running via CMake-GUI 3.10.1 with MinGW ,But When I try to configure that I got this error.I think something wrong with my CMake-GUI.Maybe BLAS should automatically detected by CMake-GUI.So what should I do.
The Fortran compiler identification is GNU 7.2.0
The C compiler identification is GNU 7.2.0
The CXX compiler identification is GNU 7.2.0
Check for working Fortran compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gfortran.exe
Check for working Fortran compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gfortran.exe -- works
Detecting Fortran compiler ABI info
Detecting Fortran compiler ABI info - done
Checking whether C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gfortran.exe supports Fortran 90
Checking whether C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gfortran.exe supports Fortran 90 -- yes
Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gcc.exe
Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/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:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/g++.exe
Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:49 (CMAKE_POLICY):
The OLD behavior for policy CMP0022 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Checking whether GFortran version >= 4.8 -- yes
Found MPI_C: C:/Windows/System32/msmpi.dll
Found MPI_CXX: C:/Windows/System32/msmpi.dll
Found MPI_Fortran: C:/Windows/System32/msmpi.dll
Looking for pthread.h
Looking for pthread.h - found
Looking for pthread_create
Looking for pthread_create - found
Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.10/Modules/FindBLAS.cmake:699 (message):
A required library with BLAS API not found. Please specify library
location.
Call Stack (most recent call first):
CMakeLists.txt:151 (find_package)
Configuring incomplete, errors occurred!
See also "F:/FreshElmerCM10MGW_ouput_x02/elmerfem/CMakeFiles/CMakeOutput.log".

CMake with mingw on Windows 10: Detecting CXX compiler ABI info - failed

I want to use cmake to create MinGW Makefiles on windows 10. I have installed mingw and I can use mingw32-make and g++ commands without issue.
The test project is a super simple CMakeLists.txt file:
cmake_minimum_required(VERSION 3.10)
project(hello-world)
add_executable(hello-world main.cpp)
and a simple main.cpp file:
#include <iostream>
int main() {
std::cout << "hello Visual Studio Code! :)" << '\n';
return 0;
}
These are the commands I use to create the makefiles:
>> mkdir build
>> cd build
>> cmake -G "MinGW Makefiles" ..
This is where I get errors:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.10/Modules/CMakeDetermineCompilerId.cmake:495 (file):
file STRINGS file
"C:/Projects/test/build/CMakeFiles/3.10.1/CompilerIdCXX/a.exe" cannot be read.
... some more errors in the test files
-- The CXX compiler identification is GNU 6.3.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 - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
This is from the error log:
The CXX compiler identification could not be found in "C:/Projects/test/build/CMakeFiles/3.10.1/CompilerIdCXX/a.exe"
What is the CXX compiler ABI info and how can it be, that there is a working CXX compiler detected but this fails?
Let me know if you need anymore info about the setup!
What turned out to be my culprit was Windows Defender! Turned that off and the CXX compiler ABI info - failed issue went away.
I used the CMake-GUI tool to figure out the missing tool dependencies. For example : CMAKE_ADDR2LINE was not set, once I pointed it to the correct location of addr2line.exe ,the errors were resolved.

make: No targets provided near line 28 (CMake)

I am having newbie problems with CMake. The error I get is make: No targets provided near line 28
My setup is as follows:
Developer Command Prompt for VS2015
Microsoft Windows [Version 6.3.9600]
cmake version 2.8.11.2
make version1.1 (Jan 28 2007)
The steps I have followed are listed on CMake Tutorial | CMake in the first section A Basic Starting Point (Step1).
Quoting from the website...
The most basic project is an executable built from source code files. For simple projects a two line CMakeLists.txt file is all that is required. This will be the starting point for our tutorial. The CMakeLists.txt file looks like:
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial tutorial.cxx)
Note that this example uses lower case commands in the CMakeLists.txt file. Upper, lower, and mixed case commands are supported by CMake. The source code for tutorial.cxx will compute the square root of a number and the first version of it is very simple, as follows:
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);
return 0;
}
Commands
c:\HW>cd c:\hw\tutorial
c:\HW\tutorial>cd build
c:\HW\tutorial\build>cmake ../src
-- Building for: NMake Makefiles
-- The C compiler identification is MSVC 19.0.23026.0
-- The CXX compiler identification is MSVC 19.0.23026.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/HW/tutorial/build
c:\HW\tutorial\build>make
make: No targets provided near line 28
Lines 26 to 31 of Makefile, line 28 emphasized:
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
SHELL = cmd.exe
(Incidentally when I ran GNU make (just to see what would happen) I got
makefile:28: *** missing separator. Stop.)
You're using CMake's generator NMake Makefiles, which generates a buildsystem for nmake. So run nmake instead of make to do the build.