简体   繁体   中英

Compile C code in Visual Studio in Windows for Linux

I'm using Visual Studio in Windows to develop basic C applications. I want to compile my code for Linux, without the need to have Linux installed on my machine. Is that possible ? And how ?

yes, it is possible. Have a look at this stackoverflow question.

  1. Install WLS on your Windows machine
  2. Use the standard gcc instruction (or, better, Makefiles and/or 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. 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 .

The following blog and document links are a good place to start.

Similarly, Visual Studio Code has some support for this as well:

Sincerely,

You can install a VM (virtual machine) on your windows computer, then install linux on the virtual machine.

Note: both the VM and linux are free downloads

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