I write a code using opencv library, I used codeblocks ide configuring it to work with opencv (configuring linker settings and search directory and including all the necesary path to enviroment variable) correctly and then the program works fine. The problem is when I try to compile using minGW with g++ 6.3.0 version, it gave me the next error:
ImgSeg.cpp:2:39: fatal error: opencv2/imgproc/imgproc.hpp: No such file or
directory
#include <opencv2/imgproc/imgproc.hpp>
^
compilation terminated.
I try all possible form to put the opencv2 directory in enviroment variable but it has the same error all the time, it's a little frustrating. this is what I have on path in enviroment variable:
C:\opencv_install\lib;
C:\opencv_install\include;
C:\opencv_install\bin;
I'm using windows 7 64 and opencv 2.4.9
GCC does not search PATH when looking for include files.
You will need to tell it where to look by using the -I commandline parameter:
-IC:\opencv_install\include
When linking, you'll also need to tell GCC where to find the libraries you're linking:
-LC:\opencv_install\lib -lopencv_core
In CodeBlocks you'll need to add the former to include directories (not PATH) in the project settings.
Finally I could compile the program but I had to install mingw64 version 4.9.2 from this link. The command that I use to compile was this:
g++ -std=c++11 "name of the program.cpp" -IC:/opencv_install/include -LC:/opencv_install/lib -llibopencv_core249 -llibopencv_highgui249 -llibopencv_imgproc249 -o "name of the exe"
It's important include the -l lib that you used in the program
Related
I know that someone already asked this question but it isn`t up to date anymore. Most of the links are dead and the commands are not relevant anymore.
I have read these
Compile IOS program from linux commandline
How to cross-compile clang/llvm for iOS?
For example, I have been trying to compile silversearcher-ag for my iPhone 6 (jailbroken). This is the project link https://github.com/ggreer/the_silver_searcher.
I am targeting iOS 12.4.
These are the commands that I`ve tried
./configure CC=/home/growtopiajaw/Desktop/cctools-port-master/usage_examples/ios_toolchain/target/bin/arm-apple-darwin11-clang CXX=/home/growtopiajaw/Desktop/cctools-port-master/usage_examples/ios_toolchain/target/bin/arm-apple-darwin11-clang++ --host=arm-apple-darwin11
make
I am using cctools-port to cross compile the project. My compiled cctools toolchain is located under /home/growtopiajaw/Desktop/cctools-port-master/usage_examples/ios_toolchain/target and below is how the toolchain`s directory structure looks like
This is my configure log: https://del.dog/nugibonury
This is my make log:
CC src/ignore.o
In file included from src/ignore.c:11:
./src/options.h:7:10: fatal error: 'pcre.h' file not found
#include <pcre.h>
^~~~~~~~
1 error generated.
make: *** [Makefile:494: src/ignore.o] Error 1
This is my GitHub repository containing the cross compile toolchain
https://github.com/GrowtopiaJaw/arm-apple-darwin11
Apple does not ship PCRE. You need to get the headers and dylib/tbd files manually.
If you're using checkra1n or unc0ver, then the deb on the APT repo contains headers as well, so you could just use that.
If you plan to package this into an APT/dpkg file, make sure to add pcre as a dependency.
I am using Vim's YouCompleteMe C semantic completer installed with the --clang-completer flag. It complains that it can not find the 'omp.h' file used in the Eigen/Core library file. Error message is as follows:
In included file: 'omp.h' file not found /usr/include/eigen3/Eigen/Core:247:10: note: error occurred here [pp_file_not_found]
The code compiles and runs perfect, so that's why I know it is not a real issue and something wrong with YouCompleteMe. I have tried using both clang and clangd, it does not matter, same issue.
If I simply remove the -fopenmp from the compile_command.json file, it fixes the issue.
Thanks in advance.
The pre-built clangs from llvm.org don't include openmp. YCM includes a copy of the clang resource dir from the pre-built llvm.org packages, therefore 'omp.h' (which is part of the resource dir) is not found.
If you need to use openmp, then i suggest you set g:ycm_clangd_binary_path to point to a clangd that is installed alongside your llvm toolchain containing openmp.
Trying to convert a large gcc/makefile project into clang. Got it roughly working for x86, but now I'm trying to get cross compilation working.
The way it currently works is that we use Linaro's 7.1.1 arm compiler alongside its companion sysroot directory for base libraries/headers. I installed clang-6.0 and then the base clang(not sure if that mattered).
I used some commands I found to redirect clang to clang-6.0 and when I execute 'clang -v' and got
clang version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
....
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/9
....
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.5.0
....
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
It does not find the current compiler we use which is at
/usr/local/gcc-linaro-7.1.1-2017.08-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++(also a directory for *x86_64*)
I only found references to setting --sysroot, but not to a specific compiler. Definitely still lost about the relationship between clang+llvm+other compilers. I even saw somewhere saying I needed to compile llvm before I could use it?
I very roughly made changes in our make files to get the following output, basically all I had to add was '-target arm-linux-gnueabuhf' and reordered the mcpu/mfloat/marm/march so they came after -target in case it mattered
clang --sysroot=/usr/local/sysroot-glibc-linaro-2.25-2017.08-arm-linux-gnueabihf -c -std=c++0x
-g -DDEBUG_ON -target arm-linux-gnueabihf -mcpu=cortex-a7 -mfloat-abi=hard -marm -march=armv7ve
-Wall -fexceptions -fdiagnostics-show-option -Werror .... -I/usr/local/gcc-linaro-7.1.1-2017.08-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include .... and many more
I think the problem probably lies with the change I made which is the actual 'clang' call that replaced
/usr/local/gcc-linaro-7.1.1-2017.08-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ ....
End up with
fatal error: 'cstdarg' file not found
#include <cstdarg>
As said before I can already cross-compile with gcc, so I've already come across issues with std libraries that require 'build-essentials', 'g++-multilibs', etc. So they're already installed.
Looked and really haven't found anything too useful to me, I'm on linux mint 18.3 and the closest things I found were issues people had on mac and windows.
So I came across some posts mentioning setting --gcc-toolchain=/your/choice/of/cross/compiler but they also mention it not working. I discovered that if you combine this with the installation of llvm-6.0-dev(or maybe llvm-6.0-tools, tools installed dev so not 100%) it at least worked for me.
Any compiler clang or gcc needs to know where a header file is defined. The standard headers, standard libraries, c-runtime, and libc are all packaged together for each target e.g., arm64, x86 in a directory called 'sysroot'. When we compile a program we need to pass the path to sysroot for a compiler to know where to look for standard headers during compilation, and where to look for common libraries (libc, libstdc++ etc) during linkage.
Normally when we compile a program for the same machine the compiler uses the standard headers available in '/usr/include' and libraries from '/usr/lib'. When cross-compiling programs we should supply the sysroot as compiler flag. e.g. gcc --sysroot="/path/to/arm64/sysroot/usr" test.cpp. Same for clang. Most often pre-packaged cross compilers come with a script/binary that has 'sysroot' path embedded into it. e.g., aarch64-linux-gnu-gcc (https://packages.ubuntu.com/xenial/devel/gcc-aarch64-linux-gnu).
... the closest things I found were issues people had on mac and windows.
On mac the clang compiler will have the similar configuration as linux. So the details you found there should be totally applicable to yours.
More details on sysroot and cross-compilation:
https://elinux.org/images/1/15/Anatomy_of_Cross-Compilation_Toolchains.pdf
I am trying to build this code:
https://docs.opencv.org/3.2.0/d5/d6f/tutorial_feature_flann_matcher.html
I am using Ubuntu 16.04 with CLion 2017.3 and have OpenCV 3.4 installed.
xfeatures2d.hpp can't be found on the system.
I have looked at many different problems on the internet, but couldn't find a solution.
Any help?
You have to include cmake comiplation flag to opencv OPENCV_EXTRA_MODULES_PATH and set it to the opencv_contrib/modules.
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
Here's what I had to do to compile OpenCV with xfeatures2d:
Download opencv_contrib (I took a release from the releases page). This step is what gives us xfeatures2d.
Unpack the tarball somewhere, e.g., ~/src/opencv_contrib-4.5.5
When configuring OpenCV (the main OpenCV source like opencv-4.5.2) with CMake, add the following option to cmake command line (adjusting the value to be your actual path to the modules subdirectory of the opencv_contrib tarball):
-DOPENCV_EXTRA_MODULES_PATH=$HOME/src/opencv_contrib-4.5.5/modules/
Now just build as you normally would and install.
The above actions gave me the expected file (among others): /usr/include/opencv4/opencv2/xfeatures2d.hpp.
When I compile a simple program : hello_world.cpp
**I get the error-
**fatal error: cv.h: No such file or directory
compilation terminated.****
Solutions I found but didn't work:
I checked for cv.h and highgui.h if they are there, and got these results:
/home/snu/OpenCV-2.4.0/include/opencv/highgui.h
/usr/lib/perl/5.14.2/CORE/cv.h
/home/snu/OpenCV-2.4.0/include/opencv/cv.h
I checked if opencv is correctly installed by using
pkg-config opencv --libs, this is what i got :
-lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
I made some changes in the header files of hello_world.cpp as-
#include "opencv2/highgui/highgui.hpp"
Welcome to Stack Overflow, the land of the non-answer.
"You are not doing it right, is the problem"
"Do this", with no explanation. Doesn't work.
The cmake answer is ok, but I don't really want to use cmake for the sole purpose of making a single library import.
--- end of roast, my answer:
As per https://answers.opencv.org/question/225224/opencvcvh-not-found/
OpenCV 4 discontinued the C-API in favor of the C++ one, apparently.
So you should install the latest version of OpenCV 3. This can be done using platform specific installer listed below:
https://sourceforge.net/projects/opencvlibrary/files/3.4.10/
For Linux specifically, you want this file from the ones in the link above.
Download and extract it.
Then based on these instructions to install it,
Make a directory, I called my opencv-install and put the extracted folder in it.
opencv-install/opencv-opencv-25a1900
cd opencv-install
rm opencv-opencv-25a1900/CMakeCache.txtls
cmake opencv-opencv-25a1900
make
sudo make install # global install
Then change your import to #include "opencv/cv.h"
Well how about that, you still needed cmake, but at least you don't have to make your project a "cmake project". In fact, if someone else with the same operating system has already done up to step 5, you can simply use their build !
For Linux beginners (requires Debian-base, cmake not needed)
As a little courtesy, and to put my "money" where my "mouth" is, I will provide to you my own build. Understand that using someone else's build assumes a bit more trust than compiling it yourself. I know when I first start with C/Linux compiling OS projects can be kind of daunting so.... here you go! It is for For Debian GNU/Linux 11 (bullseye) x86_64. I think this means it works on Ubuntu, and maybe other OSes that use apt. If you try it and it doesn't work, you should try a different build or make one yourself by starting at step one above.
You are probably not compiling correctly. Add the opencv-include folder in the compiler settings.
Use CMake to link libraries and include directories. It makes your life easier and also for anyone else who will be extending/reading your code in the future. You will not need to add folders specifically into projects as CMake will do that for you automatically.
For example, to link OpenCV, use the follow lines of code:
FIND_PACKAGE( OpenCV REQUIRED )
TARGET_LINK_LIBRARIES( myProject ${OpenCV_LIBS} )
please use the code below for such errors:
#include <opencv/cv.h>
in the place of
#include <cv.h>