简体   繁体   English

如何使用 Makefile 在项目子目录中包含 C++ 文件

[英]How do I include C++ files in project subdirectory with Makefile

I am working on a C++ project that has to be compiled using a Makefile.我正在处理一个必须使用 Makefile 编译的 C++ 项目。 The project requiring various sources and headers, I decided to organize them in different directories inside the project.该项目需要各种来源和标头,我决定将它们组织在项目内的不同目录中。 My situation looks like this (fake example):我的情况是这样的(假的例子): 在此处输入图像描述

In the main.cpp file I try to include a_bis.hpp with the line:在 main.cpp 文件中,我尝试将 a_bis.hpp 包含在以下行中:

#include "a/a_bis/a_bis.hpp"

When compiling I get the error message a/a_bis/a_bis.hpp: No such file or directory.编译时出现错误消息 a/a_bis/a_bis.hpp:没有这样的文件或目录。 From what I understood I need to add the -I flag to the compiling command.据我了解,我需要将 -I 标志添加到编译命令中。 Here is what it looks like:这是它的样子:

g++ -Wall -Wextra -Werror -I"D:\C++\test" main.cpp

The path is correct, but I keep getting the same error.路径是正确的,但我不断收到同样的错误。 I tried other syntaxes ( -I/D/C++/test, -I"D:\C++\test").我尝试了其他语法(-I/D/C++/test、-I"D:\C++\test")。 Looking online I see the same syntax over and over again, which I already tried.在线查看时,我一遍又一遍地看到相同的语法,我已经尝试过了。

Does someone have any clue of what might cause this issue?有人知道可能导致此问题的原因吗?

This project is a school project and I am forbidden of using any cmake tool.这个项目是一个学校项目,我被禁止使用任何 cmake 工具。 Thanks for any help!谢谢你的帮助!

Thanks for your help, I found the issue.感谢您的帮助,我找到了问题所在。 I am using the regular path of my Windows system but I executed the make commands using a WSL terminal.我使用的是 Windows 系统的常规路径,但我使用 WSL 终端执行了 make 命令。 When executing the make command in a Powershell terminal there seems to be no problem using the syntax pointed out by MadScientist's comment ( -ID:/C++/test ).在 Powershell 终端中执行 make 命令时,使用 MadScientist 的评论 ( -ID:/C++/test ) 指出的语法似乎没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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