How do I compile c++ for Linux?
I'm a newbie learning c++ and it's quite addicting...
However, due to some programs not yet working in *nix (3dsmax etc), I'm stuck with Vista on my laptop. I'm programming using Code::Blocks, and when I compile it exports as .exe. I don't recall Ubuntu being able to handle .exe files, so how do I compile my c++ programs such that I can run them on Ubuntu? Bonus points if one file runs on both :P Thanks, -SimbaSpirit |
Use g++. It is a free C++ compiler.
|
Quote:
If we leave outside emulators and similar software. To install the c++ compiler, you need to install gcc, and probably g++, depending on the distro. To compile a c++ program, you'd do Code:
g++ file.cpp -o progname |
I remember telling it to use gcc for compilation, and I know that linux can't run .exe files ( as i mentioned earlier ). The question is, how do I make the code::blocks that is running on my WINDOWS machine compile my program so that it can be run on a LINUX machine?
|
Quote:
I can't really help you with either of these, other than pointing the options as I did. |
But why compiling linux code on a windows box? Code::blocks is available under Linux, and you can find more free open source IDE...
|
The GNU compiler can do cross compilation - compiling progams on one system which are to run on another system type. It is possible to build windows .exe files with a compiler running on Linux. However, it's fiddly. Don't expect that you can change a single setting in a Makefile and that will be all that is needed.
On Ubuntu, the packages you need to do this are mingw32, mingw32-binutils and mingw32-runtime. It may be possible to do the reverse, running the compiler on a Windows platform, but I have never tried it. Like I said though, it's no walk in the park. |
To elaborate on what the last poster stated: I've run it on windows, so I can confirm that you can do the same (or really vice versa) on windows also.
Also, as stated you'll need to make sure you're computers are using cross compliant code. For instance, if the application in question is a GUI use GTK instead of MFC's builtin controls. It's a pain in the rear, but it's a good practice to get use to. |
If you build your program using a decently cross-platform like QT, the amount of platform conditional sections will be minimal. There is still likely to be the odd section of code which must be platform specific however.
|
All times are GMT -5. The time now is 09:24 AM. |