CodeBlocks preprocessor file

This is a discussion on CodeBlocks preprocessor file within the C++ Programming forums, part of the General Programming Boards category; I'm not sure if this is the right place to ask but I'm having trouble finding how to save a ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    48

    CodeBlocks preprocessor file

    I'm not sure if this is the right place to ask but I'm having trouble finding how to save a copy of this intermediate file in codeblocks.

    I'm sure theres a command line flag or something I have to put somewhere but I don't know where or what.

    Can anyone tell me how?

    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What do you think a "CodeBlocks preprocessor file" is?

    If you mean "the result of running the preprocessor without actually doing any compiling", then you need to give the -E flag. It's not a "typical" option, so you'll have to go to "Other options".

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    Yeah I'm talking about the file created before compiling, that substitutes included files and inline functions and such.

    I'm just learning and wanted to look at this file just to see.

    I went into, Settings->Compiler and debugger then the other options tab.

    Is it supposed to be blank? I typed -E and now I receive this error message...

    Code:
    Compiling: C:\Things\Matts\My_Stuff\c++\NewC++Files\16_workshop.cpp
    Linking console executable: C:\Things\Matts\My_Stuff\c++\NewC++Files\16_workshop.exe
    C:\Things\Matts\My_Stuff\c++\NewC++Files\16_workshop.o: file not recognized: File format not recognized
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 0 seconds)
    0 errors, 0 warnings
    Why do I get this error message?

    Is the 16_workshop.o the file Im looking for? is so what do you suggest I view it with?, the formatting is awful in notepad, and if not where is this file saved? and again do I need to open it with something other than notepad?


    sorry again I'm new.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    We didn't bother to change the output name from 16_workshop.o (the .o generally means object file). So that 16_workshop.o is your pre-processed file that you can look at. The error comes from the fact that the linker wanted to finish the job, but recognized that the .o file wasn't really an .o file.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    Ok, thats pretty cool thanks.

    one other thing that I haven't been able to understand is command line parameters.

    Code:
    1: #include <iostream.h>
    2: int main(int argc, char **argv)
    3: {
    4: cout << "Received " << argc << " arguments...\n";
    5: for (int i=0; i<argc; i++)
    6: cout << "argument " << i << ": " << argv[i] << endl;
    7: return 0;
    8: }
    Output: TestProgram Teach Yourself C++ In 21 Days
    Received 7 arguments...
    argumnet 0: TestProgram.exe
    argument 1: Teach
    argument 2: Yourself
    argument 3: C++
    argument 4: In
    argument 5: 21
    argument 6: Days
    Thats an example in the book, I understand kinda whats going on except for where the parameters (arguments?) came from.

    I know when I run that piece of code I am not going to get that output, but I get 1 parameter, the entire filename of my file including the path.

    On the next example there is a conditional test to make sure there are atleast 2 arguments, if didn't say anything about the input of the parameters how could there be more than 1?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You give the command-line parameters on the command line. When you type "TestProgram Teach Yourself C++ In 21 Days" all those things you typed after the name of the program are the command-line parameters. The 0th is always the name of the program. The 1st, 2nd, ..., are the other things on the line: Teach, Yourself, C++, etc.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    I'm sorry I'm a newb where do I type this?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The command line. You know, the thing, where you type? (See below.)

    If for whatever reason you don't want to use the command line, but instead run via your IDE, you'll have to have the IDE put the arguments on the command line for you. In Code::Blocks, I believe that's done with Project->Set programs' arguments, but that only works if you have set up an actual project (and not just a single file).
    Attached Images Attached Images  

  9. #9
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    I'm just using single scripts right now, create new empty file.

    How do I bring up the command line? I type my code into a .cpp file, build and compile. At the end I see 'press any key to exit';

    When do I have time to type in commands?

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    tabstop wasn't referring to the CodeBlocks terminal window. You can write, compile and run programs without using CodeBlocks (or any other IDE) at all. You write the program in any text editor, e.g. Notepad, and save it using any name with a .cpp extension. Then open a command window -- probably under "Accessories" in your Start Program menu, or click Start/Run, type cmd in the "run" box and press enter. A command prompt window will open. There, you navigate to the directory where you saved the .cpp file, then type in your commands to preprocess, compile, link, run, or whatever.

  11. #11
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    that makes a little more sense but I think over my head at this point

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Not really, it's very easy once you get the hang of it. For simple programs it's actually easier to do that than to set up a project in an IDE. Also, it will give you a better understanding of what's actually going on "under the hood", without the security blanket of an IDE.

    For example, completely compiling and linking "myprogram.cpp" can be as easy as typing "g++ myprogram.cpp" and it will be compiled and saved as "a.exe". And then to run it just type "a".

  13. #13
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    How do you compile and link through cmd?

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    As I said in post #12, assuming you're using the gcc (g++) compiler, and assuming your source code is saved as "myprogram.cpp", just type:
    g++ myprogram.cpp <enter>

    Or, if you want to specify the name of the executable, for example "myprog.exe":
    g++ -o myprog.exe myprogram.cpp <enter>

    It gets a little more complicated if you have to link in other code libraries, but still not difficult.

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,758
    You could also browse the compiler documentation.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cant compile using Codeblocks 10.05
    By laimaretto in forum Windows Programming
    Replies: 2
    Last Post: 12-15-2010, 11:24 AM
  2. Giving CodeBlocks a shot
    By jeffcobb in forum Tech Board
    Replies: 24
    Last Post: 05-23-2010, 12:46 PM
  3. Code::Blocks Help
    By rakeshkool27 in forum C Programming
    Replies: 0
    Last Post: 01-16-2010, 07:25 AM
  4. library issues in CodeBlocks
    By everlearnin in forum C++ Programming
    Replies: 0
    Last Post: 06-02-2009, 08:44 PM
  5. Codeblocks crashes linux?
    By Shakti in forum Tech Board
    Replies: 1
    Last Post: 03-25-2009, 07:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21