Apple Mach-O Linker (Id) Error in xcode - c++

I am using xcode to work with SNAP package (http://memetracker.org).
When I Build, I get a few "Apple Mach-O Linker (Id) Error"
I read that I may have to add the right framework but I do not know how I can find what the right framework is.
Undefined symbols for architecture x86_64:
"_Env", referenced from:
_main in cliquesmain.o
"ExeStop(char const*, char const*, char const*, char const*, int const&)", referenced from:
TPt<TUNGraph>::operator->() const in cliquesmain.o
TVec<TVec<TInt, int>, int>::operator[](int const&) in cliquesmain.o
TVec<TInt, int>::operator[](int const&) in cliquesmain.o
TPt<TExcept>::operator->() const in cliquesmain.o
TRStr::GetNullRStr() in cliquesmain.o
TRStr::~TRStr() in cliquesmain.o
TVec<TInt, int>::operator[](int const&) const in cliquesmain.o
...
"WrNotify(char const*, char const*)", referenced from:
ErrNotify(char const*) in cliquesmain.o
"TCliqueOverlap::GetCPMCommunities(TPt<TUNGraph> const&, int, TVec<TVec<TInt, int>, int>&)", referenced from:
_main in cliquesmain.o
.....

Have you added this memetracker "library" correctly? Check out the tab "build phases", if not then there is probably your problem.
I assume you have the code/library in your project, so you have auto-completion, but to link this library you need to specify where to find it.

Related

Compiling hello world.cpp in terminal (macOS) [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Compiling a C++ program with GCC
(9 answers)
Closed 3 years ago.
I'm trying to compile a C++ helloWorld in terminal.
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I cd to the directory containing the code. I manage to compile with the command g++ -o hello c_helloworld.cpp. But when I use the command gcc -o hello c_helloworld.cpp I get the following error.
Undefined symbols for architecture x86_64: "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced
from:
std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&)
in c_helloworld-a3d3b8.o "std::__1::ios_base::getloc() const",
referenced from:
std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::basic_string,
std::__1::allocator >::__init(unsigned long, char)", referenced
from:
std::__1::basic_string, std::__1::allocator >::basic_string(unsigned long, char) in
c_helloworld-a3d3b8.o "std::__1::basic_string, std::__1::allocator
::~basic_string()", referenced from:
std::__1::ostreambuf_iterator > std::__1::__pad_and_output >(std::__1::ostreambuf_iterator >, char const*, char const*, char const*, std::__1::ios_base&, char) in
c_helloworld-a3d3b8.o "std::__1::basic_ostream >::put(char)", referenced from:
std::__1::basic_ostream >& std::__1::endl
(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o "std::__1::basic_ostream >::flush()", referenced from:
std::__1::basic_ostream >& std::__1::endl
(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o "std::__1::basic_ostream
::sentry::sentry(std::__1::basic_ostream >&)", referenced from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"std::__1::basic_ostream
::sentry::~sentry()", referenced from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o "std::__1::cout",
referenced from:
_main in c_helloworld-a3d3b8.o "std::__1::ctype::id", referenced from:
std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&)
in c_helloworld-a3d3b8.o "std::__1::locale::~locale()", referenced
from:
std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced
from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"std::__1::ios_base::clear(unsigned int)", referenced from:
std::__1::ios_base::setstate(unsigned int) in c_helloworld-a3d3b8.o "std::terminate()", referenced from:
___clang_call_terminate in c_helloworld-a3d3b8.o "___cxa_begin_catch", referenced from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
___clang_call_terminate in c_helloworld-a3d3b8.o "___cxa_call_unexpected", referenced from:
std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o
"___cxa_end_catch", referenced from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"___gxx_personality_v0", referenced from:
std::__1::basic_ostream >& std::__1::__put_character_sequence
(std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
std::__1::ostreambuf_iterator > std::__1::__pad_and_output >(std::__1::ostreambuf_iterator >, char const*, char const*, char const*, std::__1::ios_base&, char) in
c_helloworld-a3d3b8.o
std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o
std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o
Dwarf Exception Unwind Info (__eh_frame) in c_helloworld-a3d3b8.o ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
gcc is used to compile C programs (by default), g++ is for C++.
So, the behaviour is expected.
By default, gcc links to the standard C library.
If you want to compile C++ programs you can link to the standard C++ library by adding the following option:
gcc -o hello c_helloworld.cpp -lstdc++
PS. I suggest you to search the website before asking a question, there was already an answer for this.
Compiling a C++ program with gcc
Using g++ is easier for compiling .cpp files. Execute the compiled code by running ./outputfile in the directory. So basically that would be running
g++ file.cpp -o file && ./file
in the command line
Edit: My mistake.. gcc can be used here as well, but it's simpler to just use g++

QT Library imported in iOS native sdk

So the plan for this project is to have a QT library that can be used in a native SDK.
We have done a mock library that when imported in a QT App buit into a xcodeproj works without issues.
The library is static, running lipo -info returns x86_64 arm64.
I used the tutorial from https://alediaferia.com/2014/12/18/a-native-ios-app-with-a-qt-third-party-library/ but got stuck. After a bit of digging I got to the step where linking occurs this is the result:
Undefined symbols for architecture arm64:
"_pcre2_match_16", referenced from:
safe_pcre2_match_16(pcre2_real_code_16 const*, unsigned short const*, int, int, int, pcre2_real_match_data_16*, pcre2_real_match_context_16*) in libQt5Core.a(qregularexpression.o)
"_pcre2_match_context_create_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_jit_stack_assign_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_jit_stack_free_16", referenced from:
QThreadStorage<QPcreJitStackPointer*>::deleteData(void*) in libQt5Core.a(qregularexpression.o)
"_pcre2_get_ovector_pointer_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_match_data_free_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_config_16", referenced from:
QRegularExpressionPrivate::getPatternInfo() in libQt5Core.a(qregularexpression.o)
"_pcre2_pattern_info_16", referenced from:
QRegularExpressionPrivate::getPatternInfo() in libQt5Core.a(qregularexpression.o)
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_jit_compile_16", referenced from:
QRegularExpressionPrivate::optimizePattern() in libQt5Core.a(qregularexpression.o)
"_pcre2_match_context_free_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_pcre2_compile_16", referenced from:
QRegularExpressionPrivate::compilePattern() in libQt5Core.a(qregularexpression.o)
"_pcre2_code_free_16", referenced from:
QRegularExpressionPrivate::~QRegularExpressionPrivate() in libQt5Core.a(qregularexpression.o)
QRegularExpressionPrivate::compilePattern() in libQt5Core.a(qregularexpression.o)
"_pcre2_jit_stack_create_16", referenced from:
safe_pcre2_match_16(pcre2_real_code_16 const*, unsigned short const*, int, int, int, pcre2_real_match_data_16*, pcre2_real_match_context_16*) in libQt5Core.a(qregularexpression.o)
"_pcre2_match_data_create_from_pattern_16", referenced from:
QRegularExpressionPrivate::doMatch(QString const&, int, int, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, QRegularExpressionPrivate::CheckSubjectStringOption, QRegularExpressionMatchPrivate const*) const in libQt5Core.a(qregularexpression.o)
"_uncompress", referenced from:
qUncompress(unsigned char const*, int) in libQt5Core.a(qbytearray.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How the project looks:
Does anyone know what is going on?
You're missing the linking to libqtpcre2
Add
-lqtpcre2
into your "OTHER LINKER FLAGS" in xcode's "build settings"

How to get face_detection_ex.cpp in dlib to work in c++?

I'm new to c++, so sorry if there is an obvious solution I'm missing. I'm trying to run this example code for dlib in c++. I'm getting this error...
In file included from /Users/john/ClionProjects/dlib/examples/face_detection_ex.cpp:41:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/gui_widgets.h:13:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/widgets.h:9:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/drawable.h:8:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/../gui_core.h:14:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/xlib.h:4:
/Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:11:2: error: "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
#error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
^
/Users/johnoberhauser/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:12:2: error: "Also make sure you have libx11-dev installed on your system"
#error "Also make sure you have libx11-dev installed on your system"
I've tried going into /dlib/CMakeLists.txt and adding
set(DLIB_NO_GUI_SUPPORT OFF)
I know it's found the X11 package as I'm not getting a message from the cmake there (and I just installed XQuartz)
Also, I'm using Clion, so I'm not running cmake from the command line. And I'm on OSX
Edit: I tried removing the parts of the code that use the gui, just to see if it would work. But I then get this error:
Undefined symbols for architecture x86_64:
"_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives", referenced from:
_dlib_check_consistent_assert_usage in main.cpp.o
"_cblas_saxpy", referenced from:
dlib::blas_bindings::cblas_axpy(int, float, float const*, int, float*, int) in main.cpp.o
"_cblas_sscal", referenced from:
dlib::blas_bindings::cblas_scal(int, float, float*) in main.cpp.o
"_dgesvd_", referenced from:
dlib::lapack::binding::gesvd(char, char, int, int, double*, int, double*, double*, int, double*, int, double*, int) in main.cpp.o
"_png_create_info_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_create_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_destroy_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
"_png_get_bit_depth", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_color_type", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_height", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_width", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_rows", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_init_io", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_read_png", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_longjmp_fn", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader_user_error_fn_silent(png_struct_def*, char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_palette_to_rgb", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_sig_bytes", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_sig_cmp", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
ld: symbol(s) not found for architecture x86_64
I think this is a separate issue from the first one, but idk, maybe they are related? For this issue, I've tried doing what was mentioned here https://github.com/davisking/dlib/issues/57 I made the link for the first part, then added these lines to my cmakelist.txt
include_directories(../../../../usr/X11/lib)
include_directories(../../../../usr/local/include)
include_directories(../../../../usr/local/lib)
Didn't seem to fix the issue though.
Edit 2: So I think both these issues are resolved now. I think added those include_directories lines that I mentioned above help. Also, I started using cmake from the command line, instead of with clion.
However, I am now getting a new error :/
Undefined symbols for architecture x86_64:
"dlib::base_window::invalidate_rectangle(dlib::rectangle const&)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::base_window::set_size(int, int)", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::image_window::add_overlay(std::__1::vector<dlib::image_display::overlay_rect, std::__1::allocator<dlib::image_display::overlay_rect> > const&)", referenced from:
void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::__1::vector<dlib::rectangle, std::__1::allocator<dlib::rectangle> > const&, dlib::rgb_pixel) in main.cpp.o
"dlib::image_window::clear_overlay()", referenced from:
_main in main.cpp.o
"dlib::image_window::image_window()", referenced from:
_main in main.cpp.o
"dlib::image_window::~image_window()", referenced from:
_main in main.cpp.o
"dlib::popup_menu_region::disable()", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)", referenced from:
dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const in main.cpp.o
"dlib::image_display::get_image_display_rect() const", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
One issue after another :/
Edit 3: Success! So I was using Clion for compiling. Even though the cmake from clion is the same version as the cmake I'm using in the command line, it just didn't work for some reason.
I solved this by deleting the "cmake-build-debug" directory.
Then reopen the project(CLion will regenerate it).
It seems there remain some cache files would affect the compiling.
But before this step, please make sure you do install XQuartz.

Clang undefined behavior checker link error

Upon trying to compile a C++ source file with clang 3.5 with the undefined behavior checker
clang++-3.5 -std=c++11 -fsanitize=undefined main.cpp
I am getting the following error upon linking:
Undefined symbols for architecture x86_64:
"typeinfo for __cxxabiv1::__class_type_info", referenced from:
__ubsan::checkDynamicType(void*, void*, unsigned long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
"typeinfo for __cxxabiv1::__si_class_type_info", referenced from:
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
"typeinfo for __cxxabiv1::__vmi_class_type_info", referenced from:
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
ld: symbol(s) not found for architecture x86_64
Do I need to link with an additional library?
It seems you are missing libc++abi. Try adding
-lc++abi
to your link command.

Error on C++'s Hello World

I started learning C++ and I tried to run the classic Hello World program:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, World!";
return 0;
}
but when I compile it in terminal using GCC I always get that error:
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::cout", referenced from:
_main in ccpe3DPY.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccpe3DPY.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccpe3DPY.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccpe3DPY.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccpe3DPY.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
can you tell me why?
You've compiled your program with gcc, which is a C compiler, not a C++ compiler. Use g++ instead; it knows to include the C++ run-time libraries, where those missing symbols are defined.
Thats a C compiler you need to use a C++ compiler like rob says above g++. Also if you are a beginner I would highly recommend using Microsoft visual studio express if you run a windows OS; if not then netbeans.