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.
Related
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
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
I'm new to build and install opencv on my Ubuntu 14.04.
I follow pyimagesearch to do it.
After typing cmake command, I encounter some errors as follows.
I google some solutions and try to reinstall some packages, ex:gcc.
Still can not work... :(
for /usr/bin/ld: cannot find -lstdc++ problem, anyone has ideas?
thank you :)
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/eric/program_files/OpenCV/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
-- The CXX compiler identification is Clang 3.4.0
-- The C compiler identification is GNU 4.8.5
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/usr/bin/clang++" is not able to compile a simple test
program.
It fails with the following output:
Change Dir:
/home/eric/program_files/OpenCV/opencv/build/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec3807027872/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3807027872.dir/build.make
CMakeFiles/cmTryCompileExec3807027872.dir/build
make[1]: Entering directory
`/home/eric/program_files/OpenCV/opencv/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/home/eric/program_files/OpenCV/opencv/build/CMakeFiles/CMakeTmp/CMakeFiles
1
Building CXX object
CMakeFiles/cmTryCompileExec3807027872.dir/testCXXCompiler.cxx.o
/usr/bin/clang++ -o
CMakeFiles/cmTryCompileExec3807027872.dir/testCXXCompiler.cxx.o -c
/home/eric/program_files/OpenCV/opencv/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTryCompileExec3807027872
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec3807027872.dir/link.txt --verbose=1
/usr/bin/clang++
CMakeFiles/cmTryCompileExec3807027872.dir/testCXXCompiler.cxx.o -o
cmTryCompileExec3807027872 -rdynamic
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[1]: *** [cmTryCompileExec3807027872] Error 1
make[1]: Leaving directory
`/home/eric/program_files/OpenCV/opencv/build/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec3807027872/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:88 (project)
-- Configuring incomplete, errors occurred!
try:
sudo apt-get install g++
or
ln -s /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so
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/
Based on How can I compile lame as static library...?, I've compiled lame using this script on a macbook pro:
mkdir -p build
rm -rf build/* #*/
function build_lame()
{
make distclean
./configure \
CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${SDK}.platform/Developer/SDKs/$SDK$SDK_VERSION.sdk" \
CC="/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch $PLATFORM -miphoneos-version-min=7.0" \
--prefix="/Users/$USER/Desktop/$PROJECTNAME" \
--host="arm-apple-darwin9" \
--disable-shared \
--enable-static \
--disable-frontend \
make
cp "$PROJECTNAME/.libs/$PROJECTNAME.a" "build/$PROJECTNAME-$PLATFORM.a"
}
PROJECTNAME=libmp3lame
SDK_VERSION=7.0
SDK="iPhoneSimulator"
PLATFORM="i386"
build_lame
SDK="iPhoneOS"
PLATFORM="armv7"
build_lame
SDK="iPhoneOS"
PLATFORM="armv7s"
build_lame
lipo -create build/$PROJECTNAME-* -output build/$PROJECTNAME.a
I then added the resulting libmp3lame.a to an iPhone project in Xcode 5.0.2. When building for an iOS device, it works fine. My problem starts when building for the simulator. When doing this, I get the following linker error:
Undefined symbols for architecture i386:
"_init_xrpow_core_sse", referenced from:
_init_xrpow_core_init in libmp3lame.a(quantize.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why does this error occur and how to solve it?
Here is a code snippet from quantize.c from the lame library:
static void
init_xrpow_core_c(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
{
// here, the initialization of xrpow is done in normal c code (i've cut that out to keep it small)
}
void
init_xrpow_core_init(lame_internal_flags * const gfc)
{
gfc->init_xrpow_core = init_xrpow_core_c;
#if defined(HAVE_XMMINTRIN_H)
if (gfc->CPU_features.SSE)
gfc->init_xrpow_core = init_xrpow_core_sse;
#endif
#ifndef HAVE_NASM
#ifdef MIN_ARCH_SSE
gfc->init_xrpow_core = init_xrpow_core_sse;
#endif
#endif
}
The problem was in the --host parameter to configure. It needs to be changed depending on the machine on which you want to run the Simulator. In my case, this is a MacBook Pro from mid 2009, running Mac OS X 10.8.5.
uname -a reports:
Darwin <my computer name>.local 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
So I wildly guessed that the --host parameter for configure for this environment, in which the Simulator runs, needs to be set to i686-apple-darwin12.5.0. The guess was right. My build script now looks like this:
mkdir -p build
rm -rf build/* #*/
function build_lame()
{
make distclean
./configure \
CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${SDK}.platform/Developer/SDKs/$SDK$SDK_VERSION.sdk" \
CC="/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch $PLATFORM -miphoneos-version-min=7.0" \
--prefix="/Users/$USER/Desktop/$PROJECTNAME" \
--host="$HOST" \
--disable-shared \
--enable-static \
--disable-frontend \
make
cp "$PROJECTNAME/.libs/$PROJECTNAME.a" "build/$PROJECTNAME-$PLATFORM.a"
}
PROJECTNAME=libmp3lame
SDK_VERSION=7.0
SDK="iPhoneSimulator"
HOST="i686-apple-darwin12.5.0"
PLATFORM="i686"
build_lame
SDK="iPhoneOS"
HOST="arm-apple-darwin9"
PLATFORM="armv7"
build_lame
SDK="iPhoneOS"
HOST="arm-apple-darwin9"
PLATFORM="armv7s"
build_lame
lipo -create build/$PROJECTNAME-* -output build/$PROJECTNAME.a
This works when building for Simulator in Xcode.