How can g++ recognize *.hpp header files?

This is a discussion on How can g++ recognize *.hpp header files? within the C++ Programming forums, part of the General Programming Boards category; I'm using g++ 4.1.2 to compile *.hpp files, however, it always output: g++: xxx.hpp: linker input file unused because linking ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    33

    How can g++ recognize *.hpp header files?

    I'm using g++ 4.1.2 to compile *.hpp files,
    however, it always output:
    g++: xxx.hpp: linker input file unused because linking not done

    So, how can I make g++ recognize *.hpp files?

    Also, why is boost library favor *.hpp than *.h?
    As far as I know, *.hpp is a non-standard file extension...

    Thanks in advance.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    For one thing, you aren't supposed to compile header files. You should compile .cpp or .c files.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You shouldn't COMPILE header files, so although you are correct that it doesn't recognize them as source files, it shouldn't cause a problem - header files should be included in .c, .cpp, .C or .cxx files.

    --
    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.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    33
    I'm trying to precompile header files.
    So that the compilation time could be reduced.

    Or, am I misunderstood how to precompile?
    Actually I'm just trying.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    It's certainly possible to precompile headers, but if the compiler supports it is another matter. I don't know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Also I don't think file extensions are part of the C++ standard. I believe the C standard does define these, but not the C++ one. Someone correct if I'm wrong.

    So you can't actually think of the hpp extension has non-standard. It is instead a convention that cpp is the extension to use for source files and hpp for header files, whereas c and h respectively are the ones used for C. You can still use these two for C++ projects, but its just not conventioned that way.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    33
    So, how to use g++ to precompile *.hpp files?

    Any idea?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, you can precompile your header, and to make the compiler realize that what the file is, use the option "-x c++-header".

    Note however that there are several conditions that have to be applied, the most important one is that one compilation unit (source file) can't have more than one precompiled header.

    --
    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.

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    You provide little information. The warning message you are getting can happen for several reasons, one of them the fact you are providing linker switches in your command line but actually not attempting any linking, like in the common mistake of using the -c switch which instructs the compiler not to link.

    First start here: http://gcc.gnu.org/onlinedocs/gcc-4....d-Headers.html

    Then if you can't get it to work tells us what you are doing and the error you are getting.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Nov 2007
    Posts
    33
    Hi matsp,

    You're right. Now I can compile my hpp files to gch precompiled header files.
    However, I can't feel any noticeable performance gain.

    Should I do something else when I compile my project?

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Boost compilation times often stem from template logic, not the time needed to parse the headers. Precompiled headers can't improve that.

    And of course, precompiled headers don't improve runtime performance.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Unless you're including a very big set of headers, such as Windows.h. Then PCH improves compile time significantly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is unlikely that precompiled headers is going to vastly reduce your compile time unless you have a HUGE project with LOTS of header files that all get included into lots of files.

    Precompiled headers work best on machines where the header files themselves take a long time to access, such as network mounted file-systems. If the files you are using are "local", then you probably won't see much difference.

    If you have a machine with multiple processor(core)s, then using "make -j N" where N is about 1.5-3x the number of cores. On a single processor machine, "make -j 2" may make it a bit faster - there's no better way to find out than to try. "make -j N" will run N simultaneous compile jobs, which helps the overall compile time. It obviously won't actually help much if there is only one or two source files that are huge, but for many C++ projects, there are many small source files, and here it can really help quite a bit to get multiple compiles going at the same time.

    --
    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.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Using PCH for Windows.h saves lots of time when you have a lot of source files that needs Windows.h. That's the beauty of the them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Projects using external libraries, especially when those library headers are big and complex, make good targets.
    Meanwhile, pre-compiled headers only increase compilations times. Not linking, and definitely not run-time speeds.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

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

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 03:42 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. more header files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2001, 01:56 PM

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