Thread: Inconsistent Compilation

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Inconsistent Compilation

    I'm compiling the following program:
    Code:
    #include <stdio.h>
    
    void main()
    {
    printf("Hello World\n");
    }
    With the following include statement and the associated header file in the same directory as the .c file:
    Code:
    #include "stdio.h"
    gcc will then compile successfully using the following

    $gcc -x none file.c

    With the following include statement and the associated header file in /usr/include
    Code:
    #include <stdio.h>
    gcc will not compile the file using any of the following

    $gcc -x c file.c
    $gcc -x none file.c
    $gcc -std=c89 file.c

    Now...how about this...

    If I compile a file with the stdio.h header in the same directory, a precompiled header is kicked out: stdio.h.gch

    If that .gch file is moved to /usr/include then compilation will proceed without any errors when the following statement is used:
    Code:
    #include <stdio.h>
    According to: http://gcc.gnu.org/onlinedocs/gcc-3...ed-Headers.html

    "...only one precompiled header may be used during any compilation..."

    so this proves to be a solution for small projects.

    More...if the following is entered, a list of syntax errors results:

    $ pwd
    /usr/include
    $ gcc -x none stdio.h
    /usr/include/stdio.h:21 error: syntax error before '*' token
    ......

    GES

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Why are you messing with writing headers to /usr/include. That just trashes the compiler for everyone else (maybe just you, but who knows).

    You say "errors", but you neglect to say what errors.

    You post code with void main, which is plain wrong and causes most gcc's to output an error message anyway.

  3. #3
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    i have to agree with Salem.. dont mess with /usr/include or /usr/lib .. go to /usr/local if you are going to add stuff.. or you end up with a busted install. like it appears you have ..

    and speaking of that.. have you checked in /usr/local/include ?
    gcc will check /usr/local/include before it checks /usr/include so if there is a busted file there it may be causing the problem..
    let me clarify that.. you should not have a stdio.h in /usr/local/include ..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 07-03-2009, 11:20 AM
  2. Simple C++ Compilation Question
    By mercury529 in forum C++ Programming
    Replies: 14
    Last Post: 07-30-2006, 09:40 PM
  3. Compilation units
    By filler_bunny in forum C++ Programming
    Replies: 0
    Last Post: 10-21-2003, 03:57 AM
  4. MS VC++ Crash on compilation
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-23-2003, 07:06 PM
  5. Preproccessor conditional compilation
    By Garfield in forum C Programming
    Replies: 5
    Last Post: 09-28-2001, 09:28 AM