Thread: gcc vs CodeBlocks compiler

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    12

    gcc vs CodeBlocks compiler

    Hello All:

    Is there a difference between compilers in 'CodeBlocks' and with the general 'gcc' compiler?

    I have a program that compiles fine in 'CodeBlocks' the c-programming editor that I use, and then when I compile using gcc in a unix enviroment it will throw errors.

    Any input?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    CodeBlocks is an IDE, not a compiler. It could well be configured to use this "general 'gcc' compiler", and the problem might lie in an incorrect invocation of "gcc in a unix enviroment".

    Or, maybe the errors are due to something platform specific, e.g., you are using CodeBlocks on Windows, and then are using Windows specific stuff.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    12
    Well in my code, I have a header file. When I compile in 'CodeBlocks'; it compiles without error, and the program runs as usual, but then I compile using gcc in a unix enviroment like I said, and it seems the
    Code:
    struct
    method that I clearly declared in the main program isn't declared.

    Could I post my code and error message?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by CDdotdot47
    Could I post my code and error message?
    Yes.

    By the way, on a hunch: make sure that you are compiling as C in both cases. You might be say, compiling as C++ instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    12
    Hi:

    Thank you.

    Attached is my source file plus my header file.
    tv2.c is the main file and mytrace.h is the header.

    Below is the error code that I am getting when I compile with gcc:
    Code:
    bash-2.05$ gcc tv2.c
    tv2.c: In function `trace_init':
    tv2.c:21: error: `trace_item' undeclared (first use in this function)
    tv2.c:21: error: (Each undeclared identifier is reported only once
    tv2.c:21: error: for each function it appears in.)
    tv2.c:21: error: parse error before ')' token
    I checked my compiler settings in 'CodeBlocks' and it says it is set to GNU GCC Compiler.

    Thanks for helping with this.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    C requires that you use struct trace_item, not just trace_item.
    Code:
    trace_buf=(trace_item*)malloc(sizeof(struct trace_item) * TRACE_BUFSIZE);
    and there is no need for the cast of the return value of malloc ANYWAY.

    IOW: Laserlight nailed it.

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    12
    Ok I tried what you said and now i'm getting this error:

    Code:
    bash-2.05$ gcc tv2.c
    Undefined                       first referenced
     symbol                             in file
    log                                 /var/tmp//ccCa68F0.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    bash-2.05$

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You presumably used the log function from <math.h>. You may need to pass -lm as an option to gcc.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jul 2010
    Posts
    12
    okay it compiled now with GCC.

    So how do I configure CodeBlocks to compile the same as GCC?

    Now when i re-compile the same code in CodeBlocks, I get like a million errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc compiler doesnt know parameter
    By thescratchy in forum C Programming
    Replies: 5
    Last Post: 04-30-2010, 01:40 PM
  2. Determine the location of gcc (using gcc)
    By Kennedy in forum Linux Programming
    Replies: 10
    Last Post: 03-16-2010, 08:04 AM
  3. Replies: 1
    Last Post: 01-11-2008, 09:34 AM
  4. gcc not for C++?
    By tin in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2004, 08:26 AM