Include Header-Datei in anderem Verzeichnis in c ++

Ich habe C ++ gelernt und bin auf die folgende Frage gestoßen: Ich habe eine Verzeichnisstruktur wie:

 - current directory

  - Makefile

  - include

     - header.h

  - src

      - main.cpp

my header.h:

#include <iostream> 

using namespace std;

void print_hello();

my main.cpp:

#include "header.h"

int main(int argc, char const *argv[])
{
    print_hello();
    return 0;
}

void print_hello()
{
    cout<<"hello world"<<endl;
}

mein Makefile:

CC = g++
OBJ = main.o
HEADER = include/header.h 
CFLAGS = -c -Wall 

hello: $(OBJ) 
    $(CC) $(OBJ) -o $@

main.o: src/main.cpp $(HEADER)
    $(CC) $(CFLAGS) 
CC = g++
OBJ = main.o
HEADER = include/header.h 
CFLAGS = -c -Wall 

hello: $(OBJ) 
    $(CC) $(OBJ) -o $@

main.o: src/main.cpp $(HEADER)
    $(CC) $(CFLAGS) $< -o $@

clean: 
    rm -rf *o hello
lt; -o $@ clean: rm -rf *o hello

Und die Ausgabe von make ist:

g ++ -c -Wall src / main.cpp -o main.o src / main.cpp: 1: 20: Schwerwiegender Fehler: header.h: Keine solche Datei- oder Verzeichniskompilierung wurde beendet. Makefile: 10: Rezept für Ziel 'main.o' fehlgeschlagen make: *** [main.o] Error 1

Welche Fehler habe ich hier gemacht. Es ist frustrierend. Schätzen Sie wirklich jeden Rat!

Antworten auf die Frage(6)

Ihre Antwort auf die Frage