国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

這篇具有很好參考價(jià)值的文章主要介紹了windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

由于編譯器支持特性、編譯后程序運(yùn)行速度、安裝使用便捷程度等的不同,我們往往會(huì)安裝多種不同的編譯器。對(duì)于c++語(yǔ)言主要的編譯器有:microsoft、intel、gnu等,對(duì)于fortran語(yǔ)言則更多,包括gnu、intel、pgi等等。不同的編譯器在一個(gè)系統(tǒng)下,往往需要利用一些手段進(jìn)行區(qū)分,比如環(huán)境變量的臨時(shí)設(shè)置等方式,便于區(qū)別使用。
本文介紹一下對(duì)于同一個(gè)程序利用不同的編譯器進(jìn)行編譯的不同方法。

1. 編譯器準(zhǔn)備

本文介紹主要針對(duì)c++和fortran,但以c++為例,fortran的方式是類(lèi)似的。
c++程序可以采用3種編譯器:microsoft、intel、gnu。

其中前兩種編譯器的安裝在【前文】 介紹過(guò)了,這里不再說(shuō)明。

GNU編譯器在windows最常用的是mingw和cygwin。這里我們使用【mingw-w64】。幾年前mingw-w64主要下載的工具是【MingW-W64-builds工具】。但近今年維護(hù)似乎不再持續(xù),而轉(zhuǎn)向msys2了。所以下載msys2【下載地址】 即可。msys2用法參考其【官網(wǎng)】 。需要注意的是,下載安裝msys2后只有msys2支持環(huán)境,編譯工具需要另外下載,打開(kāi)msys2命令行,輸入如下命令下載編譯工具:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain

編譯器下載完成后,需要將工具所在路徑加入系統(tǒng)路徑,如:

D:\msys64\mingw64\bin

在命令行下使用命令path或者env可以看到該路徑已經(jīng)加入了系統(tǒng)路徑中。
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試
注意:如果是在msys2提供的命令行下工作,那么可以修改home下的.bashrc文件,將mingw的地址加入到msys2的系統(tǒng)目錄中,比如:

export PATH="/mingw64/bin/:$PATH"

如此每次打開(kāi)msys2命令行就能找到g++等工具了。觀測(cè)path可知:
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

2. 編譯工具和編輯器準(zhǔn)備

編譯工具我們使用命令行和cmake,【前文】介紹過(guò),安裝即可 。
編輯器使用【vscode】 。
需要安裝C/C++,C/C++ Extension Pack 兩個(gè)插件,后者已經(jīng)包含了CMake Tools插件。

3. 程序準(zhǔn)備

C/C++測(cè)試程序使用一個(gè)簡(jiǎn)單的程序(這個(gè)示例是vscode網(wǎng)址上的)

#include <iostream>

#include <vector>
#include <string>

using namespace std;


int main(int, char**) {

    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    cout << "Hello, world!\n";

    int i=0;
    for (const string& word : msg)
    {
        cout << word << " ";
        i++;
    }
    cout << endl;
}

4. 命令行結(jié)合cmake使用三種編譯器編譯c++程序

4.1 使用GNU編譯器

建立一個(gè)文件夾,放入c++程序,并創(chuàng)建一個(gè)CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

# set the project name
project(main)

# add the executable
add_executable(main main.cpp)

enable_testing()

add_test(NAME test_serial COMMAND main)

然后進(jìn)入普通的命令行,使用如下命令進(jìn)行編譯和測(cè)試:

cmake -G "MinGW Makefiles"

cmake --build .

ctest  -VV

結(jié)果為:

D:\test\projects\icltestcmkcgnu>cmake -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 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/msys64/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: D:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/test/projects/icltestcmkcgnu

D:\test\projects\icltestcmkcgnu>cmake --build .
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.obj
[100%] Linking CXX executable main.exe
[100%] Built target main

D:\test\projects\icltestcmkcgnu>ctest  -VV
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcgnu/DartConfiguration.tcl
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcgnu/DartConfiguration.tcl
Test project D:/test/projects/icltestcmkcgnu
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: test_serial

1: Test command: D:\test\projects\icltestcmkcgnu\main.exe
1: Test timeout computed to be: 10000000
1: Hello, world!
1: Hello C++ World from VS Code and the C++ extension!
1/1 Test #1: test_serial ......................   Passed    0.46 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.48 sec

D:\test\projects\icltestcmkcgnu>

4.2 使用ms編譯器

建立一個(gè)文件夾,放入c++程序,并創(chuàng)建一個(gè)CMakeLists.txt,與前一小結(jié)相同。

然后使用如下命令進(jìn)行編譯和測(cè)試:

cmake .

cmake --build .

ctest -C Debug -VV

注意:進(jìn)入的命令行是Developer Command Prompt for VS 2019,這是安裝ms build工具得到的。

注意:ctest的時(shí)候使用選項(xiàng)-C Debug,因?yàn)閙s這種編譯器區(qū)分不同的模式。

D:\test\projects\icltestcmkcms>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.29.30139.0
-- The CXX compiler identification is MSVC 19.29.30139.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/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: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/test/projects/icltestcmkcms

D:\test\projects\icltestcmkcms>cmake --build .
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.11.2+f32259642
版權(quán)所有(C) Microsoft Corporation。保留所有權(quán)利。

  Checking Build System
  Building Custom Rule D:/test/projects/icltestcmkcms/CMakeLists.txt
  main.cpp
  main.vcxproj -> D:\test\projects\icltestcmkcms\Debug\main.exe
  Building Custom Rule D:/test/projects/icltestcmkcms/CMakeLists.txt

D:\test\projects\icltestcmkcms>ctest -C Debug -VV
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcms/DartConfiguration.tcl
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcms/DartConfiguration.tcl
Test project D:/test/projects/icltestcmkcms
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: test_serial

1: Test command: D:\test\projects\icltestcmkcms\Debug\main.exe
1: Test timeout computed to be: 10000000
1: Hello, world!
1: Hello C++ World from VS Code and the C++ extension!
1/1 Test #1: test_serial ......................   Passed    0.32 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.35 sec

D:\test\projects\icltestcmkcms>

4.3 使用intel編譯器

建立一個(gè)文件夾,放入c++程序,并創(chuàng)建一個(gè)CMakeLists.txt,與前一小結(jié)相同。

然后使用如下命令進(jìn)行編譯和測(cè)試:

cmake -T "Intel C++ Compiler 2022" -DCMAKE_CXX_COMPILER="icl" .

cmake --build .

ctest -C Debug -VV

注意:進(jìn)入的命令行是Intel oneAPI command prompt for Intel 64 for Visual Studio 2019,這是安裝intel oneapi工具得到的。

結(jié)果為:

D:\test\projects\icltestcmkcintel>cmake -T "Intel C++ Compiler 2022" -DCMAKE_CXX_COMPILER="icl" .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- The C compiler identification is IntelLLVM 2022.0.0 with MSVC-like command-line
-- The CXX compiler identification is IntelLLVM 2022.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Program Files/intel/compiler/2022.0.0/windows/bin/intel64/icl.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: D:/Program Files/intel/compiler/2022.0.0/windows/bin/intel64/icl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/test/projects/icltestcmkcintel

D:\test\projects\icltestcmkcintel>cmake --build .
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.11.2+f32259642
版權(quán)所有(C) Microsoft Corporation。保留所有權(quán)利。

  Checking Build System
  Building Custom Rule D:/test/projects/icltestcmkcintel/CMakeLists.txt
  Building Custom Rule D:/test/projects/icltestcmkcintel/CMakeLists.txt

D:\test\projects\icltestcmkcintel>ctest -C Debug -VV
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcintel/DartConfiguration.tcl
UpdateCTestConfiguration  from :D:/test/projects/icltestcmkcintel/DartConfiguration.tcl
Test project D:/test/projects/icltestcmkcintel
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: test_serial

1: Test command: D:\test\projects\icltestcmkcintel\Debug\main.exe
1: Test timeout computed to be: 10000000
1: Hello, world!
1: Hello C++ World from VS Code and the C++ extension!
1/1 Test #1: test_serial ......................   Passed    0.32 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.34 sec

D:\test\projects\icltestcmkcintel>

4.4 fortran程序

方法是類(lèi)似的,創(chuàng)建一個(gè)CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

enable_language(Fortran)

# set the project name
project(main)

# add the executable
add_executable(main main.f90)

enable_testing()

add_test(NAME test_serial COMMAND main)

GNU編譯器,進(jìn)入普通的命令行,用命令:

cmake -G "MinGW Makefiles"

cmake --build .

ctest -VV

編譯。

Intel編譯器,則進(jìn)入Intel oneAPI command prompt for Intel 64 for Visual Studio 2019命令行,
使用命令:

cmake -G "NMake Makefiles"

cmake --build .

ctest -VV

編譯。

5. 使用vscode和三種編譯器編譯調(diào)試c++程序

5.1 gnu 編譯器

使用一般的命令行,進(jìn)入當(dāng)前c++程序所在的文件夾,使用命令:

code .

打開(kāi)vscode。

從vscode菜單:終端-》配置默認(rèn)生成任務(wù),選擇g++,會(huì)生成tasks.JSON,自動(dòng)放在文件加下的.vscode下。
其內(nèi)容為:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++.exe 生成活動(dòng)文件",
			"command": "D:\\msys64\\mingw64\\bin\\g++.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "編譯器: D:\\msys64\\mingw64\\bin\\g++.exe"
		}
	]
}

在編輯器中選擇cpp文件,并
從vscode菜單:終端-》運(yùn)行任務(wù),選擇g++,這時(shí)可以生成執(zhí)行文件。

在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》添加配置,選項(xiàng)gdb,可以生成調(diào)試所需的json配置,自動(dòng)放在文件加下的.vscode下。需要注意:若沒(méi)有g(shù)db選項(xiàng),可以隨意選擇,然后用下述json配置替換即可。

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "g++.exe - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "d:\\msys64\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++.exe 生成活動(dòng)文件"
      }
    ]
  }

修改其中的"stopAtEntry": true,,那么可使在調(diào)試時(shí)逐句執(zhí)行。

在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》啟動(dòng)調(diào)試,則可進(jìn)入調(diào)試。

從調(diào)試欄中選擇單步跳過(guò),不斷執(zhí)行,可以在左側(cè)欄中看到變量的變化。

結(jié)果為:
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

5.2 ms 編譯器

使用命令行Developer Command Prompt for VS 2019,進(jìn)入當(dāng)前c++程序所在的文件夾,使用命令:

code .

打開(kāi)vscode。

從vscode菜單:終端-》配置默認(rèn)生成任務(wù),選擇C/C++: cl.exe 生成活動(dòng)文件,會(huì)生成tasks.JSON,自動(dòng)放在文件加下的.vscode下。
其內(nèi)容為:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: cl.exe 生成活動(dòng)文件",
			"command": "cl.exe",
			"args": [
				"/Zi",
				"/EHsc",
				"/nologo",
				"/Fe:",
				"${fileDirname}\\${fileBasenameNoExtension}.exe",
				"${file}"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$msCompile"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "編譯器: cl.exe"
		}
	]
}

在編輯器中選擇cpp文件,并
從vscode菜單:終端-》運(yùn)行任務(wù),選擇cl.exe,這時(shí)可以生成執(zhí)行文件。

在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》添加配置,選項(xiàng)c++(windows),可以生成調(diào)試所需的json配置,
,自動(dòng)放在文件加下的.vscode下。

{
    // 使用 IntelliSense 了解相關(guān)屬性。 
    // 懸停以查看現(xiàn)有屬性的描述。
    // 欲了解更多信息,請(qǐng)?jiān)L問(wèn): https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "cl.exe - 生成和調(diào)試活動(dòng)文件",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "externalTerminal",
            "preLaunchTask": "C/C++: cl.exe 生成活動(dòng)文件"
        }
    ]
}

修改其中的"stopAtEntry": true,,那么可使在調(diào)試時(shí)逐句執(zhí)行。

在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》啟動(dòng)調(diào)試,則可進(jìn)入調(diào)試。

從調(diào)試欄中選擇單步跳過(guò),不斷執(zhí)行,可以在左側(cè)欄中看到變量的變化。

結(jié)果為:
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

5.3 intel 編譯器

將c++編譯器更改為intel編譯可以進(jìn)行編譯和運(yùn)行。但目前無(wú)法使用oneapigdb進(jìn)行調(diào)試(估計(jì)以后這個(gè)問(wèn)題會(huì)解決。)

首先設(shè)置c++編譯器:
從vscode菜單:查看-》命令面板,選擇C/C++ 編輯配置,找到編譯器路徑,設(shè)置為指定的intel編譯器:
D:/Program Files/intel/compiler/latest/windows/bin/intel64/icl.exe

如此可以得到一個(gè)c_cpp_properties.json自動(dòng)放在.vscode目錄下。
內(nèi)容為:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "D:/Program Files/intel/compiler/latest/windows/bin/intel64/icl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

從vscode菜單:終端-》配置默認(rèn)生成任務(wù),選擇C/C++: icl.exe 生成活動(dòng)文件,會(huì)生成tasks.JSON,自動(dòng)放在文件加下的.vscode下。
其內(nèi)容為:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: icl.exe 生成活動(dòng)文件",
            "command": "D:/Program Files/intel/compiler/latest/windows/bin/intel64/icl.exe",
            "args": [
                "-fdiagnostics-color=always",
                "/Zi",
                "/Od",
                "/Z7",
                "/debug:all",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:/Program Files/intel/compiler/latest/windows/bin/intel64"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "編譯器: \"D:/Program Files/intel/compiler/latest/windows/bin/intel64/icl.exe\""
        }
    ]
}

在編輯器中選擇cpp文件,并
從vscode菜單:終端-》運(yùn)行任務(wù),選擇icl.exe,這時(shí)可以生成執(zhí)行文件。

在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》添加配置,選項(xiàng)oneapi,可以生成調(diào)試所需的json配置,
,自動(dòng)放在文件加下的.vscode下。
在編輯器中選擇cpp文件,并
從vscode菜單:運(yùn)行-》啟動(dòng)調(diào)試,則可進(jìn)入調(diào)試,但實(shí)際只能執(zhí)行而無(wú)法調(diào)試。
測(cè)試表明windows下無(wú)論gdb-oneapi、gdb都無(wú)法進(jìn)行有效調(diào)試,直接在命令行下執(zhí)行也不行。

結(jié)果為:
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

這個(gè)調(diào)試問(wèn)題目前看windows下是沒(méi)有解決的。從如下問(wèn)題可以看到。

【How do I read files with gdb-oneapi, Intel’s debugger, on Windows?】
【Debugging Intel C++ compiled code with GDB】
【Intel’s oneapi C compiler not producing debug information [duplicate]】

5.4 命令行g(shù)db調(diào)試

這里只介紹簡(jiǎn)單的命令:
進(jìn)入調(diào)試:

gdb execfile

或者

gdb 
file execfile
symbol-file symbofile

執(zhí)行:

run

列出源代碼:

list

加入斷點(diǎn)

break linenumber

逐步執(zhí)行:

step

6. 使用vscode和cmake及gnu和ms編譯器編譯調(diào)試c++程序

6.1 gnu編譯器

使用一般的命令行,進(jìn)入當(dāng)前c++程序所在的文件夾,使用命令:

code .

打開(kāi)vscode。

從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:配置,自動(dòng)進(jìn)行cmake配置。

從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:生成,編譯程序。

從左側(cè)文件欄可以看到生成了執(zhí)行程序main.exebuild目錄下面。

執(zhí)行程序,只要在終端進(jìn)入build目錄,直接輸入main.exe回車(chē)即可。

cmake調(diào)試程序,首先需要插入斷點(diǎn),然后從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:調(diào)試,對(duì)程序進(jìn)行調(diào)試,從調(diào)試欄中選擇單步跳過(guò),不斷執(zhí)行,可以在左側(cè)欄中看到變量的變化。

結(jié)果為:
windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

6.2 ms編譯器

使用命令行Developer Command Prompt for VS 2019,進(jìn)入當(dāng)前c++程序所在的文件夾,使用命令:

code .

打開(kāi)vscode。

從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:配置,自動(dòng)進(jìn)行cmake配置。

從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:生成,編譯程序。

從左側(cè)文件欄可以看到在build目錄下,debug目錄下生成了執(zhí)行程序main.exe。

在終端進(jìn)入改目錄,直接輸入main.exe回車(chē)即可執(zhí)行程序。

cmake調(diào)試程序,首先需要插入斷點(diǎn),然后從vscode菜單:查看-》命令面板,輸入cmake,選擇cmake:調(diào)試,對(duì)程序進(jìn)行調(diào)試,從調(diào)試欄中選擇單步跳過(guò),不斷執(zhí)行,可以在左側(cè)欄中看到變量的變化。

結(jié)果為:

windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試

7. 小結(jié)

本文初步總結(jié)了windows下使用不同編譯器編譯c++和fortran程序的方法,以及結(jié)合vscode和cmake進(jìn)行調(diào)試的方法,為windows下c++程序和fortran程序編譯提供示范。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-447102.html

參考

  1. https://code.visualstudio.com/docs/cpp/cmake-linux#_create-a-cmake-hello-world-project
  2. https://devblogs.microsoft.com/cppblog/cmake-tools-extension-for-visual-studio-code/
  3. https://blog.csdn.net/u013525455/article/details/52813637

到了這里,關(guān)于windows下使用microsoft、intel、gnu不同編譯器利用cmake和vscode對(duì)c++和fortran程序進(jìn)行編譯和調(diào)試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 嵌入式C語(yǔ)言自我修養(yǎng)《GNU C編譯器擴(kuò)展語(yǔ)法》學(xué)習(xí)筆記

    嵌入式C語(yǔ)言自我修養(yǎng)《GNU C編譯器擴(kuò)展語(yǔ)法》學(xué)習(xí)筆記

    目錄 一、C語(yǔ)言標(biāo)準(zhǔn)和編譯器 二、指定初始化 三、宏構(gòu)造“利器”:語(yǔ)句表達(dá)式 四、typeof與container_of宏 五、零長(zhǎng)度數(shù)組 六、屬性聲明:section? 七、屬性聲明:aligned? C語(yǔ)言標(biāo)準(zhǔn)的發(fā)展過(guò)程: ● KR C. ● ANSI C. ● C99. ● C11. 指定初始化結(jié)構(gòu)體成員: ????????和數(shù)組類(lèi)似,

    2024年02月08日
    瀏覽(24)
  • 【Intel Parallel編譯器(icc icpc ifort)Linux-centos7系統(tǒng)安裝配置】

    【Intel Parallel編譯器(icc icpc ifort)Linux-centos7系統(tǒng)安裝配置】

    @(toc) 本篇文章主要講解在linux系統(tǒng)centos7.5/centos7.9版本中,Intel編譯器的安裝、環(huán)境導(dǎo)入、并行庫(kù)調(diào)用以及在不同centos版本中安裝時(shí)缺少32位庫(kù)的解決方案等內(nèi)容。 一、★Intel編譯器定義 Intel Parallel Studio XE Cluster版C/C++ Fortran編譯器,是一種主要針對(duì)Inetl平臺(tái)的高性能編譯器,可

    2024年02月09日
    瀏覽(23)
  • Microsoft的CL編譯器與GCC到底有什么區(qū)別?

    gcc -v : gcc version 11.2.0 (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) cl : 用于 x64 的 Microsoft (R) C/C++ 優(yōu)化編譯器 19.29.30136 版 CL作為微軟的非開(kāi)源編譯器,聽(tīng)上去似乎比開(kāi)源的GNU套件GCC編譯器更“高級(jí)”,但事實(shí)真的如此嗎? 咱們統(tǒng)一使用普遍的x64架構(gòu),看看兩個(gè)編譯器對(duì)同一段

    2024年02月05日
    瀏覽(23)
  • 不同版本的 .NET Framework 下的 csc編譯器的版本

    以下是不同版本的 .NET Framework 下的 csc.exe 編譯器的版本: .NET Framework 2.0 - 3.5: csc.exe 版本:2.0.xxxxxx .NET Framework 4.x: .NET Framework 4.0: csc.exe 版本:4.0.xxxxxx .NET Framework 4.5 - 4.8: csc.exe 版本:4.0.xxxxxx .NET Framework 4.5.1 以及更新版本(4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8): csc.exe 版本

    2024年02月12日
    瀏覽(20)
  • CS0656 缺少編譯器要求的成員“Microsoft.CSharp..........Create

    錯(cuò)誤?? ?CS0656?? ?缺少編譯器要求的成員“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create” 問(wèn)題出現(xiàn)原因: 使用動(dòng)態(tài)類(lèi)型dynamic,在編譯的時(shí)候提示錯(cuò)誤信息如上。 解決方案: 1.不用dynamic類(lèi)型 2.在使用的地方添加一個(gè)dll,Microsoft.CSharp,或者用nuget添加Microsoft.CSharp即可

    2024年02月11日
    瀏覽(22)
  • CS0656 C# 缺少編譯器要求的成員“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create”

    CS0656 C# 缺少編譯器要求的成員“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create”

    剛剛由于在代碼中使用了dynamic動(dòng)態(tài)類(lèi)型,項(xiàng)目就起不來(lái)了 報(bào)了如下錯(cuò)誤: CS0656 C# 缺少編譯器要求的成員“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create” 解決辦法如下: 或者通過(guò)dotnet命令 2.不使用dynamic類(lèi)型。定義需要的類(lèi)型

    2024年02月15日
    瀏覽(45)
  • 【開(kāi)發(fā)環(huán)境】Windows下搭建TVM編譯器

    【開(kāi)發(fā)環(huán)境】Windows下搭建TVM編譯器

    關(guān)于搭建TVM編譯器的官方文檔:Install from Source — tvm 0.14.dev0 documentation (apache.org) 1. 安裝Anaconda 首先我們需要安裝Anaconda,因?yàn)槠渲邪覀兯枰母黝?lèi)依賴: 進(jìn)入Anaconda官網(wǎng)https://www.anaconda.com/products/distribution,下載Windows版本,下載完成后運(yùn)行.exe, 可以更改安裝路徑(

    2024年02月15日
    瀏覽(24)
  • Windows下QT Creator安裝MinGW 32bit編譯器

    Windows下QT Creator安裝MinGW 32bit編譯器

    ??注:本作者是基于FFmpeg開(kāi)發(fā)需要,故在Windows下QT Creator中安裝MinGW 32bit編譯器!其它型號(hào)編譯器參照此文章基本可以實(shí)現(xiàn)! 1、下載鏈接 鏈接: 2、下載后的文件(Qt路徑下包含:5.12.0文件和Tools文件): 1、將:Qt/Tools/mingw730_32拷貝到QT Creator安裝路徑下的Tools文件下 2、將:

    2024年02月14日
    瀏覽(29)
  • Windows的cmd運(yùn)行編譯器(cmd運(yùn)行c/c++、python等)

    Windows的cmd運(yùn)行編譯器(cmd運(yùn)行c/c++、python等)

    目錄 一、cmd.exe 二、cmd.exe運(yùn)行編譯器gcc.exe/g++.exe執(zhí)行C/C++程序代碼 三、gcc.exe與g++.exe的區(qū)別及其使用注意事項(xiàng) 1、文件格式問(wèn)題 2、標(biāo)準(zhǔn)庫(kù)問(wèn)題 3、語(yǔ)法規(guī)范問(wèn)題 4、extern \\\"C\\\"聲明問(wèn)題與重載函數(shù)(overloaded function) 四、cmd運(yùn)行python解釋器執(zhí)行python程序代碼 ? ? ? 前面我們已講述了

    2024年02月04日
    瀏覽(20)
  • 【linux】編譯器使用

    【linux】編譯器使用

    目錄 1. gcc ,g++ 編譯器使用 a. 有關(guān)gcc的指令(g++同理) 2. .o 文件和庫(kù)的鏈接方式 a. 鏈接方式 b. 動(dòng)態(tài)庫(kù) 和 靜態(tài)庫(kù) 優(yōu)缺點(diǎn)對(duì)比 c. debug 版本 和 release 版本 注意: linux下自帶gcc編譯器,如果要安裝g++編譯器; sudo yum install -y gcc-g++ (普通用戶) gcc + 文件名 得到可執(zhí)行文件 gcc + 文

    2024年04月26日
    瀏覽(28)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包