How to use dlib in Xcode C++ console application - c++

I have installed dlib using Homebrew.
brew install dlib
How can I create a C++ project that uses dlib in Xcode ? I have tried some build settings. However, it does not work.
Add /usr/local/Cellar/dlib/19.1_2/include to Header Search Paths
Add /usr/local/Cellar/dlib/19.1_2/lib to Library Search Paths
Add -ldlib to Other Linker Flags
I have got these errors:
Undefined symbols for architecture x86_64:
"_cblas_dgemm", referenced from:
dlib::blas_bindings::cblas_gemm(dlib::blas_bindings::CBLAS_ORDER, dlib::blas_bindings::CBLAS_TRANSPOSE, dlib::blas_bindings::CBLAS_TRANSPOSE, int, int, int, double, double const*, int, double const*, int, double, double*, int) in main.o
"_cblas_saxpy", referenced from:
dlib::blas_bindings::cblas_axpy(int, float, float const*, int, float*, int) in main.o
"_cblas_sscal", referenced from:
dlib::blas_bindings::cblas_scal(int, float, float*) in main.o
"_dgesvd_", referenced from:
dlib::lapack::binding::gesvd(char, char, int, int, double*, int, double*, double*, int, double*, int, double*, int) 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)

By default, homebrew installs dlib without any BLAS library. I have solved the issue by linking Accelerate.framework with binary file.
Accelarate.framework is provided by Apple. It includes everything that dlib needs. Further information:
https://developer.apple.com/reference/accelerate
In order to add that library to your project,
Choose the project name in project navigator (Left Side).
If it is not appeared on the editor, click "Show project and targets list" and choose target binary.
Choose "Build Phases" shown below.
Expand "Link Binary With Libraries" and click add items icon.
Search Accelerate.framework and add it.
Change its status to "Required".
Alternatively, it may work if you uninstall dlib and install dlib with brew install dlib --with-openblas command. However, I haven't tested it yet.
By the way, Homebrew warns about openblas if you brew info openblas:
macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

brew cask install xquartz
brew install gtk+3 boost
brew install dlib
Then your setup will be fine. I am using without adding Accelerate.framework explicitly.

Related

Undefined symbols error on c++/qt6 app when linking on macos

I use g++-12 and qt6 installed via homebrew.
At linking my executable on macos, I get this error:
Undefined symbols for architecture x86_64:
"__ZN9QMetaType25registerConverterFunctionERKSt8functionIFbPKvPvEES_S_", referenced from:
The function it's not finding is:
QMetaType::registerConverterFunction(std::function<bool (void const*, void*)> const&, QMetaType, QMetaType)
but in the QtCore lib, the closest corresponding function I can find is:
QMetaType::registerConverterFunction(std::__1::function<bool (void const*, void*)> const&, QMetaType, QMetaType)
Notice the ::__1 namespace
I never got into this kind of problem. Any clue where this comes from?
(the codes compile fine on linux and I can even cross compile it on linux for windows via mingw)

cmake does not find openssl library on mac os x (despite manually adding )

I'm trying to compile https://github.com/dmikushin/binance-cxx-api on osx 10.13.6
(since code is written for linux i had to adjust things a little)
I get following errors (which are openssl related as far as i see):
Undefined symbols for architecture x86_64:
"_EVP_sha256", referenced from:
binance::hmac_sha256(char const*, char const*) in binance_utils.cpp.o
"_HMAC", referenced from:
binance::hmac_sha256(char const*, char const*) in binance_utils.cpp.o
"_SHA256_Final", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
"_SHA256_Init", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
"_SHA256_Update", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
ld: symbol(s) not found for architecture x86_64
The project is cmake based and does not find or link against openssl (installed with homebrew)
I added include and lib dirs directly in the cmake GUI -> compiler, linker flag
(took the include dir, still gave me the errors)
Also applied several combinations of below and alike => didn't make the error go away
cmake -DOPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2d_1/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/Cellar/openssl/1.0.2d_1/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/Cellar/openssl/1.0.2d_1/lib/libssl.dylib
googling did not bring up new ideas (most of these errors seem to be fixed by the cmake -DOPENSSL.. option)
Does anyone have an idea?
Did you consider editing the cmake project ?
Adding the following lines in the CMakeLists.txt:
FIND_PACKAGE(OpenSSL)
if(${OpenSSL_FOUND})
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
endif()
And editing the following line to link to OpenSSL
target_link_libraries(${PROJECT_NAME} jsoncpp curl websockets ssl crypto)

Errors using OpenCV with opencv_contrib on Xcode

For my application running on iPhone I am using OpenCV using opencv2.framework in Xcode with objective-c and C++ as languages. My development worked well until I wanted to introduce cv::Tracker that is not included in opencv2.framework but part of opencv_contrib.
I rebuilt and installed from the source opencv-3.4.0 with opencv_contrib-master using CMake and terminal commands make and install.
In Xcode I have set
HEADER_SEARCH_PATHS = /usr/local/include and
LIBRARY_SEARCH_PATHS = /usr/local/lib
When compiling I get a long list of errors of the style:
Undefined symbols for architecture x86_64:
"cv::error(int, cv::String const&, char const*, char const*, int)",
referenced from:
cv::Mat::Mat(int, int, int, void*, unsigned long) in OpenCVRenderer.o
"cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&) in
OpenCVRenderer.o
cv::Mat::Mat(cv::Size_<int>, int, cv::Scalar_<double> const&) in
OpenCVRenderer.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in OpenCVRenderer.o
"cv::polylines(cv::_InputOutputArray const&, cv::_InputArray const&,
bool, cv::Scalar_<double> const&, int, int, int)", referenced from:
.
.
.
I set OTHER_LDFLAGS = (list of opencv dylibs) preceeded by a "-" sign
Now I get errors as if the libraries are not found while there are in fact in /usr/local/lib
For example I get:
ld: library not found for -libopencv_core.3.4.0.dylib
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Any help?
Thank you.
There are a couples of problems with your settings.
You only specified where to find the libraries, not opencv2.framework. You should either specify framework_search_path (and link your framework to the project) or link the corresponding libraries.
You said you were building an iPhone app, yet the error says Undefined symbols for architecture x86_64:. That is, either you built your app for phone simulator or for mac. Yet, your framework is most likely built for iPhone architecture (armv7 and arm64). This case, you need to rebuild the framework. If you build iPhone app, do not link any dylib libraries in /usr/local/lib/.
Note that libopencv_core.3.4.0.dylib is part of normal opencv so the error has nothing to do with opencv_contrib (yet).

linking Boost library to Xcode project

I'm trying to create a project that uses the Boost library. I'm on OS X 10.9.5 (I should update that) and using Xcode 6.2. I installed boost with homebrew brew install boost and it's located in /usr/local/Cellar/boost/1.59.0. I added the path the the /usr/local/Cellar/boost/1.59.0/include to the header search path in Xcode and it seems to recognize it because the autocomplete hinting works.
In the boost documentation it mentions that some of the Boost libraries must be built before they can be used. I assume homebrew took care of that because I have a bunch of .a and .dylib files in /usr/local/Cellar/boost/1.59.0/lib
I'm still new to C++ and the Xcode build process but it seems I still need to link the compiled libraries to my project. I tried adding the path /usr/local/Cellar/boost/1.59.0/lib to my project's library search paths but I'm not sure if that is correct.
Here is the error I get when I try to build my project.
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::create_directory(boost::filesystem::path const&) in main.o
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&) in main.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 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)
Is there something else I need to configure to get this to work?
Adding the path is correct but you also need to specify the libraries you need. On the commandline you would use -l for that in Xcode you can add them to Other Linker Flags.
The libraries you need are boost_filesystem and boost_system.

Compiling frameworks(cppunit, boost, ++) from terminal to work with Xcode 4.6

I'm trying to use some frameworks with Xcode 4.6.2.
C++ frameworks, such as cppunit and boost that is supposed to be compiled and linked to in my projects always fails with "Undefined symbols for architecture x86_64[...]" or i386 for that matter when I'm trying different build settings.
I have tried setting Compiler to clang and g++ with various sets of cpu-architecture flags (64, 32 and 32_64). I have come to a point where I can't find any solutions on my own.
I've also tried the fail safe packages from without any luck:
brew install cppunit universal
port install cppunit +universal
(Also without success the Boost library)
Also, a lot of tries on Boost is done. Bjam has really made a lot of work the last 24 hours. Multiple settings has been tried:
http://www.codeproject.com/Tips/555070/Boost-vs-OSX-iOS-XCode and
http://boost.2283326.n4.nabble.com/Errors-compiling-Boost-Log-on-OS-X-tp4646151p4646299.html
And more in pure trial and error on my part.
So my question is: what are the combination of compiler and linker and the respective flags I should use in order to make it work in my Xcode projects?
Per request from Captain Obvlious, here are some errors when running an application with Boost::Test:
Undefined symbols for architecture x86_64:
"boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)", referenced from:
my_test::test_method() in main.o
"boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)", referenced from:
my_test::test_method() in main.o
"boost::unit_test::framework::master_test_suite()", referenced from:
init_unit_test_suite(int, char**) in main.o
"boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&)", referenced from:
boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>) in main.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)", referenced from:
___cxx_global_var_init2 in main.o
"boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)", referenced from:
boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>) in main.o
"vtable for boost::unit_test::unit_test_log_t", referenced from:
boost::unit_test::unit_test_log_t::unit_test_log_t() in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You need to add whichever library those functions depend on via "Link Binary With Libraries" in the Build Phases of your Project. However, this then brings up the dreaded EXC_BAD_ACCESS you can read about elsewhere on Stack.