我有麻烦试图编译此C++使用G++的程序?
我正在使用MacOS操作系统&在终端中,我已经安装了G ++,当试图编译我的C ++程序文件时,该文件具有单独的汇编;发生以下错误消息:
main.cpp:3:10: fatal error: 'Item.h' file not found
#include "Item.h"
^~~~~~~~
1 error generated.
使用以下命令:g ++ main.cpp -std = C ++ 11
我假设我必须编译其他程序。一个是一个标题程序,该程序已声明为类,在另一个.CPP程序中,它在标题程序中定义了类。抱歉,如果这种解释写得不好,或者不理解,那么我正在遇到很大的麻烦,继续我的编程旅程,因此,如果您在这篇文章中无法理解一些内容,请对此帖子发表评论。谢谢,我会尽力向您解释这个主题。
I'm using a macOS operating system & within the terminal I have installed g++, when trying to compile my C++ Program File, which has separate compilation; the following error message occurs:
main.cpp:3:10: fatal error: 'Item.h' file not found
#include "Item.h"
^~~~~~~~
1 error generated.
with the following command: g++ main.cpp -std=c++11
I'm assuming I have to compile the other programs. One is a header program which has a declared class, and in another .cpp program, it defines the class in the header program. Sorry if this explanation is poorly written or not that understanding, I'm having big troubles continuing my programming journey so if there's something you can't understand in this post please leave a comment on this post & I will do my best to explain the subject to you, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
item.h
不在当前目录中,则需要将包含它的目录指定为g ++
命令中的inclage目录。例如,如果您的文件夹结构是这样的:那么您的G ++命令应
注意,使用单独的翻译单元(CPP文件),您需要先将每个命令编译为对象文件(
.o 文件,这就是
-c
选项所做的),然后将它们与最后一个命令链接在一起。另外,使用少量的翻译单元,您可以在一个步骤中脱离编译并链接它们:
如果您有很多,我绝对建议设置
makefile
或其他某种其他形式的构建系统翻译单元。If
Item.h
is not in your current directory, you will need to specify the directory containing it as an include directory in theg++
command. For example, if your folder structure is this:Then your g++ command(s) should be
Note that with separate translation units (cpp files), you need to compile each one to an object file first (
.o
file, that's what the-c
option does), and then link them together with the last command.Alternatively, with a small number of translation units, you can get away with compiling and linking them in one step:
I would definitely recommend setting up a
Makefile
or some other form of build system if you will have many translation units.