Thread: compiling problem

  1. #1
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14

    compiling problem

    Hi All.

    I just created a myproject folder. This folder contains two sub folders i.e. src and include to hold .cpp and .h files.
    I created a simple class in student.h file and defined a simple display function in student.cpp file.

    Then I created another file inside src folder where I defined my main function i.e. mainfile.cpp and called display function.

    The exact directory structure is this....

    myproject
    - include
    -student.h
    -src
    -student.cpp
    -mainfile.cpp

    I compiled .h file. It compiled successfully. I compiled this from within include folder.

    Then I tried to compile .cpp file using

    c:\myproject\src\ g++ student.cpp

    But it gave error as it could not find student.h file. I had included student.h file within the student.cpp file.

    Can any one help about how can I compile .cpp file successfully.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    The compiler knows how to find your files how? You should specify the path to the headers on the command line.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14
    Quote Originally Posted by MacGyver View Post
    The compiler knows how to find your files how? You should specify the path to the headers on the command line.
    Do you want to say that

    I should give

    C:\myproject\src\ g++ student.cpp C:\myproject\header\student.h

    Is above line correct.

    But if I use 5 header files then do I need to give the path of all header files like this.....

    Is not any other way...

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Something like this:

    Code:
    g++ -IC:\myproject\include student.cpp
    Note the space between the path and the .cpp file you're compiling.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Location
    India
    Posts
    14
    Quote Originally Posted by MacGyver View Post
    Something like this:

    Code:
    g++ -IC:\myproject\include student.cpp
    Note the space between the path and the .cpp file you're compiling.
    THANKS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Running Program After Compiling
    By kristentx in forum C++ Programming
    Replies: 13
    Last Post: 09-12-2007, 10:46 AM
  2. Problem compiling simple code examples
    By Wintersun in forum Windows Programming
    Replies: 8
    Last Post: 08-14-2007, 10:30 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. compiling problem
    By tinkerbell20 in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2005, 12:12 PM
  5. simple compiling problem
    By waxydock in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2005, 10:33 AM