Xcode is giving me the following error, I don't really know what to do, is driving my crazy.
I'm importing an OpenCV framework so maybe the problem is there or something related to the compiler.
Could anyone tell me what to do or search for?
Undefined symbols: "_CGImageDestinationCreateWithURL", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageDestinationAddImage", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageSourceCreateImageAtIndex", referenced from:
cv::ImageIODecoder::readHeader() in OpenCV(grfmt_imageio.o) "_CGImageDestinationFinalize", referenced from:
cv::ImageIOEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)in OpenCV(grfmt_imageio.o) "_CGImageSourceCreateWithURL", referenced from:
cv::ImageIODecoder::readHeader() in OpenCV(grfmt_imageio.o) ld: symbol(s) not found collect2: ld returned 1 exit status
Just for sake of future visitors (like me ;-)), I report the Gustavo self-answer:
Add
"ImageIO.framework"
to
"Linked Frameworks and Library"
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 am trying to use the odin library (https://github.com/OpenImageDenoise/oidn/) within my project, but I am unable to get it to link successfully. When I include the library and use the example code from the documentation, my IDE does not flag any errors. However upon trying to compile it with cmake I get the following errors:
Undefined symbols for architecture x86_64:
"_oidnCommitDevice", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnCommitFilter", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnExecuteFilter", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnGetDeviceError", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnNewDevice", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
_main in main.cpp.o
"_oidnNewFilter", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnReleaseDevice", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
_main in main.cpp.o
"_oidnReleaseFilter", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.cpp.o
"_oidnSetSharedFilterImage", referenced from:
data_denoise(std::__1::vector<float, std::__1::allocator<float> >&) in main.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'm not sure if I need to link the library within the cmake file, since there is nothing related to that in the documentation.
Solved! I just needed to link the dylib to cmake.
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.
The following call from the command line, clang++ vcfaltcount.cpp -o vcfac, produces the following error/warnings
>In file included from vcfaltcount.cpp:1:
./Variant.h:86:5: warning: control may reach end of non-void function [-Wreturn-type]
}
>Undefined symbols for architecture x86_64:
"split(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in ccGOdUhH.o
vcf::VariantCallFile::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
"vcf::VariantCallFile::getNextVariant(vcf::Variant&)", referenced from:
_main in ccGOdUhH.o
"vcf::VariantCallFile::parseHeader()", referenced from:
vcf::VariantCallFile::openFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
There are many other posts on "undefined symbols for such&such architecture," and I have attempted to use those suggestions to successfully compile.
I think the problem may arise from the header file, variant.h. In the API from which the source code came there was a corresponding variant.cpp file that defined the functions, which were only declared in variant.h. I moved those definitions into variant.h. Any thoughts on what I may be missing? I can provide the header if need be, but it is long. Thanks.