[英]How do I use Visual Studio Code to build, debug and run existing C++ solution (.sln) from Visual Studio 2019?
[英]How do I transfer my C++ solution made in Visual Studio for Windows to Visual Studio for Mac?
在Windows计算机的技术营地中,我使用Visual Studio中的C ++开发了多种解决方案。 不幸的是,我家里没有Windows计算机,因此我尝试使用Visual Studio for Mac 2019.当我尝试运行任何说``Visual Studio Community 2019不支持此项目类型的解决方案''时,都会显示此警报。 Mac。构建解决方案时,它表示构建成功,但是带有或不带有调试选项的运行均呈灰色显示,如何解决此问题?
我能够使用Windows 10 Parallels使它工作,并且它说它需要更新该解决方案,因为我是在Visual Studio 2017中制作的。我对其进行了更新并且可以工作,但是我的程序运行非常慢。 完成此操作后,它仍无法在Mac的Visual Studio中运行。
这是名为MyFirstProgram.cpp的主要.cpp文件:
#include "pch.h"
#include "Main.h"
#include <string>
using namespace std;
int main()
{
cout << "My header file works!" << endl;
}
pch.cpp文件:
#include "pch.h"
pch.h文件:
#ifndef PCH_H
#define PCH_H
#endif //PCH_H
和Main.h文件:
#pragma once
#include <iostream>
#include <string>
要在Mac上使用Visual Studio代码构建C ++项目,请确保已安装C / C ++构建工具。
转到Visual Studio上的市场,单击视图,选择扩展。 在搜索中键入C ++,然后选择Microsoft扩展名并安装
创建一个新项目
将代码复制并粘贴到新的main.cpp和MyFirstProgram.cpp文件中。
尝试重建
或者,您可以在Mac上使用Xcode或Jetbrain CLion
在不使用任何笨重的IDE的情况下在Mac或Linux上构建cpp程序的另一个技巧是构建一个简单的任务文件
** Mac具有g ++编译器**
它将为您创建一个隐藏的json文件。 修改json文件以运行main.cpp文件
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"main.cpp",
"-o",
"${yourDirectoryName}"
],
},
{
"label": "run",
"type": "shell",
"command": "./${yourDirectoryName}",
"dependsOn": [
"build"
],
}
]
}
该任务称为run 。
要运行它,请转到终端,选择运行任务。 单击任务运行 > 继续而不扫描任务输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.