Error When Building C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joinkumaresh
    New Member
    • Feb 2008
    • 1

    Error When Building C++

    Hi

    (I' am using: c++,Eclipse,CDT ,Mingw & GDB on windows xp)

    When i have my header files in 'scorce folder' then it's working fine..

    but if i have my header files in separate 'header folder' then comes the error..

    'function1' was not declared in this scope
    function1.h: No such file or directory

    I tried with these 2 makefile files but it seem to be not working, please see if someone can help me in this.


    1)
    main.exe: main.o function1.o
    g++ main.o function1.o -o main.exe
    main.o: main.cpp function1.h
    g++ -c main.cpp
    function1.o: function1.cpp function1.h
    g++ -c -I"C:\Documen ts and Settings\kdevar ajan\workspace\ Mycpp\Header" function1.cpp

    2)
    main.exe: main.o function1.o
    g++ main.o function1.o -o $@
    .cpp.o: function1.h
    g++ -c -I"C:\Documen ts and Settings\kdevar ajan\workspace\ Mycpp\Header" $< -o $@

    Thanks in advance...
  • Harinezumi
    New Member
    • Feb 2008
    • 32

    #2
    Hi,

    Originally posted by joinkumaresh
    Hi

    (I' am using: c++,Eclipse,CDT ,Mingw & GDB on windows xp)

    When i have my header files in 'scorce folder' then it's working fine..

    but if i have my header files in separate 'header folder' then comes the error..

    'function1' was not declared in this scope
    function1.h: No such file or directory

    I tried with these 2 makefile files but it seem to be not working, please see if someone can help me in this.


    1)
    main.exe: main.o function1.o
    g++ main.o function1.o -o main.exe
    main.o: main.cpp function1.h
    g++ -c main.cpp
    function1.o: function1.cpp function1.h
    g++ -c -I"C:\Documen ts and Settings\kdevar ajan\workspace\ Mycpp\Header" function1.cpp

    2)
    main.exe: main.o function1.o
    g++ main.o function1.o -o $@
    .cpp.o: function1.h
    g++ -c -I"C:\Documen ts and Settings\kdevar ajan\workspace\ Mycpp\Header" $< -o $@

    Thanks in advance...
    I use the same configuration (c++, Eclipse, etc.), except that Eclipse manages the makefile for me :). But if I remember correctly, you need to specify the path to the header file when you include it.
    E.g. if the file you want to include function1.h into is in the folder "source" and "Header" is a subfolder of "source", then you need to type #include "Header/function1.h".
    Or if the folder "source" and "Header" are in the same folder (siblings), then write #include "../Header/function1.h".
    I use this in my projects and works fine.

    Bye,

    Comment

    Working...