I'm using VLCKit (MobileVLCKit.framework) in my iOS project. At first everything works well. Then I add some C++ code, so some file are .mm files. When I compile, it failed. Xcode log
Undefined symbols for architecture armv7:
"std::runtime_error::runtime_error(std::string const&)", referenced from:
libebml::CRTError::CRTError(std::string const&, int) in MobileVLCKit(StdIOCallback.o)
"std::ostream& std::ostream::_M_insert<void const*>(void const*)", referenced from:
libebml::IOCallback::writeFully(void const*, unsigned long) in MobileVLCKit(IOCallback.o)
libebml::IOCallback::readFully(void*, unsigned long) in MobileVLCKit(IOCallback.o)
"std::runtime_error::runtime_error(std::string const&)", referenced from:
libebml::IOCallback::writeFully(void const*, unsigned long) in MobileVLCKit(IOCallback.o)
libebml::IOCallback::readFully(void*, unsigned long) in MobileVLCKit(IOCallback.o)
"VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >", referenced from:
...
I don't know why and how to solve this problem.
I found the solution: Change C++ Standard Library to libstdc++ (GNU c++ standard library) in the Build Settings.
Related
I'm having issues linking the mat.h file from Matlab to my c++ file.
My portion where I'm including the directory for the .h file within my Makefile is here:
set(MAT_ROOTDIR "/Applications/MATLAB_R2021a.app/extern/include")
target_include_directories(onnxruntime_test PRIVATE ${MAT_ROOTDIR})
I simply #include <mat.h> within my cpp file, but I get this error:
Undefined symbols for architecture x86_64:
"_matClose_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_matGetVariable_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_matOpen_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_mxDestroyArray_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_mxGetNumberOfElements_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_mxGetPr_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_mxIsDouble_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.cpp.o
"_mxIsEmpty_800", referenced from:
matread(char const*, std::__1::vector<double, std::__1::allocator<double> >&) in model_explorer.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)
I am pretty sure it is finding the right .h file but I'm not sure why I'm still getting undefined symbols. Is there another thing I should be linking as well? Any help would be greatly appreciated!
I am working on a Mac OS.
I'm thinking you don't know what .h files are.
You probably need a -l argument when you link so it links the library.
The errors you're getting are not due to a failure to find the include file. They're due to an error finding compiled code -- which is probably in a library.
You can simulate yourself like this:
void foo();
int main(int, char **) {
foo();
}
Compile that, and you'll get a similar error to the errors you listed -- because we don't have the code for foo() anywhere, and we haven't linked against a library that has it, either.
I'm trying to link id3lib statically to my XCode project.
I've found some answers in other threads suggesting to add as linker flags the full path to the .a file. This works but produces a huge number of errors:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::copy(char*, unsigned long, unsigned long) const", referenced from:
dami::io::StringReader::readChars(unsigned char*, unsigned int) in libid3.a(tag_impl.o)
dami::convert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, ID3_TextEnc, ID3_TextEnc) in libid3.a(utils.o)
dami::io::StringReader::readChars(unsigned char*, unsigned int) in libid3.a(tag_parse_lyrics3.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
ID3_TagImpl::IsV2Tag(ID3_Reader&) in libid3.a(tag_impl.o)
dami::mm::parse(ID3_TagImpl&, ID3_Reader&) in libid3.a(tag_parse_musicmatch.o)
dami::id3::v1::parse(ID3_TagImpl&, ID3_Reader&) in libid3.a(tag_parse_v1.o)
dami::lyr3::v1::parse(ID3_TagImpl&, ID3_Reader&) in libid3.a(tag_parse_lyrics3.o)
dami::lyr3::v2::parse(ID3_TagImpl&, ID3_Reader&) in libid3.a(tag_parse_lyrics3.o)
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
void std::__1::vector<ID3_Field*, std::__1::allocator<ID3_Field*> >::__push_back_slow_path<ID3_Field* const>(ID3_Field* const&) in libid3.a(frame_impl.o)
"std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> >::reserve(unsigned long) in libid3.a(tag.o)
std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> >::__grow_by_and_replace(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned char const*) in libid3.a(tag.o)
std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>,
And so on. Again, googling suggests that the issue might be the fact the choice for standard library. Hence I tried to switch the C++ Standard Library field from "Compiler Default" to "libstdc++" (and I'm still getting the huge amount errors) or to "libc++" - and I'm getting way less errors, namely:
Undefined symbols for architecture x86_64:
"_compress", referenced from:
dami::io::CompressedWriter::flush() in libid3.a(io_decorators.o)
"_iconv", referenced from:
dami::convert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, ID3_TextEnc, ID3_TextEnc) in libid3.a(utils.o)
"_iconv_close", referenced from:
dami::convert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, ID3_TextEnc, ID3_TextEnc) in libid3.a(utils.o)
"_iconv_open", referenced from:
dami::convert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, ID3_TextEnc, ID3_TextEnc) in libid3.a(utils.o)
"_uncompress", referenced from:
dami::io::CompressedReader::CompressedReader(ID3_Reader&, unsigned int) in libid3.a(io_decorators.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 have no idea of how to solve this. If I remove the library full path as linker flag, everything seems to work, but the library is linked dynamically (which doesn't work for me). I'm on Mac OS X 10.10; id3lib was installed via homebrew (manual installation tests led to similar results).
Does anybody have a clue?
Thanks,
Daniele
Go to Link Binary With Libraries in project settings and link your project with system libraries libz (_compress, _uncompress) and libiconv ( _iconv, _iconv_close, _iconv_open).
I have read a few related answers and some articles online as well as the official Google Test documentation, but since I lack experience in this area I am very insecure about a few things and seek guidance.
I am starting a brand new pet project in c++ and I want to write proper tests as I code along, ran into Google Test and decided to give it a try.
Currently this is my folder structure:
/
/bin
/main.cpp
/lib
/lib/db
/lib/external/googletest
My idea is to have the tests and class files in their own folders, for example:
/lib/db/db.h
/lib/db/db.cpp
/lib/db/db.test
Question #1
Is there a naming convention or expectation for the file containing the tests? (/lib/db/db.test in that example above)
Question #2
I ran the following commands
cd lib/external/googletest/googletest
cmake .
make
make install
cp lib*.a /usr/local/lib
cp -r include/gtest/ /usr/local/include/
And seeing how it ended up creating a series of .h files in /usr/local/include/gtest, I expected to be able to #include <gtest/gtest.h> and be able to run tests, I added this to my main.cpp:
TEST(Param1, Param2) {
EXPECT_EQ(1, 1);
}
and when building the following error showed up:
Undefined symbols for architecture x86_64:
"testing::AssertionSuccess()", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in main-230b96.o
"testing::Test::SetUp()", referenced from:
vtable for Param1_Param2_Test in main-230b96.o
"testing::Test::TearDown()", referenced from:
vtable for Param1_Param2_Test in main-230b96.o
"testing::Test::Test()", referenced from:
Param1_Param2_Test::Param1_Param2_Test() in main-230b96.o
"testing::Test::~Test()", referenced from:
Param1_Param2_Test::~Param1_Param2_Test() in main-230b96.o
"testing::Message::Message()", referenced from:
Param1_Param2_Test::TestBody() in main-230b96.o
"testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
Param1_Param2_Test::TestBody() in main-230b96.o
"testing::internal::AssertHelper::~AssertHelper()", referenced from:
Param1_Param2_Test::TestBody() in main-230b96.o
"testing::internal::GetTestTypeId()", referenced from:
___cxx_global_var_init in main-230b96.o
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
___cxx_global_var_init in main-230b96.o
"testing::internal::IsTrue(bool)", referenced from:
testing::internal::scoped_ptr<std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::reset(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in main-230b96.o
testing::internal::scoped_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::reset(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in main-230b96.o
"testing::internal::EqFailure(char const*, 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&, bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&) in main-230b96.o
"testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
Param1_Param2_Test::TestBody() in main-230b96.o
"typeinfo for testing::Test", referenced from:
typeinfo for Param1_Param2_Test in main-230b96.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: *** [all] Error 1
Solution
Thanks to trojanfoe I fixed my makefile to look like this:
CC=g++
target_folder=bin
all:
$(CC) *.cpp -o $(target_folder)/prod
./bin/prod
test:
$(CC) *.cpp -o $(target_folder)/test lib/external/googletest/googletest/libgtest.a lib/external/googletest/googletest/libgtest_main.a
./bin/test
clean:
rm -f $(target_folder)/* *.o
And now it works just fine, please keep in mind that this is a skeleton project and I need to structure the test files and entry point, so at this point its just compiling a basic test.
You have forgotten to link-in the google test library with your executable.
I've been working on a project that contains two parts:
A Cocoa Touch Static Library (.framework)
A Demo application that uses my (.framework) Static Library
I have learned that any .framework that is added to my .framework (i.e., opencv2.framework) must also be added to my Demo application. I've also learned that the Build Settings for Architectures must be the same and the Build Settings Search Paths must be set.
Happy as can be, I've been building and using my .framework in my Demo application for quite some time. Recently, I've added Google Protocol Buffers to my .framework.
My .framework is compiling and all seems well in the .framework.
Of course, my Demo application wasn't very happy.
So now I've added the libprotobuf-lite.a to my Demo application and added the path to the Header files in the Header Search Paths.
This should do the trick. But instead, I receive the following errors and thus far have not been able to find an answer. Here is the error log:
Undefined symbols for architecture armv7:
"vtable for google_public::protobuf::Message", referenced from:
google_public::protobuf::Message::Message() in Test-Remote-iOS-Aggregate(ftype.pb.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"typeinfo for google_public::protobuf::Message", referenced from:
typeinfo for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
message::FtypeMessage const* google_public::protobuf::internal::dynamic_cast_if_available<message::FtypeMessage const*, google_public::protobuf::Message const*>(google_public::protobuf::Message const*) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::GetTypeName() const", referenced from:
vtable for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::InitializationErrorString() const", referenced from:
vtable for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::SpaceUsed() const", referenced from:
vtable for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::ReflectionOps::Merge(google_public::protobuf::Message const&, google_public::protobuf::Message*)", referenced from:
message::FtypeMessage::MergeFrom(google_public::protobuf::Message const&) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::WireFormat::VerifyUTF8StringFallback(char const*, int, google_public::protobuf::internal::WireFormat::Operation)", referenced from:
google_public::protobuf::internal::WireFormat::VerifyUTF8String(char const*, int, google_public::protobuf::internal::WireFormat::Operation) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"_OBJC_CLASS_$_CVImageConverter", referenced from:
objc-class-ref in Test-Remote-iOS-Aggregate(IDMessageCommand.o)
"google_public::protobuf::UnknownFieldSet::ClearFallback()", referenced from:
google_public::protobuf::UnknownFieldSet::Clear() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::DiscardUnknownFields()", referenced from:
vtable for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(google_public::protobuf::UnknownFieldSet const&)", referenced from:
message::FtypeMessage::ByteSize() const in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::WireFormat::SerializeUnknownFields(google_public::protobuf::UnknownFieldSet const&, google_public::protobuf::io::CodedOutputStream*)", referenced from:
message::FtypeMessage::SerializeWithCachedSizes(google_public::protobuf::io::CodedOutputStream*) const in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))", referenced from:
message::protobuf_AddDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::WireFormat::SkipField(google_public::protobuf::io::CodedInputStream*, unsigned int, google_public::protobuf::UnknownFieldSet*)", referenced from:
message::FtypeMessage::MergePartialFromCodedStream(google_public::protobuf::io::CodedInputStream*) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::UnknownFieldSet::MergeFrom(google_public::protobuf::UnknownFieldSet const&)", referenced from:
message::FtypeMessage::MergeFrom(message::FtypeMessage const&) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::GeneratedMessageReflection::GeneratedMessageReflection(google_public::protobuf::Descriptor const*, google_public::protobuf::Message const*, int const*, int, int, int, google_public::protobuf::DescriptorPool const*, google_public::protobuf::MessageFactory*, int)", referenced from:
message::protobuf_AssignDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::~Message()", referenced from:
message::FtypeMessage::FtypeMessage() in Test-Remote-iOS-Aggregate(ftype.pb.o)
message::FtypeMessage::~FtypeMessage() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::UnknownFieldSet::UnknownFieldSet()", referenced from:
message::FtypeMessage::FtypeMessage() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::CheckTypeAndMergeFrom(google_public::protobuf::MessageLite const&)", referenced from:
vtable for message::FtypeMessage in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::DescriptorPool::generated_pool()", referenced from:
message::protobuf_AssignDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int)", referenced from:
message::protobuf_AddDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::Message::SerializeToOstream(std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const", referenced from:
message::TestMessaging::ftypeMessage(void const*, unsigned long) in Test-Remote-iOS-Aggregate(TestMessaging.o)
"google_public::protobuf::MessageFactory::InternalRegisterGeneratedMessage(google_public::protobuf::Descriptor const*, google_public::protobuf::Message const*)", referenced from:
message::(anonymous namespace)::protobuf_RegisterTypes(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(google_public::protobuf::UnknownFieldSet const&, unsigned char*)", referenced from:
message::FtypeMessage::SerializeWithCachedSizesToArray(unsigned char*) const in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::DescriptorPool::FindFileByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
message::protobuf_AssignDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::MessageFactory::generated_factory()", referenced from:
message::protobuf_AssignDesc_ftype_2eproto() in Test-Remote-iOS-Aggregate(ftype.pb.o)
"google_public::protobuf::UnknownFieldSet::~UnknownFieldSet()", referenced from:
message::FtypeMessage::FtypeMessage() in Test-Remote-iOS-Aggregate(ftype.pb.o)
message::FtypeMessage::~FtypeMessage() in Test-Remote-iOS-Aggregate(ftype.pb.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas on what could be the likely issue here?
Thank you.
It looks like the linker is not running on your .framework, and that the .proto files were built for a full libprotobuf instead of libprotobuf-lite.
Try adding a fat libprotobuf.a to your app's framework folder and see if it finds the symbols.
As a side note, you also have another error in there you didn't mention:
"_OBJC_CLASS_$_CVImageConverter", referenced from:
objc-class-ref in Test-Remote-iOS-Aggregate(IDMessageCommand.o)
Not sure how to fix that one without seeing your code.
Not sure what issue I am having here.
Mac clang 3.1 cmake
gtest
few files
using few C++11 features
I have downloaded and installed XCode build tools
CMAKE_CXX_FLAGS = -Wall -std=c++0x -stdlib=libc++ -v
builds fine with output...
[100%] Building CXX object CMakeFiles/soupbintcptest.dir/soupmessages_tests.cpp.o
clang version 3.1 (tags/RELEASE_31/final)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
Linking dumps a slew of errors. ABI errors? I know there is this C++11 namespace mangling thing happening.
Undefined symbols for architecture x86_64:
They are all things in the std:: namespace that will not link like:
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::_Setprecision)", referenced from:
testing::AssertionResult testing::internal::FloatingPointLE<float>(char const*, char const*, float, float) in libgtest.a(gtest-all.cc.o)
testing::AssertionResult testing::internal::FloatingPointLE<double>(char const*, char const*, double, double) in libgtest.a(gtest-all.cc.o)
testing::Message::Message() in libgtest.a(gtest-all.cc.o)
or
"std::cerr", referenced from:
testing::internal::GTestLog::GetStream() in libgtest.a(gtest-all.cc.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
testing::UnitTest::AddTestPartResult(testing::TestPartResult::Type, char const*, int, testing::internal::String const&, testing::internal::String const&) in libgtest.a(gtest-all.cc.o)
testing::internal::SingleFailureChecker::~SingleFailureChecker() in libgtest.a(gtest-all.cc.o)
testing::internal::StringStreamToString(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*) in libgtest.a(gtest-all.cc.o)
testing::TestInfo::TestInfo(char const*, char const*, char const*, char const*, void const*, testing::internal::TestFactoryBase*) in libgtest.a(gtest-all.cc.o)
testing::TestInfo::~TestInfo() in libgtest.a(gtest-all.cc.o)
testing::internal::ReportInvalidTestCaseType(char const*, char const*, int) in libgtest.a(gtest-all.cc.o)
testing::internal::XmlUnitTestResultPrinter::PrintXmlUnitTest(__sFILE*, testing::UnitTest const&) in libgtest.a(gtest-all.cc.o)
...
I believe I have built gtest with the same clang++ version. Not sure what else is going on here to drive these issues.
I've seen similar errors to yours when the linker is pulling in a different c++ library to the one that matches what the compiler is building for. In your case, you are only modifying the compiler flags, but the linker doesn't know your choice and is likely linking to the wrong C++ library.
If you are able to use CMake 3.2 or later, then rather than modifying the C++ compiler flags directly, I'd recommend you just tell CMake you want to use C++11 and then let it work out the appropriate compiler and linker flags for you. This can be done by adding the following before your project() call:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
This and related CMake features are discussed in detail in this article.
There is nothing C++11 about name mangling, it's been going on since the very first C++ implementations. However, do not forget that you must have built gtest for the same stdlib switch, because it can't find the Standard libraries.