简体   繁体   中英

Including headers in C++

In C++, does one need to copy any needed header files into the directory of the main C++ file?

Ex. I have OpenCV installed globally, and the Python bindings are working well. However, if I write:

#include "opencv2/highgui/highgui.hpp"

I receive a "not found" error. Do I need to copy these from their global install location to the project dir? I'm certain there must be a well-established set of practices for this, so I don't want to poke around in the dark on my own.

It depends on which operating system and build tool chain you are using, but as an example using linux, gcc and cmake, this article shows how to build with opencv.

http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html

As you can see with the find_package directive, cmake is searching for the opencv include files.

Obviously, you can specify include path directly with g++ -I , but having cmake find it for you has the advantage that it will have a better chance of being found if you compile on a different system. It will also give you an error if it can't find the files.

Lastly, you should ensure that you have the "dev" files, as opposed to just the library. The dev files will have headers to include. While, the library will only have shared objects ( *.so ) and archives ( *.a ) that can be used for static or runtime linking.

如果它是全局安装的,则需要通知编译器全局查看,即

#include <opencv2/highgui/highgui.hpp>

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