Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ compiler that runs on windows and generates Linux code

I'm just curious if this is posible: Is there C++ compiler that runs on windows and can generate Linux code?

like image 239
x1234x Avatar asked Dec 22 '10 19:12

x1234x


People also ask

Which C compiler is used in Linux?

GCC compiler is used to compile and run a C program on the Linux operating system. We can use the in-build text editor or other editors like Visual Studio Code or Sublime Text to write our C Programs.

Which C compiler is used in Windows?

If you want to run C or C++ programs in your Windows operating system, then you need to have the right compilers. The MinGW compiler is a well known and widely used software for installing GCC and G++ compilers for the C and C++ programming languages.

Can a program compiled on Linux run on Windows?

Is there a way to compile the program on Linux (i.e. Ubuntu) is such a way that the .exe file can just run on Window without any need to recompile it on Windows? Yes. To build a program on linux which runs on Windows, you need to use a cross-compiling tool chain which builds code with links to Windows run-times.


2 Answers

The g++ cross compiler can do that.

See http://metamod-p.sourceforge.net/cross-compiling.on.windows.for.linux.html.

like image 131
Frédéric Hamidi Avatar answered Oct 20 '22 01:10

Frédéric Hamidi


Absolutely it's possible. You need a compiler that can handle cross-compilations and then specify the target. The key point is to get a compiler that's capable of creating the binary files in a manner required by the target system. g++ would do just that for you.

I worked on a project where we used linux to create embedded arm executables using their C compiler, and then used scp to copy it over for testing.

like image 28
Kieveli Avatar answered Oct 20 '22 01:10

Kieveli