[英]the g++ command returns no such file or directory
I am new to programming;我是编程新手; I'm starting a new job and I have to resume what the fellow before me did.我要开始一份新工作,我必须继续我之前的那个人所做的。
So I have to run a program called test.cpp in C++.所以我必须在 C++ 中运行一个名为 test.cpp 的程序。 This code contains a header called misc.hpp located in a subfolder of where test.cpp is called include.此代码包含一个名为 misc.hpp 的头文件,位于 test.cpp 称为 include 的子文件夹中。
When I open the terminal from where test.cpp is and run g++ test.cpp
it tells me that:当我从 test.cpp 所在的位置打开终端并运行g++ test.cpp
它告诉我:
test.cpp:4:19: fatal error: misc.hpp: No such file or directory. test.cpp:4:19: 致命错误: misc.hpp: 没有那个文件或目录。
I also tried the g++ test.cpp -I include/misc.cpp but same thing我也试过 g++ test.cpp -I include/misc.cpp 但同样的事情
Could you please help me?请你帮助我好吗?
The -I
(upper-case i) option is to add a directory to search for header files. -I
(大写 i)选项是添加一个目录来搜索头文件。 It's not for including source files.它不是用于包含源文件。
So if the header file is include/misc.hpp
then you should do所以如果头文件是include/misc.hpp
那么你应该这样做
g++ test.cpp -Iinclude
-I include/misc.cpp
doesn't work because: -I include/misc.cpp
不起作用,因为:
misc.hpp
, not misc.cpp
该文件是misc.hpp
,而不是misc.cpp
-I
is for include directories -I
用于包含目录So:所以:
g++ test.cpp -I include
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.