[英]How to get G++ to find import files
I'm trying to compile a C++ file on a Mac that uses opencv2. 我正在尝试在使用opencv2的Mac上编译C ++文件。
I downloaded opencv, found an opencv2 folder in it, and copied it into the folder where main.cpp (the program I'm trying to run is). 我下载了opencv,在其中找到一个opencv2文件夹,并将其复制到main.cpp(我尝试运行的程序)所在的文件夹中。
The folder structure is: 文件夹结构为:
main.cpp
BRIEF.h
core.hpp
cvdef.h
My current command (after reading this and this ) is g++ -I/opencv2/core.hpp main.cpp
, run from within the same folder main.cpp
is in. 我的当前命令(读取后这和本 )是
g++ -I/opencv2/core.hpp main.cpp
,从在同一文件夹中运行main.cpp
是英寸
main.cpp
has #include "BRIEF.h"
which works fine. main.cpp
具有#include "BRIEF.h"
,可以正常工作。
BRIEF.h
has #include "opencv2/core.hpp"
which works fine. BRIEF.h
具有#include "opencv2/core.hpp"
,可以正常工作。
core.hpp
has #include "opencv2/core/cvdef.h"
which fails saying the file was not found. core.hpp
具有#include "opencv2/core/cvdef.h"
,该失败提示未找到文件。
How do I use G++ such that the file can be found? 如何使用G ++以便可以找到文件?
As you said, you are only including this file /opencv2/core.hpp
so it is normal that the compiler fails finding the other files. 如您所说,您仅包含此文件
/opencv2/core.hpp
因此编译器无法找到其他文件是正常的。
In your code you are including your files starting from your project root directory, so you have to include the project root directory for the compiler to find these files: 在您的代码中,您包括从项目根目录开始的文件,因此必须包括项目根目录,编译器才能找到这些文件:
g++ -I$(PROJECT_DIR) $(PROJECT_DIR)/main.cpp
or if you run g++
from the root directory, you can use .
或者,如果您从根目录运行
g++
,则可以使用.
, which will expand into the current path (your project root directory): ,它将扩展到当前路径(您的项目根目录):
g++ -I. main.cpp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.