How to compile OpenCV with extra modules on OS X? - c++

I've previously compiled OpenCV 3.0 successfully following this guide, which essentially consists of the following steps:
Download all the prerequisites (XCode, Command Line Tools, CMake and OpenCV source)
Build static libs by configuring CMake (via gui) with:
Uncheck BUILD_SHARED_LIBS
Uncheck BUILD_TESTS
Add an SDK path to CMAKE_OSX_SYSROOT (if it matters, I used /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk).
Add x86_64 to CMAKE_OSX_ARCHITECTURES (emphasis mine, this seems to be the issue, I'm sure I've followed this step)
Uncheck WITH_1394
Uncheck WITH_FFMPEG
Configure and generate via CMake, then make and sudo make install from the CLI.
All of the above alone works fine.
I'm now looking to compile OpenCV with the extra modules. According to their read-me it should be as simple as filling out OPENCV_EXTRA_MODULES_PATH to <opencv_contrib>/modules in CMake and then building as usual.
I followed the steps outlined above with the added parameter and building OpenCV succeeds, however, when trying to use one of the extra modules in a program (namely cv::ximgproc::createStructuredEdgeDetection, if it matters), I'm getting the following error when compiling:
Undefined symbols for architecture x86_64:
"cv::ximgproc::createStructuredEdgeDetection(cv::String const&, cv::Ptr<cv::ximgproc::RFFeatureGetter const>)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've included the header which should include the above:
#include <opencv2/ximgproc.hpp>
I'm compiling via XCode, where I've set an additional header search path of /usr/local/include and a library search path of /usr/local/lib for the project, am I missing something here?
Standard OpenCV functionality works fine.
What could be the issue and how would I go about solving it?

OpenCV contrib modules are built correctly.
You just need to add the contrib libs to your dependencies, in this case adding: -lopencv_ximgproc.
All available libs can be found under <OPENCV_DIR>/install/ folder.
E.g. in my 32bit vc12 static build are in<OPENCV_DIR>/install/x86/vc12/staticlib folder.

Related

Resolve "ld: library not found for -ltensorflow_framework.2.3.0"

I'm trying to run a hello world macOS project that runs Tensorflow models. Documentation for Tensorflow (not to be confused by Tensorflow Lite) lack instructions on how to add the libtensorflow_framework to an XCode project that targets macOS.
What I did so far is:
create a conda environment (pip, python3.8.3)
pip install tensorflow==2.3.0rc0
locate the path to the tensorflow package, and drag and drop the libtensorflow_framework.2.3.0.dylib file into a group called lib that is located directly under the project root.
The I tried to run the app, but I got the following error:
ld: library not found for -ltensorflow_framework.2.3.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
which doesn't even make sense, because the file name is libtensorflow_framework.2.3.0.dylib and not ltensorflow_framework.2.3.0
So, I'm not sure what was the cause of that problem. However, I was able to finally link Tensorflow 2.2.0 to my Xcode project. (thanks to the hints that #Mikael H provided)
Here's what I did:
I installed TensorFlow using brew instead of python/pip.
brew install libtensorflow
I checked that /usr/local/include has the ./tensorflow/ headers and I added this path to the Xcode Header Search Path.
I checked that /usr/local/lib has the dylib files and added the path to Library Search Path.
I added the following arguments -ltensorflow -ltensorflow_framework.2.2.0 to the Other Linker Arguments.
You can find the Header Search Path, Library Search Path, and Other Linker Arguments by going to your target's settings -> Build Settings -> All & Combined.

Linker errors with Boost on Mac (OSX 10.10.02 | Xcode 6.1.1)

Recently I started working with Boost on Windows for a project. It needs to be cross-platform so I also installed it on Mac. Unfortunately; whenever I add it to the Xcode project it gives me a big slew of linker-errors and conversion-warnings.
Example of one of the linker-errors:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
boost::asio::error::get_system_category() in main.o
boost::system::error_code::error_code() in main.o "boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code
1 (use -v to see invocation)
Example of one of the conversion-warnings:
In file included from
/usr/local/Cellar/boost/1.57.0/include/boost/date_time/posix_time/posix_time_types.hpp:16:
/usr/local/Cellar/boost/1.57.0/include/boost/date_time/posix_time/posix_time_duration.hpp:24:21: warning: implicit conversion loses integer precision: 'long' to
'hour_type' (aka 'int') [-Wshorten-64-to-32]
time_duration(h,0,0)
I tried several installation methods and configuration methods but it still won't work.
These are my steps:
Compile Boost or get a compiled version of Boost.
Create an XCode project.
Enter this sample code in the main class.
Add the header and library paths to the Xcode project file.
Build.
Compile options I have tried:
Compiling from source using the official guide.
Compiling from source using a few scripts I found here on Stackoverflow.
Installing the brew package manager and downloading a package with binaries.
Configuration options I have tried:
Setting the header search path to /usr/local/Cellar/boost/1.57.0/include or equivalents and
setting the library search path to /usr/local/Cellar/boost/1.57.0/lib or the equivalents.
Setting just the header search path but not the library path.
Option 1 but recursive (causes more errors).
I would appreciate it a lot if someone could point me in the right direction. I think it's something Xcode related since all of the compiled versions give me the same errors.
I found the answer. After the header- and library paths are added to the projects search paths you need to go to "Build Phases". There you need to add the individual libraries you need to the "link libraries to binary" subsection. You can find the necessary files in the lib folder (in the boost folder).
You can choose for either the library files with .a extension or with the .mt.dylib extension. If you choose the .a extension files the library will be added to the compiled version of your program. If you choose the .mt.dylib files then the libraries will not be added to your compiled program. In this case you are assuming the dynamic library files are already present on the computer running the program.

ld: framework not found SDL2_image

I want to use SDL2_image frameworks (an extension of SDL2 framework), i've downloaded and copied the SDL2_image frameworks in the folders below:
/Library/Frameworks/
/System/Library/Frameworks
/Users/ < user > /Library/Frameworks
my code works fine with SDL2 framework but when i add SDL2_image framework i get an error as follows:
ld: framework not found SDL2_image
clang: error: linker command failed with exit code 1 (use -v to see invocation)
i tried clearing my framework search path, tried to change my valid architecture section none of them has worked.
I solved the problem by changing the Base SDK option to Current OS X for both the Target and Modules
Instructions are as follows:
from project navigator select your project -> Select build Settings -> from architectures field change Base SDK to Current OS X.

Tesseract working with XCode

I wish to use Tesseract with OpenCV on a C++ project (not iOS) I'm working, but I'm unable to get Tesseract to work with XCode. I've added the .dylib files for Leptonica and Tesseract and it works fine, but then I get the following error when I run the APIExample program
read_params_file: parameter not found: save_raw_choices
If I do not add the .dylib files and try adding the header files obtained through Homebrew, I get the following error
Undefined symbols for architecture x86_64:
"tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
tesseractTest() in main.o
"tesseract::TessBaseAPI::End()", referenced from:
tesseractTest() in main.o
I'm a little inexperienced with development in Mac OS X.
I encountered same problem and found only this remark on google groups:
http://code.google.com/p/tesseract-ocr/issues/detail?id=990
Basically, just use different tessdata - e.g. download spanish and set it as language. It would pass that step and show some results. Though they were not splendid in my case but at least you will see it working:).
Then I would recommend asking at the project google group for help...
I had the same problem when I didn't include the tesseract c flags and libraries when compiling.
if you add this to your cflags: pkg-config --cflags tesseract
and this to your libs: pkg-config --libs tesseract
then it should compile.
I know it is an old question but I didn't found anythink online and after hours I solved this issue by adding the line (-ltesseract) to the Build Settings -> Other Linker Flags in xCode

missing linkers in Qt

I have downloaded this project https://github.com/owncloud/sync-qt
next i did some modification to it.
I have added this files https://github.com/frankosterfeld/qtkeychain and sqlite3.h because of a missing libraries
Now the problem is that i have got those issues:
error: cannot find -lqtkeychain
error: cannot find -lsqlite3
error: cannot find -lkparts
error: cannot find -lkdeui
error: cannot find -lkdecore
error: collect2: error: ld returned 1 exit status
My OS is Fedora 18 64bit
I am using Qt Creator 2.5.0 Based on Qt 4.8.2 (64 bit)
I think this error is that i have some missing linkers !! but i don't know how to fix that ??
It is not the "linkers" which are missing, but some (development) libraries which are required to link the final executable (the linker takes the object files produced from your sources and all required libraries and links them together to produce the final executable file).
You need to make sure that the necessary -devel packages are installed - e.g. for the kde libraries, you need to install kdelibs4-devel. Since you have been able to compile the sources, it seems like these packages are already available on your system (they also contain the #include files, so without them compilation would already fail).
It seems that fedora stores these libraries below /usr/lib/kde4/devel/ (or /usr/lib64/kde4/devel/) - check that these files are there (e.g. /usr/lib64/kde4/devel/libkdecore.so). If not, install the respective -devel package, like
# yum install kdelibs4-devel