Thread: warning in "header" but not in <header>

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    warning in "header" but not in <header>

    I have a project which used a generic header I keep in /usr/local/include. I have to send it to someone, so I've copied the appropriate functions into a (smaller) header and changed #include <mine.h> to #include "mine.h". Now I get some inappropriate warnings involving "incompatible pointer". If I put a softlink in my LIB_PATH to the header and go back to #include <mine.h>, they disappear.

    What's the deal? I can't use the softlink, I have to give this to someone with #include "mine.h".

    ps. the pointers are not really incompatible, and the error persists even if I cast them as themselves.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what is the declarations in the "mine.h" that give problems?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    gcc has an option (which I believe is on by default) to treat system headers as special when it comes to warning (since they're not under your control, generally, and sometimes they have weird things in them). So when it sees <mine.h> your header gets the special treatment. Therefore I would suggest actually fixing the problem.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by tabstop View Post
    Therefore I would suggest actually fixing the problem.
    Okay
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I have a project which used a generic header I keep in /usr/local/include.
    However temptingly convenient this may seem, it's generally a bad idea just to stuff random header files in the top-level of the well known include directories.

    - it may get trashed when some well known library gets installed (or you may have already trashed something).
    - it may give the impression something is installed, when it isn't.

    Create your own local include directory for all your favourite files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    The directory /usr/local/include should be fine for locally developed header files as long as they don't go into the well known /usr/include. Specify the include directory as a -I command line option to the gcc or whichever C compiler you are using.

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Was

    #include "mine.h"


    Defined within your local directory? If not that is most likely where the problem lies. I would agree that using gcc option '-I' would be key. When you use "" around header files then the preprocessor will first search in the source directory. If you do not want to use -I then an appropriate Makefile will be needed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM