I understand what an unresolved symbol error is, but I don't understand why I'm getting it in this particular situation with this particular library. Here is the output of the error.
Undefined symbols for architecture x86_64:
"soci::soci_error::soci_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
soci::type_conversion<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::from_base(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, soci::indicator, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in Inspector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Note that I am using the following link flags:
-L/usr/local/lib -lsoci_core -lsoci_postgresql -lpq -ldl
Note also that references to other symbols (e.g., the soci::session constructor and destructor) are being resolved.
What am I doing wrong? Is there another soci library that I should also be linking against?
EDIT: Note that I am working on Mac OS X, and have tried both the installation through homebrew (via brew install soci --with-pg), and the standalone installations of 3.2.2 and 3.2.1.
I don't know why this solved the error, but changing from libc++ to libstdc++ resolved it.
Related
I want to enable debug version of libc++ in macOS, so I define _LIBCPP_DEBUG=1 in cxx_build_flags [Debug Version of libC++],
but unable to link debug function of libc++. I guess there is only release version of libc++ in my system, so how can I get the debug version of libc++ in macOS
Undefined symbols for architecture x86_64:
"std::__1::__libcpp_db::__decrementable(void const*) const", referenced from:
void std::__1::__nth_element<std::__1::__debug_less<std::__1::__less<float, float> >&, std::__1::__wrap_iter<float*> >(std::__1::__wrap_iter<float*>, std::__1::__wrap_iter<float*>, std::__1::__wrap_iter<float*>, std::__1::__debug_less<std::__1::__less<float, float> >&)
I think I got this to work!
So the steps I took,
Check your toolchains __config file for _LIBCPP_VERSION's value.
Browse the source repo for the commit where that version was set
From that commit, find the debug.cpp file
Include/compile/link the debug.cpp with your project (and remember to set _LIBCPP_DEBUG=1).
For me the intermediate results for the steps were (with Catalina, XCode Version 11.3.1)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__config was at version 8000
Looking at the history at https://github.com/llvm/llvm-project/commits/main?&path[]=libcxx&path[]=include&path[]=__config I found commit https://github.com/llvm/llvm-project/commit/25977548aa5ad7cfe45a17e4ba136abfa4613b96#diff-0a85f740cd20254bc3bb03975c89d93a
The debug.cpp for that commit is at https://github.com/llvm/llvm-project/blob/25977548aa5ad7cfe45a17e4ba136abfa4613b96/libcxx/src/debug.cpp
I try to reactivate this thread without an answer with more details.
I have the same issue. This is very easy to reproduce:
#include <string>
int main()
{
std::string name;
return 0;
}
and then compile with:
clang++ -D_LIBCPP_DEBUG=1 main.cpp
We obtain:
Undefined symbols for architecture x86_64:
"std::__1::__libcpp_db::__insert_c(void*)", referenced from:
void std::__1::__libcpp_db::__insert_c<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in main-7ff3c5.o
"std::__1::__libcpp_db::__erase_c(void*)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string() in main-7ff3c5.o
"std::__1::__c_node::~__c_node()", referenced from:
std::__1::_C_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::~_C_node() in main-7ff3c5.o
"std::__1::__get_db()", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string() in main-7ff3c5.o
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string() in main-7ff3c5.o
"typeinfo for std::__1::__c_node", referenced from:
typeinfo for std::__1::_C_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in main-7ff3c5.o
"vtable for std::__1::__c_node", referenced from:
std::__1::__c_node::__c_node(void*, std::__1::__c_node*) in main-7ff3c5.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)
And if I use g++-9 providen by brew (a real g++ not a disguised Apple Clang compiler), it compiles and runs perfectly.
Forgetting to use debug mode of libc++, is it the only solution?
NB: I saw the same question in https://forums.developer.apple.com/thread/99194
and still no answer.
I feel that all dependences are installed, and I want to install Caffe without GPU, but when I do make all, there is an error:
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolch ain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_conv_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lcn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lrn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_pooling_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_relu_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_sigmoid_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_softmax_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_tanh_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
clang: warning: argument unused during compilation: '-pthread'
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
caffe::WindowDataLayer<float>::load_batch(caffe::Batch<float>*) in window_data_layer.o
caffe::WindowDataLayer<double>::load_batch(caffe::Batch<double>*) in window_data_layer.o
caffe::ReadImageToCVMat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, bool) in io.o
"cv::imencode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
caffe::ReadImageToDatum(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, caffe::Datum*) in io.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
I do not understand why this happens and it seems like my Xcode may have some problems? Could someone help me?
There are two separate things here:
"clang: warning: argument unused during compilation: '-pthread'" is an ignoreable (although annoying) compiler warning (not error) that you often get with MacOS clang, these days it has pthreads support builtin. Ignore it, or suppress it with -Wno-error=unused-command-line-argument
whereas "Undefined symbols for architecture x86_64: ... clang: error: linker command failed with exit code " is an actual error. Fix that. (Looks like a missing header file to me, so check your -I... include paths. I don't know Caffe so I can't comment more on that.)
make sure you install openCV before building caffe.
brew install -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv
please go threw caffe OS X Installation.
I had a similar problem as well. It could be the Makefile.config. Please check the paths you provided for PYTHON_INCLUDE and PYTHON_LIB.
I had given the brew python path to PYTHON_INCLUDE and system path to PYTHON_LIB. I also made sure that the caffe python was added to the python path before compiling.Hope this information is of help.
I've managed to compile Swiften library for a iOS project, but now I'm having linking errors related to Boost library.
I've compiled Boost following these steps, the error I'm getting during linking is:
Undefined symbols for architecture arm64:
"vtable for boost::filesystem::detail::utf8_codecvt_facet", referenced from:
__GLOBAL__I_a in boost(path.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've read some articles which suggest including some compilation params, but not sure which params or where should I put them. I've also reached this thread with no solution. Anyone else faced this issue? Anyone succeeded compiling and running Swiften for iOS? Any tip on the right direction would be much appreciated.
UPDATE 1
It seems filesystem and program_options libs share utf8_codecvt_facet object, and one was overriding the other while building boost. Finally, I managed to compile the whole Swiften library, but when I try to use it I'm getting more linking errors :( I get this error when I declare a JID object on my main class:
Undefined symbols for architecture armv7:
"Swift::StringPrep::getPrepared(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
Swift::StringPrep::Profile)", referenced from:
Swift::JID::nameprepAndSetComponents(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&) in JID.o
I was working on some computer vision code with OpenCV, and wanted to try running OpenCV by compiling the OpenCV tutorial code using CMake. When I tried to compile and run the basic display_image program, it compiled successfully and ran(I added a CMakeLists.txt file and ran cmake . and then make in Terminal. However, when I applied the same procedure to run a few other programs, it didn't work.
I got the following error message
$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/censam/OpenCV/Vision Code/Examples/grabcut
$ make
Linking CXX executable grabcut
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, int)", referenced from:
_main in grabcut.cpp.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
GCApplication::showImage() const in grabcut.cpp.o
"cv::Exception::Exception(int, std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, std::__1::basic_string<char, >
std::__1::char_traits<char>, std::__1::allocator<char> > const&, >
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >
const&, int)", referenced from:
getBinMask(cv::Mat const&, cv::Mat&) in grabcut.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [grabcut] Error 1
make[1]: *** [CMakeFiles/grabcut.dir/all] Error 2
make: *** [all] Error 2
My CMakeLists.txt file is as follows:
cmake_minimum_required(VERSION 2.8)
project( grabcut )
find_package( OpenCV REQUIRED )
add_executable( grabcut grabcut.cpp )
target_link_libraries( grabcut ${OpenCV_LIBS} )
May I know why this happens?I suspect it could be because CMake hasn't linked the required libraries during compiling. When I tried this with XCode, I got the same result, but I prefer to use CMake so that I can port my code over to linux systems more easily.
I found the following link Linking OpenCV 2.3 program in Mac OS X Lion: symbol(s) not found for architecture x86_64 also had the same problem, but the issue doesn't seem to have been resolved.
Any help on how I can get my program to compile and run using CMake in OSX Mavericks will be much appreciated.
Change the compiler from clang to g++-4.2.
A more detailed explain could be find here.
I have setup OpenCV2 in XCode but unfortunately imshow does not work:
Undefined symbols for architecture x86_64:
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray 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 am running OS X 10.8.4 with latest XCode.
I have attached a few images below to show the setup in XCode and the libraries.
So far it seems that other functions work fine with OpenCV, except this.
I'm going to go out on a limb and say that you compiled OpenCV2 with libstdc++, and are now compiling your application with libc++ support.
You need to compile OpenCV2 with the same C++ library, otherwise it will not be able to link.
if you do an nm of the OpenCV2 library, if it was compiled with libstdc++, it will look like:
cv::imshow(std::string const&, cv::_InputArray const&)
while if it was compiled with libc++, it would look like:
cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)
to get the demangled symbol do:
nm library | c++filt | grep cv::imshow