Thread: compiling with g++

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    106

    compiling with g++

    my files in my compiling folder:

    input.cpp contains the line #include "input.h"
    input.h contains the line #include "input.cpp" and #input H5Cpp.h
    test.cpp contains the line #include "input.cpp"

    however, H5Cpp.h is in another folder, it is part of the HDF5 library

    when I compile with the command:
    g++ -c input.cpp test.cpp

    I get an error telling me that H5Cpp.h is not found.

    I have added the H5Cpp.h's folder location to LD_LIBRARY_PATH variable in .bash_profile and have made certain that it is loaded each time. However, this error persists. What am I doing wrong?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do not include .cpp files, unless you really, really know what you're doing (hint: I'm 99% sure you don't).
    Replace
    #input "H5Cpp.h"
    with
    #input <H5Cpp.h>
    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
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by Elysia View Post
    Do not include .cpp files, unless you really, really know what you're doing (hint: I'm 99% sure you don't).
    Replace
    #input "H5Cpp.h"
    with
    #input <H5Cpp.h>
    i got the files this way. changing the quotes to brackets does not work. I think < and > are used when the library is standard, " and " used when the lib is non standard.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by elninio View Post
    i got the files this way. changing the quotes to brackets does not work. I think < and > are used when the library is standard, " and " used when the lib is non standard.
    its a shared project. the guy that gave them to me certainly knows what hes doing as he is working on his PHD

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, quotes mean search local directory, and <> means search include paths, and possible local directory second.
    Oh, believe me there's a lot of people who don't know what they're doing.
    Do the source file contain templates?
    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
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you read the docs on Options for Directory Search.
    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

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by Elysia View Post
    No, quotes mean search local directory, and <> means search include paths, and possible local directory second.
    Oh, believe me there's a lot of people who don't know what they're doing.
    Do the source file contain templates?
    no templates in input.h.
    we have a class that reads .h5 files, its functions are input.h
    input.cpp defines two const float arrays. these are parameters for image analysis functs

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Templates in input.cpp is what I meant.
    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.

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by Elysia View Post
    Templates in input.cpp is what I meant.
    no templates in input.cpp. it only defines some parameters as float. that is all.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then the include is wrong, in all sorts of possible ways.
    But I can understand if you don't want to change it.
    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.

  11. #11
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    fixed the dependency error by adding -I/../libdir but clearly there are other dependency issues:

    Code:
    # g++ input.cpp h5inspect.cpp -I/prog/igor/lib/hdf5-1.8.1/hdf5/include
    input.h: In member function 'float dataset_buf::operator()(int, int, int) const':
    input.h:73: error: 'assert' was not declared in this scope
    input.h: In member function 'float& dataset_buf::operator()(int, int, int)':
    input.h:77: error: 'assert' was not declared in this scope
    input.h: At global scope:
    input.h:97: error: expected ',' or '...' before '<' token
    input.h:97: error: ISO C++ forbids declaration of 'valarray' with no type
    input.h:107: error: ISO C++ forbids declaration of 'valarray' with no type
    input.h:107: error: expected ';' before '<' token
    input.h: In constructor 'quantizer::quantizer(int)':
    input.h:97: error: class 'quantizer' does not have any field named 'v'
    input.h:97: error: 'v' was not declared in this scope
    input.h: In member function 'int quantizer::nq() const':
    input.h:102: error: 'v' was not declared in this scope
    input.h: In member function 'int quantizer::operator()(float) const':
    input.h:116: error: 'v' was not declared in this scope
    ...

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    For assert, #include <cassert>
    For valarray, #include <valarray>
    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

  13. #13
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by elninio View Post
    fixed the dependency error by adding -I/../libdir but clearly there are other dependency issues:
    the includes in input.h are :

    [code]
    #include <valarray>
    #include <stdexcept>
    #include <string>
    #include <map>
    #include <math.h>
    #include <limits>
    #include <algorithm>

    using std::string;
    using std::map;

    #include <H5Cpp.h>
    using namespace H5;

    [\code]

  14. #14
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by laserlight View Post
    For assert, #include <cassert>
    For valarray, #include <valarray>
    should I post the entire list of errors? I think my coworker had his class working on his system, it may just be an issue of not being able to find the correct path

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What compiler did your coworker use? It may well be that <cassert> was indirectly included for him, and you're reaping the rewards for his impreciseness in header use.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Compiling Problem
    By Deronius in forum C++ Programming
    Replies: 3
    Last Post: 06-15-2008, 11:23 AM
  2. Problem compiling files that store functions
    By tiachopvutru in forum C++ Programming
    Replies: 10
    Last Post: 05-30-2008, 05:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:41 AM
  5. Compiling syntax
    By Jez_Master in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2002, 09:46 PM