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

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)

Related

Open CV: cv::LineIterator undefined when compiling for Mac M1

I have an error of Undefined symbol cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool). So I've stumbled upon this issue that I am not sure if it is a bug but I cannot figure out how to fix it or what I am doing wrong.
I am trying to compile a library that uses OpenCV 4.5.1 that I compiled myself for a Mac Catalyst architecture. The OpenCV library I compiled for both arm64 and x86_64 architectures
$ lipo -info opencv2macos.framework/opencv2macos
Architectures in the fat file: opencv2macos.framework/opencv2macos are: x86_64 arm64
However when I try to compile a library that instantiates a cv::LineIterator line_it(mask, cv::Point(2, 4), cv::Point(10, 20), 8, false) I get this error:
Undefined symbols for architecture arm64:
"cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool)", referenced from:
getPointCorresp(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, cv::Mat const&, std::__1::vector<cv::Point_<float>, std::__1::allocator<cv::Point_<float> > > const&, cv::Mat const&, bool) in CMAUtil.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea what could be going wrong here?
After more researching and investigating, the issue was because I was using 2 opencv2 frameworks, one compiled for iOS devices and one compiled for Mac Catalyst.
When I compiled the framework for Catalyst I used a flag to change the name of the framework from opencv2 to opencv2macos which meant that the include headers were supposed to be like #include<opencv2macos/core.hpp>. However when I looked into a few more headers I could find #include<opencv2/imgproc.hpp> which explains why my project was somehow linking to the wrong framework - it was linking to code from opencv2.framework instead of opencv2macos.framework and because the two were different versions (the first one was 4.1.1 and the second was 4.5.1) I guess there was discrepancy within the implementation.

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).

Luabind Undefined Symbols/ Luabind::scope::scope

I have just started working with Luabind, and have attempted to run the Hello World test specified at http://www.rasterbar.com/products/luabind/docs.html#calling-lua-functions. However, this provides an undefined symbol error when attempted to compile.
Undefined symbols for architecture x86_64:
"luabind::scope::scope(std::__1::auto_ptr<luabind::detail::registration>)", referenced from:
luabind::scope luabind::def<void (*)(), luabind::detail::null_type>(char const*, void (*)(), luabind::detail::null_type const&) in TestClass.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Other functions such as luabind::open and luabind::call_function work correctly.
I installed both luabind and lua 5.1 through homebrew on osx.
It looks to me like you are compiling your program against libc++ and trying to link to a luabind library that was compiled against the stdlibc++ library.
The clue is std::__1::auto_ptr. This __1 inline namespace is used by libc++ to differentiate it's ABI from stdlibc++
Thus if
luabind::scope::scope(std::__1::auto_ptr<luabind::detail::registration>)
Cannot be found it is likely because libluabind doesn't have it. Dumping it's exported symbols you might find it has
luabind::scope::scope(std::auto_ptr<luabind::detail::registration>)
Instead.
If I am right, simply recompile libluabind targeting libc++ and you should find it works with your test program.

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.