[英]How do I transfer my C++ solution made in Visual Studio for Windows to Visual Studio for Mac?
I made a multiple solutions with C++ in Visual Studio at a tech camp on a Windows computer. 在Windows计算机的技术营地中,我使用Visual Studio中的C ++开发了多种解决方案。 Unfortunately, I do not have a windows computer at home, so I tried using Visual Studio for Mac 2019. This alert shows up whenever I try to run any of my solutions that says "This project type is not supported by Visual Studio Community 2019 for Mac. When I build the solution, it says it the build is successful, but the run with or without debugging options are grayed out. How can I fix this?
不幸的是,我家里没有Windows计算机,因此我尝试使用Visual Studio for Mac 2019.当我尝试运行任何说``Visual Studio Community 2019不支持此项目类型的解决方案''时,都会显示此警报。 Mac。构建解决方案时,它表示构建成功,但是带有或不带有调试选项的运行均呈灰色显示,如何解决此问题?
I was able to get it to work using a Windows 10 Parallels, and it said it needed to update the solution because I had made it in Visual Studio 2017. I updated it and it worked, but my program runs very slow. 我能够使用Windows 10 Parallels使它工作,并且它说它需要更新该解决方案,因为我是在Visual Studio 2017中制作的。我对其进行了更新并且可以工作,但是我的程序运行非常慢。 After doing this, it still does not work on Visual Studio for Mac.
完成此操作后,它仍无法在Mac的Visual Studio中运行。
Here is my main .cpp file named MyFirstProgram.cpp: 这是名为MyFirstProgram.cpp的主要.cpp文件:
#include "pch.h"
#include "Main.h"
#include <string>
using namespace std;
int main()
{
cout << "My header file works!" << endl;
}
The pch.cpp file: pch.cpp文件:
#include "pch.h"
The pch.h file: pch.h文件:
#ifndef PCH_H
#define PCH_H
#endif //PCH_H
And the Main.h file: 和Main.h文件:
#pragma once
#include <iostream>
#include <string>
To build your C++ project using Visual Studio code on Mac, ensure you have C/C++ build tools installed. 要在Mac上使用Visual Studio代码构建C ++项目,请确保已安装C / C ++构建工具。
Go to your Marketplace on Visual studio, Click on view, select Extensions. 转到Visual Studio上的市场,单击视图,选择扩展。 Type C++ on the search, and select the extension by Microsoft and install
在搜索中键入C ++,然后选择Microsoft扩展名并安装
Create a new project 创建一个新项目
Copy and paste your codes in a new main.cpp and MyFirstProgram.cpp file. 将代码复制并粘贴到新的main.cpp和MyFirstProgram.cpp文件中。
Try rebuilding 尝试重建
Alternatively, you can use Xcode or Jetbrain CLion on Mac 或者,您可以在Mac上使用Xcode或Jetbrain CLion
Another trick to build your cpp program on Mac or Linux without using any heavy IDEs is building a simple task file 在不使用任何笨重的IDE的情况下在Mac或Linux上构建cpp程序的另一个技巧是构建一个简单的任务文件
**Mac has a g++ compiler ** ** Mac具有g ++编译器**
it would create a hidden json file for you. 它将为您创建一个隐藏的json文件。 modify the json file to run your main.cpp file
修改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"
],
}
]
}
The task is called run . 该任务称为run 。
to run it, go to terminal, select run task. 要运行它,请转到终端,选择运行任务。 click on the task run > continue without scanning the task output
单击任务运行 > 继续而不扫描任务输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.