library not found for -lippicv - opencv

After installing opencv3 on my OSX,I run this command
g++ -ggdb `pkg-config --cflags --libs opencv` facedetect.cpp -o /tmp/test && /tmp/test
I got this error
ld: library not found for -lippicv
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If you're compiling with Mac OSX, I ran into the same problem and found a solution here, under "Install OpenCV 3 on Mac OSX with brew", "Troubleshooting":
# Find ippicv
find /usr/local -name "libippicv.a"
# For me it is /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/3rdparty/lib/libippicv.a
# Make a symlink to /usr/local/lib
ln -s /some/path/OpenCV/3rdparty/lib/libippicv.a /usr/local/lib/
# I used
ln -s /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/3rdparty/lib/libippicv.a /usr/local/lib/

Related

linker can't find lua library

I ran g++ -g ./src/*.cpp -L/usr/lib/ -llua5.3
and got an error.
/usr/bin/ld: cannot find -llua5.3
collect2: error: ld returned 1 exit status
How can I make linker find lua library?
I've installed lua with this commands
wget -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz
tar zxf lua-5.3.0.tar.gz
cd lua-5.4.2
make linux
make install
I've installed apt install liblua5.3-dev instead of wget -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz to make it work

How to set the include path, #include "opencv2/opencv.hpp"

I am trying to do Compiling With OpenCV section in this page: Installing Darknet
After I did OPENCV = 1, I tried to do re-make, so I did make in the darknet directory.
The directory is below.
(yolo) bash-3.2$ pwd
/Users/moray/darknet
(yolo) bash-3.2$ ls
LICENSE LICENSE.gpl LICENSE.v1 backup data libdarknet.a python src
LICENSE.fuck LICENSE.meta Makefile cfg examples libdarknet.so results
LICENSE.gen LICENSE.mit README.md darknet include obj scripts
and the result of the re-makaing is here.
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:6:10: fatal error: 'opencv2/opencv.hpp' file not found
#include "opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1
So I thought include path could not reference opencv.hpp, I looked for the file and found it.
(yolo) bash-3.2$ ls ~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp
/Users/moray/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp
Therefore I tried to change #include "opencv2/opencv.hpp" to "include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp" in ./src/image_opencv.cpp
And the result is here.
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:7:10: fatal error:
'~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp' file not found
#include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1
I cannot understand why the error happens.
Please tell me your think.
============================================
os: macOS Catalina 10.15.1
(yolo) is a virtual environment in anaconda(3)
opencv was installed by pip command in (yolo)
all the packages by pip command in (yolo):
(yolo) bash-3.2$ pip list
Package Version
--------------------- -------------------
certifi 2019.11.28
numpy 1.17.4
opencv-contrib-python 4.1.2.30
opencv-python 4.1.1.26
pip 19.3.1
setuptools 42.0.2.post20191203
wheel 0.33.6
gcc:
(yolo) bash-3.2$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
This error explains it pkg-config: command not found. In order to use OpenCV in YOLO, you have to install OpenCV that works for C or C++ program, not Python. You probably installed opencv using pip for Python. Follow these steps in one of these links to install opencv : this or this or other tutorial.
After that, to check whether you have installed OpenCV correctly and can be used in C program, run this command :
pkg-config --modversion opencv
If it doesn't show anything or shows wrong version, try to reinstall OpenCV OR it is possible that your machine doesn't locate opencv version correctly.
So add command to your ~/.bashrc for example :
vim ~/.bashrc
export PKG_CONFIG_PATH=/home/user/installation/OpenCV-3.4.0/lib/pkgconfig
source ~/.bashrc
Notes : Change the path according to your opencv installation directory that contains opencv.pc

How to include and use openCV library when installed locally?

I want to install an OpenCV version locally on OSX in a folder without overwriting the old installation that I need for an old executable.
I followed [these instructions][1], particularly the Building OpenCV from Source Using CMake, Using the Command Line section.
So basically I:
downloaded the source code with git and now it is in the subfolder openCV
Created a new directory cmake_bin_dir
Entered in cmake_bin_dir and created another subdirectory instDir
From the cmake_bin_dir I launched the command cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/my/home/Downloads/openCVProject/cmake_bin_dir/instDir/ ../openCV/
From the same directory I launched first make and then sudo make install. This created the *.dylib files in the cmake_bin_dir/instDir directory.
To test the installation I created my project directory (at the same level of cmake_bin_dir.
I tried to compile the file named test.cpp with the command:
g++ -std=c++11 -I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
-I../openCV/modules/calib3d/include/ -I../openCV/modules/features2d/include \
-I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
-I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
-I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
-I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
-I../openCV/modules/video/include -I../openCV/modules/videostab/include test.cpp -o test.o
I added the include one by one because I got compilation error each time.
However now I getting a linkage error:
Undefined symbols for architecture x86_64:
"cv::String::deallocate()", referenced from:
cv::String::~String() in test-afd12e.o
cv::String::operator=(cv::String const&) in test-afd12e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So my question is how can I compile my program and other projects using the local installation of the OpenCV library?
[1]: https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html
Ok I found my error. If anybody will have the same problem try to execute this on terminal:
export DYLD_LIBRARY_PATH=../your/path/lib/:$DYLD_LIBRARY_PATH
In my case the I executed:
export DYLD_LIBRARY_PATH=../cmake_bin_dir/lib/:$DYLD_LIBRARY_PATH
I also created a Makefile with the following content:
CPP = g++ -std=c++11
# OpenCV trunk
CPPFLAGS = -L../cmake_bin_dir/lib/ \
-I../cmake_bin_dir/include \
-I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
-I../openCV/modules/calib3d/include/ \
-I../openCV/modules/features2d/include \
-I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
-I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
-I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
-I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
-I../openCV/modules/video/include -I../openCV/modules/videostab/include \
`pkg-config --cflags --libs ../cmake_bin_dir/instDir/lib/pkgconfig/opencv.pc`
# Opencv 2.4.8
#CPPFLAGS = -L/home/krystof/libs/opencv-2.4.8/release/installed/libs \
-I/home/krystof/libs/opencv-2.4.8/release/installed/include
all: test
test: test.cpp
$(CPP) $(CPPFLAGS) $^ -o $#
Now executing make should build the program with the local openCV version.

Met undefined reference when use glib in ubuntu

I've searched about this a lot. And tried a lot. Just don't know where I go wrong.
Here is my code, it's very simple:
#include <glib.h>
int main()
{
int *ip=g_new(int,1);
*ip=42;
return *ip;
}
First I try apt-get libglib2.0-dev in my Ubuntu and Mint, when it's done, compile with:
gcc `pkg-config --cflags --libs glib-2.0` -o main main.c
/tmp/ccYFljQD.o: In function `main':
main.c:(.text+0x13): undefined reference to `g_malloc_n'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1
And the output of pkg-config:
$ pkg-config --cflags --libs glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0
So it's not working, then I try to compile from source and install one by my own.
I've apt-get libffi-dev, autogen and configure, make, make install, that's all okay.
$ pkg-config --cflags --libs glib-2.0
-I/home/donpope/software/include/glib-2.0 -I/home/donpope/software/lib/glib-2.0/include -L/home/donpope/software/lib -lglib-2.0
Yet compile with the same error:
gcc `pkg-config --cflags --libs glib-2.0` -o main main.c
/tmp/cctR3iEq.o: In function `main':
main.c:(.text+0x13): undefined reference to `g_malloc_n'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1
So I need some help here. Thank you!
Update:
Later I try this in a RedHat with older gcc. And it's just okay.
I have this Makefile in my glib sandbox:
PKGS=glib-2.0
CFLAGS+=$(shell pkg-config --cflags $(PKGS))
LDFLAGS+=$(shell pkg-config --libs $(PKGS))
%: %.c
$(CC) $(CFLAGS) $< -o $# $(LIBS) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) $< -c -o $#
%: %.o
$(CC) $< -o $# $(LIBS) $(LDFLAGS)
Starting from this and tweaking, you should be able to figure out the exact commandline and compile your program.
Also, you should make sure that your PKG_CONFIG_PATH is properly updated to contain the path where you installed glib (typically in PREFIX/lib/pkgconfig).
Ubuntu 18.04 here. I had to place all my glib flags at the end of the compile statement, even after the source .c file. So this compiles fine:
gcc -Wall -o bfs bfs.c `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`
but this does not :
gcc -Wall -o bfs `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0` bfs.c
/tmp/ccvWsLk3.o: In function `newGraph':
bfs.c:(.text+0x58): undefined reference to `g_hash_table_new'
collect2: error: ld returned 1 exit status
Which drove me nuts for a while as I was taught that it's always good style to place the source file at the end of the compile statement. :p

Unrecognized command line option '-stdlib=libstdc++'

I'm getting a g++ compiler error (compiling OpenCV 3.0 beta) on OS X 10.10.3 Yosemite.
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/5.0.1/lto-wrapper
Target: x86_64-apple-darwin14
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc5/gcc5/work/gcc-5-20150421/configure --prefix=/opt/local --build=x86_64-apple-darwin14 --enable-languages=c,c++,objc,obj-c++,fortran,java --libdir=/opt/local/lib/gcc5 --includedir=/opt/local/include/gcc5 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-5 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-5 --with-gxx-include-dir=/opt/local/include/gcc5/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc5 5-20150421_0'
Thread model: posix
gcc version 5.0.1 20150421 (prerelease) (MacPorts gcc5 5-20150421_0)
$ cd ~/opencv-3.0.0-beta/samples/cpp
$ g++ -ggdb `pkg-config --cflags --libs opencv` -stdlib=libstdc++ facedetect.cpp -o facedetect
g++: error: unrecognized command line option '-stdlib=libstdc++'
$ cd ~/opencv-3.0.0-beta/build
$ make
[ 2%] Built target zlib
[ 2%] Building CXX object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o
c++: error: unrecognized command line option '-stdlib=libstdc++'
make[2]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o] Error 1
make[1]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/all] Error 2
-stdlib=libstdc++ is a Clang option, you can't use it with GCC.

Resources