Youssef13
Youssef13

Reputation: 4944

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 ?

Upvotes: 2

Views: 2793

Answers (3)

Ed Dore
Ed Dore

Reputation: 2109

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,

Upvotes: 1

Leos313
Leos313

Reputation: 5627

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

Upvotes: 1

user3629249
user3629249

Reputation: 16540

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

Upvotes: -1

Related Questions