简体   繁体   中英

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. 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?

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. After doing this, it still does not work on Visual Studio for Mac.

Here is my main .cpp file named MyFirstProgram.cpp:

#include "pch.h"
#include "Main.h"
#include <string>
using namespace std;

int main()
{
    cout << "My header file works!" << endl;
}

The pch.cpp file:

#include "pch.h"

The pch.h file:

#ifndef PCH_H
#define PCH_H
#endif //PCH_H

And the Main.h file:

#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.

  • Go to your Marketplace on Visual studio, Click on view, select Extensions. Type C++ on the search, and select the extension by Microsoft and install

  • Create a new project

  • Copy and paste your codes in a new main.cpp and MyFirstProgram.cpp file.

  • Try rebuilding

Alternatively, you can use Xcode or Jetbrain CLion on Mac

Another trick to build your cpp program on Mac or Linux without using any heavy IDEs is building a simple task file

**Mac has a g++ compiler **

  1. Create a folder yourDirectoryName
  2. create a file main.cpp (you can copy and paste your codes in here)
  3. create a file json file ** go to the top bar on visual studio, select Terminal > configure Default Build Task > select other**

it would create a hidden json file for you. modify the json file to run your main.cpp file

{
       "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 .

to run it, go to terminal, select run task. click on the task run > continue without scanning the task output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM