Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Compiling in Linux
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
saltpro15




PostPosted: Thu Feb 12, 2009 3:36 pm   Post subject: Compiling in Linux

so I started some programming in Ubuntu, got a great IDE called anjuta, and I just have some questions, call it a learning experience instead of just hitting a button. Why are files .cxx and not .cpp? how does compiling work, since linux can't run .exe's?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Feb 12, 2009 3:44 pm   Post subject: RE:Compiling in Linux

I believe ubuntu comes with G++, though I'm not sure. I know you can compile from the terminal, for example, to compile C++, type G++ <filename>. Make sure to navigate to the right folder with the cd command. for interpreted languages or java, type <language><filename>. For example,

>> ruby example.rb

will execute the file example.rb through the ruby interpreter.
saltpro15




PostPosted: Thu Feb 12, 2009 3:45 pm   Post subject: RE:Compiling in Linux

ah, thanks, just trying to wrap my head around this
DemonWasp




PostPosted: Thu Feb 12, 2009 4:09 pm   Post subject: RE:Compiling in Linux

It doesn't matter so much what your files are called, as there are a few extensions that C++ allows, including .cxx, .cpp, .c, .cc, .C and so on. I'm not aware of any real distinguishing factor, save that C++ should be .cpp or .cxx while C should be .cc or .c .

Just try something like:
code:
g++ file.cpp -o executableName


With your own file substituted in. You can skip the -o executableName bit; if you do, it defaults to "a.out".

You are correct that Linux cannot run .exe files, as those are Windows-specific compiled files. However, UNIX operating systems do have their own binary executable format. These files are identified by the file contents as well as by the permissions on the file rather than by the extension (you must have "execute permission", and the OS must know how to execute the file - it knows how to execute shell scripts and compiled code, for example).

Here's an example of compiling a simple program:

file.cpp
code:

#include <iostream>
int main ( int argc, char ** argv ) {
    std::cout << "Hello World" << std::endl;
}


At your terminal (note: do not type the $, that's the symbol for "prompt"):
code:

$ g++ file.cpp -o myFile
$ ./myFile
Hello World
$


For interpreted languages, insectoid is quite right.
OneOffDriveByPoster




PostPosted: Thu Feb 12, 2009 8:05 pm   Post subject: Re: RE:Compiling in Linux

DemonWasp @ Thu Feb 12, 2009 4:09 pm wrote:
It doesn't matter so much what your files are called, as there are a few extensions that C++ allows, including .cxx, .cpp, .c, .cc, .C and so on. I'm not aware of any real distinguishing factor, save that C++ should be .cpp or .cxx while C should be .cc or .c .
Actually, .cc and .C are usually C++ and not C.
wtd




PostPosted: Thu Feb 12, 2009 8:20 pm   Post subject: RE:Compiling in Linux

A few common file extension conventions:

C: .h and .c
C++: .h and .cpp
Obj-C: .h and .m
Perl: .pl and .pm
Python: .py
Ruby: .rb
Java: .java and .class
C#: .cs and .exe
Shell scripts: .sh
Scala: .scala and .class
O'Caml: .ml
Haskell: .hs
saltpro15




PostPosted: Thu Feb 12, 2009 8:24 pm   Post subject: RE:Compiling in Linux

ok, I'm just wondering, if I create a game in linux and put it up on compsci, will people with windows be able to run it?
wtd




PostPosted: Thu Feb 12, 2009 9:07 pm   Post subject: RE:Compiling in Linux

If you publish the source code, yes.
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Thu Feb 12, 2009 9:08 pm   Post subject: RE:Compiling in Linux

Only if you post the source code. Compiled Linux binaries won't work in Windows.
saltpro15




PostPosted: Thu Feb 12, 2009 9:10 pm   Post subject: RE:Compiling in Linux

alright, thanks for the info guys
DemonWasp




PostPosted: Thu Feb 12, 2009 9:45 pm   Post subject: RE:Compiling in Linux

Further note: you have to use libraries that are available on all the systems you want to run on. The standard C/C++ libraries are available on most modern operating systems, but if you're looking at GUI components and such extensions to the language, you need to look more carefully.

If you don't want to post source code, you could also just compile the code on every major OS/architecture group you want to provide support for. A lot of open-source projects do this for their user's convenience, so their users don't have to run makefiles or compile the product manually.
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: