C++ 如何使用makefile在visual studio中编译代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15803738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:46:38  来源:igfitidea点击:

How to compile code with visual studio using makefile

c++visual-studiomakefile

提问by Hossein Dolatabadi

I have just downloaded a open source project which is said to be compiled using visual studio c++. It contains 3 makeFiles (makeFile, makeFile(1) and makeFile(2) ) I always open programs in VS using the .sln files and now I dont know what to do with this makeFile. can anyone instruct me how to deal with it please.

我刚刚下载了一个开源项目,据说是使用 Visual Studio C++ 编译的。它包含 3 个 makeFile(makeFile、makeFile(1) 和 makeFile(2))我总是使用 .sln 文件在 VS 中打开程序,现在我不知道如何处理这个 makeFile。任何人都可以指示我如何处理它。

regards

问候

回答by ap-osd

If you are only familiar with Visual Studio projects and solutions, dealing with makefiles can be a challenge. The following link will give you a good introduction to makefiles from a Visual studio perspective.

如果您只熟悉 Visual Studio 项目和解决方案,则处理 makefile 可能是一个挑战。以下链接将从 Visual Studio 的角度很好地介绍 makefile。

An introduction to Makefiles for Visual Studio developers

面向 Visual Studio 开发人员的 Makefile 简介

Translating Linux makefiles to Visual Studio solution will be a manual effort.

将 Linux 生成文件转换为 Visual Studio 解决方案将是一项手动工作。

NMakelooks promising. However, the following link takes a simple Makefileand explains some fundamental issues that one may encounter.

NMake看起来很有希望。但是,以下链接采用了一个简单的方法,Makefile并解释了人们可能会遇到的一些基本问题。

Makefiles in Windows

Windows 中的 Makefile

回答by Vivek Jain

You may try NMake. See NMake Referenceand Stackoverflowpost.

你可以试试NMake。请参阅NMake 参考Stackoverflow帖子。

NMake is included with Visual Studio. You may try with NMake shipped with the edition of Visual Studio you may want to use.

NMake 包含在 Visual Studio 中。您可以尝试使用随您可能想要使用的 Visual Studio 版本一起提供的 NMake。

回答by Soleil - Mathieu Prévot

VS2017 and cross-platform dev with makelinux binaries

VS2017 和带有makelinux 二进制文件的跨平台开发

If you're working on windows 10, you can make makework and compile linux binaries:

如果您在 Windows 10 上工作,则可以进行make工作并编译 linux 二进制文件:

  • have lxss installed, and gdb server, ssh server installed:

    sudo apt update && sudo apt install -y build-essential gdbserver openssh-server

  • make sure you can connect through ssh to your local machine:

    sudo vi /etc/ssh/sshd_config && sudo service ssh start

  • make sure you have linux development with c++packages installed (VS2017 install)

  • make sure you configured your connexion to lsxx through ssh in VS/tools/options/connection manager ("connection" in search).

  • make sure to have a linux project (new project/other languages/vc++/crossplatform/linux)

  • yet, add you makecommands in project/properties.

  • 安装了 lxss,并安装了 gdb 服务器、ssh 服务器:

    sudo apt update && sudo apt install -y build-essential gdbserver openssh-server

  • 确保您可以通过 ssh 连接到本地计算机:

    sudo vi /etc/ssh/sshd_config && sudo service ssh start

  • 确保你已经安装了 c++包的linux 开发(VS2017 安装)

  • 确保您在 VS/tools/options/connection manager 中通过 ssh 将连接配置为 lsxx(搜索中的“连接”)。

  • 确保有一个 linux 项目(新项目/其他语言/vc++/crossplatform/linux)

  • 然而,make在项目/属性中添加你的命令。

回答by Attila

I've just run into the same problem and for me the solution: open "VS2012 Native Command Prompt" the name varies over different versions of MSVS. then simply type 'nmake makefile.vc'. nmake is the command, makefile.vc is your own makefile in your local folder. and it is done (if no further errors occur)

我刚刚遇到了同样的问题,对我来说解决方案是:打开“VS2012 Native Command Prompt”,名称因 MSVS 的不同版本而异。然后只需输入'nmake makefile.vc'。nmake 是命令,makefile.vc 是您在本地文件夹中自己的 makefile。并完成(如果没有进一步的错误发生)