简体   繁体   English

在 Windows for Linux 中的 Visual Studio 中编译 C 代码

[英]Compile C code in Visual Studio in Windows for Linux

I'm using Visual Studio in Windows to develop basic C applications.我在 Windows 中使用 Visual Studio 来开发基本的 C 应用程序。 I want to compile my code for Linux, without the need to have Linux installed on my machine.我想为 Linux 编译我的代码,而无需在我的机器上安装 Linux。 Is that possible ?那可能吗 ? And how ?如何 ?

yes, it is possible.对的,这是可能的。 Have a look at this stackoverflow question.看看这个stackoverflow 问题。

  1. Install WLS on your Windows machine在您的 Windows 计算机上安装 WLS
  2. Use the standard gcc instruction (or, better, Makefiles and/or CMake )使用标准的gcc指令(或者更好的Makefiles和/或CMake

Example :示例

Let's say you have your program:假设你有你的程序:

//code within filename.c
#include <stdio.h>

int main(){
    printf("Hello Youssef\n");
    return 0;
}

Then, within the folder, run:然后,在文件夹中,运行:

$ gcc filename.c

and then run it:然后运行它:

$ ./a.out
Hello Youssef

You'll need to have Linux installed somewhere.您需要在某处安装 Linux。 If you can remote to a linux box, vm, or WSL console, from your Visual Studio machine, you can use VS 2019 to build and debug most applications in any of those environments, via the Cross Platform Connection Manager .如果您可以从 Visual Studio 机器远程访问 linux box、vm 或 WSL 控制台,则可以使用 VS 2019 通过跨平台连接管理器在任何这些环境中构建和调试大多数应用程序。

The following blog and document links are a good place to start.以下博客和文档链接是一个不错的起点。

Similarly, Visual Studio Code has some support for this as well:同样,Visual Studio Code 对此也有一些支持:

Sincerely,真挚地,

You can install a VM (virtual machine) on your windows computer, then install linux on the virtual machine.你可以在你的windows电脑上安装一个VM(虚拟机),然后在虚拟机上安装linux。

Note: both the VM and linux are free downloads注意:VM 和 linux 都是免费下载的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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