Im a linux user for quite sometime,
Im wondering what does compile does?
does it matter if I compile a file in a different folder location?
is installing by compiling is better than rpms??
thanks in advance, im just curious
This is going to be a long story as it touches a lot of computer basics.
There are two types of computer languages: interpreted one and compiled ones.
Interpreted languages (shells, pyton, PHP) are read by their interpreter, parsed and executed. So every time you run such a program the complete interpretation, until the machine instructions the CPU works, with is done from the source of the program.
Compiled languages (Fortran, C, C++) are ‘translated’ from source to an object form. A bunch of objects is then linked together and linked to libraries (static or dynamic) to make an executable program. The executable more or less contains machine code that can be executed directly by the CPU. Much more efficient because you compile once and excute many times. But an executable runs only on the CPU (family) where it is compiled for and it may depend on the availability of the dynamicaly linked libraries on the system.
Now the whole process of generating the executables of a product from the source, which includes one or more steps of compiling, linking and others) is called ‘compiling’ or better ‘building’ as a general term. To make a product to compile on different architectures, and to make it as independent of different libraries (versions) extra steps are included to find out aboute these parameters and this influences the whole process. Also one tries to make the process dependent of the fact that it is not needed to compile/link everything when only one source file has changed (this needs tables with dependencies which are interpreted by the make program).
Part of the making of a distribution of Linux lays in the fact that when you know about the system you are compiling for (e.g. openSUSE 11.0 for a 32 bit i586) can then generate (compile) the whole product on a system and copy the results to every system that fits the requirements. The form that is used to do this copying for openSUSE is the RPM (not restricted to openSUSE though).
With this knowledge we can think about: what is better.
When you just want the product and want it as stable as possible I would go for an install (of an RPM) from the openSUSE repositories. They are build (and often tested) against the distribution the repo belongs to.
Next comes the RPM from other sources like Packman. They are often also build against a specific distribution, when not, they may function, please try.
When no RPM is found, or when you want the newest sources from the project, or when you want to make changes to the source you can go for building yourself. Mostly you will download a tarball (all source files of a product put together and compressed by the tar utility). You normaly put this tarball in a directory made by yourself for working on this product, untar it there (which will normaly create a directory with a version number so in the course of time you can have several in this product directory). Then you go to this directory, read the README file and call make to build (or compile) the product. Be prepared for a long list of remarks, warnings and errors. In the end it will tell you if it build OK or not. When not study the lines above it to find out if you miss a library (or even the compiler), correct and make again. This can (and thus should) all be done as a normal user. Why would you do this in a different directory (directory is I think what you call a folder)? When you want another place, move the whole bunch to that other place.
Installing the result of the build is sometimes done as a normal user, but normaly you will install for all users in the system in the normal system directories, so you need to be root. Again, the product will have the places where everything goes build in somewhere. The README (or searching through the sources by yourself) may tell you where it goes (like /usr/bin and /etc or /usr/local/bin) and how to change this.
Just compiling (and linking) a piece of code written by yourself will go where you send it, but I do not think this is what want to talk about. Because when you wite your own C++ you will also know how to call the C++ compiler.
Hope this clarifies it a bit.
Thanks Henk van Velden for the effort on answering my question
well i thought that like on windows, you can point the files where you want to install them(if you dont want it on your Program Files folder). Unlike on linux, when you compile something, it will generate the files needed or edit the files on the system directory(that’s what i think ) e.g. /lib
even i execute the ./configure, make, make install on /home/gian folder
sometimes im hesitant to compile and install something because it might conflict with other programs
like mp3, before i have so much problem on putting the mp3 player to work.
i was not interested on linux before until i graduated and became a programmer(PHP). because apache is natively on linux and most apache web server are on linux boxes, linux is realy beautiful OS but different to understand
I like to learn C++ is the same with the c++ on windows?
can you recommend books specially on OOP, im a ASP, PHP programer now
C++ is a programing language, a concept. Works everywhere. Just be sure to handle the OS specific calls. But for a beginner will not be needed i think:)
If you like to start learnig C++ thats a very good book: Accelerated C++
For compiler, stick with GCC : GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) (almost all linux distos have it, or offer the right packages)
For windows try Mingw(GCC windows port): MinGW | Minimalist GNU for Windows
For anything else: GCC toolchain:)
As for IDE, i would recomand Eclipse CDT: Eclipse.org home (get the C/C++ one). Is cross platform also.
But, by far, stick with your simple makefiles, or get SCons, is much simple for begining to build your lessons.
The place where products are is different from the place in e.g. a menu (K menu comes to mind) where you want to call them when you are using a GUI. I do not know much of Windows, but Ithink you should forget a lot of the (mis)concepts of Windows when using Linux. Often when you install products where the developer thinks it obvious it should be called from KDE or Gnome it will install an item in the appropriate place in the menu complete with a nice icon. You can rearange those entries with the menu editor without being concerned where the program is.
The reason why e.g. a products executable program goes into /bin and its config file in /etc is partly historical, but it also has its pros.
Just an example. When you have a small system you can have its /bin NFS mounted readonly from another system (and thus share the executable with many systems), but have the config file in /etc localy (so everyone of those systems has its own configuration to be used with the program).
thanks again mate,
actually my win xp is broken right now, and it has something to do with ntldr or something, I have no interest on fixing it right now, I can play music and movies in my suse box,I guess ill fix my winxp when i have COD4 for now ill study c++, php and java
thanks for the links man
uhm how do i compile
there where errors when i type
cpp: error trying to exec 'cc1plus': execvp: No such file or directory
cc: error trying to exec 'cc1plus': execvp: No such file or directory
im just excited on learning this
i can now compile the source code.
How can compile the cc or cpp codes then run it
without making the make file?
Are you trying to compile your own C or C++ program that you wrote, or are you trying to install a program now?
Im trying to compile my own C or C++ programs
Using gnu C++ compiler it is simple to compile and execute your own files.
Create an executable
Then you must execute your compiled program with ./a.out
That is a basic run down. For linking libraries and compiling to a file with a different name and many other things man g++ can be very useful.