New to C++

This is a discussion on New to C++ within the C++ Programming forums, part of the General Programming Boards category; What exactly does a complier do? does it create the file to make the game/program or is it needed to ...

Adding to what alpha said and answering your last question, you technically dont need a compiler to write your code. You can write your code in word or even notpad. however if you want to actually run your code and check for errors and stuff then you would need a compiler.

The computer doesn't understand C++ The compiler translates.

You might have heard someone say that computers only understand ones and zeros (the binary system). In the old days (even before I started programming) programmers actually programmed the ones and zeros. Then, they found it was easy to convert between base-8 and binary. Everything was done with base-8 numbers. So there was some base-8 number that meant "ADD"... and a different number for each "machine language instruction". Nowadays if we're going to use the fundemental numbers, we use base-16 (=hexadecimal = hex).

It didn't take long to figure out how write a program (written with the machine-code instructions) to convert a simple english-like instruction (i.e. ADD) to the machine-language "number". This one-for-one english-like language is called ASSEMBLY LANGUAGE.

Then, they figured-out how to make a program (written in assembly) that could convert more-english-like instructions to machine language. These are COMPILERS and they convert "HIGH LEVEL LANGUAGES" like C++, BASIC, Fortran, Pascal, COBAL, etc.

A compiler takes a single high-level language instruction and converts it into (typically) several machine-language instructions.

So, you write your C++ program and save it as MyProgram.CPP The computer can't "run" your program yet. You process your program through your compiler, and the compiler generates a file named MyProgram.EXE . When you click-on MyProgram.EXE, your program runs and displays "Hello World" on the screen (for example).

Actually, a compiler won't link things automatically. A compiler won't make executables. Compiling AND linking must be done. Most programs which compile will link for you as well, but not necissarily. They are still very separate processes. Not all C++ projects are linked because not all are meant to be executables (IE static link libraries).

The compiler will not link automatically. If you are using an integrated IDE, the IDE, depending on your settings, may run the linker automatically, but if you are using command line tools, like the freebie Borland stuff, you will need to run the linker.

Even using an IDE which handles the linking for you, you may need to specify which libraries you should link with. Something that crops up weekly on the Windows board is "I get a link error when I compile my common controls program", meaning that they have not added comctl32.lib to their linker options.

I agree that using an IDE and a simple Hello World program, knowledge of the mechanisms is not strictly necessary, but that is no real excuse.

My point is that 99% of the time, ONE CLICK (or one command line) and BAM I've "automatically" converted a cpp to an exe.

I assume Prophecy_OD_ is asking because he wants to start programming, not because he wants to write a technical paper. I respect your a knowledge, Polymorphic OOP, and I'm NOT going to get into an argument with you, because that's NOT why I'm here! (I'm here to learn and to help.)

There are two steps: compilation and linking. If you're in DOS, then you do them seperatly. But most IDEs do all that automatically for you. So when you press the 'Go' Button (or 'Run', or F5, or Ctrl-F5, etc ), the IDE will all that for you can boom, the application will run right in front of your eyes if there are no errors.

I appreciate your point, but, start people off with an incorrect premise, and they will have trouble later on, start them right, they won't.

Things like the Borland tools are very commonly used by beginners, because they are free. Unless you are using the make facilities, you will need to compile and link.

One could just as easily ask why bother telling him about the assembler created by the compiler, surely, by your own argument, the compiler does all of that automatically. Again, I am not saying he shouldn't know that.

Yeah, and it's one thing not to mention it at all, but it's another thing to speak of it, but speak of it improperly. It's better to learn something properly and be a little bit confused than it is to learn it improperly and be able to get by for a while and then have to unlearn what you thought was correct. It's best to just make the distinction from the start.

I was searching through the forums trying to find an answer to my question. This thread seemed to answer them. Just one last thing.
Refering to this quote:

adrianxw
Even using an IDE which handles the linking for you, you may need to specify which libraries you should link with.

I'm using a borland compiler, and i don't need to specify the libraries i need to link to, but there are a lot of library files in my lib directory. My question is this:

Is there always one specific library that links to my program?Or
Does the linker search through all the library files until it comes across the one(s) with the correct definitions?Or
is there something ( like the compiler or header files) that specifies certain library files based on the library functions used?Or
Other?