简体   繁体   English

如何将Visual Studio for Windows中制作的C ++解决方案转移到Visual Studio for Mac?

[英]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 ++编译器**

  1. Create a folder yourDirectoryName 创建一个文件夹yourDirectoryName
  2. create a file main.cpp (you can copy and paste your codes in here) 创建一个文件main.cpp(您可以在此处复制和粘贴代码)
  3. create a file json file ** go to the top bar on visual studio, select Terminal > configure Default Build Task > select other** 创建文件json文件**转到Visual Studio的顶部栏,选择终端>配置默认生成任务>选择其他**

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.

相关问题 如何使用 Visual Studio Code 从 Visual Studio 2019 构建、调试和运行现有的 C++ 解决方案 (.sln)? - How do I use Visual Studio Code to build, debug and run existing C++ solution (.sln) from Visual Studio 2019? 无法将Visual Studio制作的C ++ DLL导入Windows上的Visual Studio C#项目 - Unable to Import a Visual Studio made C++ DLL into a Visual Studio C# Project on Windows 如何将字符串值从 C++ 返回到 javascript (windows/Visual Studio 2008)? - How do I return a string value from C++ to javascript (windows/Visual studio 2008)? 如何在 Windows 上使用 Visual Studio 2017 连接到 C++ 中的 sqlite 数据库? - How do I connect to an sqlite database in C++ using visual studio 2017 on Windows? 如何告诉 Visual Studio 我的 header 应该是 C++ 而不是 C? - How do I tell Visual Studio that my header should be C++ and not C? 如何使Visual Studio 2015 C ++项目与Visual Studio 2010兼容? - How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010? 如何在 Visual Studio 2017 中无错误地打开 Visual Studio 2019 c++ 代码? - How do i open Visual Studio 2019 c++ code in Visual Studio 2017 without errors? 如何在 Visual Studio 中打开 C++ 项目文件夹? - How do I open a c++ project folder in visual studio? 如何在 Visual Studio C++ 中增加堆栈大小? - How do I increase the stack size in Visual Studio C++? 如何安装此控制台库? Visual Studio C ++ - How do I install this console library? visual studio c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM