PDA

View Full Version : how to use g++ on linux?



outer_space
May 6th, 2007, 06:33 PM
On windows it was 'g++ main.cpp -o main.exe'

but on ubuntu exe files dont work. What works?

Thanks.

Auria
May 6th, 2007, 06:37 PM
On windows it was 'g++ main.cpp -o main.exe'

but on ubuntu exe files dont work. What works?

Thanks.

I think you're definitely on the wrong forum. This is not a proposal for Gutsy... just use packages manager to install build-essential

23meg
May 6th, 2007, 07:06 PM
Moved to Programming Talk.

jespdj
May 6th, 2007, 07:19 PM
On windows it was 'g++ main.cpp -o main.exe'

but on ubuntu exe files dont work. What works?

Thanks.

You can give executables any extension you like, or no extension at all. On Linux (and Unix in general), executables usually have no extension. "exe" will work as well as anything or no extension.


g++ main.cpp -o main
./main

Note the the "./" which means, "look in the current directory for the file named 'main'".

WW
May 6th, 2007, 07:24 PM
There is nothing wrong with the example that you gave. If you want to call the executable program "main.exe", you can. However, it is not required to use the .exe extension. In Linux, usually the executable file would just be called "main". For example,


$ g++ main.cpp -o main # Compile main.cpp, call the executable program "main"
$ ./main # Run the program

Of course, this will only work if you have g++ installed. You can install g++, gcc, and some other useful development tools and libraries by installing the package build-essential. You can do this with Synaptic Package Manager, or with the command


$ sudo apt-get install build-essential


EDIT: Heh, looks like I echoed jespdj's response.

outer_space
May 6th, 2007, 08:05 PM
Thanks, this works. I didnt know about './'