简体   繁体   中英

Makefile for different .cpp files in different folders

I have the following folder structure:

Project project:

  • folder1
    • sourceFile1_1.cpp
    • sourceFile1_2.cpp
  • folder2
    • sourceFile2.cpp
  • folder3
    • sourceFile3.cpp
  • main.cpp
  • makefile

And I'd like to create a makefile which builds the project. The source files can have dependencies among them, but there is not any cyclic dependency.

This is the makefile I have right now:

all: project.exe

clean:
    rm main.o project.exe

project.exe: main.o
    g++ -g -o main main.o

main.o:
    g++ -c -g  main.cpp 

But when I run it, I get Cannot open include file: 'whatever....h': No such file or directory

Does someone know what I'm doing wrong?

cannot open include file , means that the compiler was not able to find the file. The compiler uses the include path to search for include files. You can look at the documentation here for more information about how you can set this include path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM