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).
Related
I've been trying to get the Point Cloud Library working for a few days now. I've tried installing it several ways including cMake, MacPort and Home-brew. I've looked through many forums, blog posts and even Stack Overflow posts and I'm still stuck!
The issue is that while there's nothing wrong with the program itself, upon compile I get an Undefined Symbols for Architecture X86_64 error. See below for direct quote:
Undefined symbols for architecture x86_64:
"pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)", referenced from:
int pcl::PCDWriter::writeBinary<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&) in main.o
int pcl::PCDWriter::writeASCII<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&, int) in main.o
"pcl::PCDWriter::writeASCII(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, int)", referenced from:
pcl::PCDWriter::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, bool) in main.o
"pcl::PCDWriter::writeBinary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&)", referenced from:
pcl::PCDWriter::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, bool) in main.o
"pcl::PCDWriter::setLockingPermissions(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::interprocess::file_lock&)", referenced from:
int pcl::PCDWriter::writeBinary<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&) in main.o
int pcl::PCDWriter::writeASCII<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&, int) in main.o
"pcl::PCDWriter::resetLockingPermissions(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::interprocess::file_lock&)", referenced from:
int pcl::PCDWriter::writeBinary<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&) in main.o
int pcl::PCDWriter::writeASCII<pcl::PointXYZ>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pcl::PointCloud<pcl::PointXYZ> const&, int) 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)
It looks like all the issues spring from the same type definition: PCDWriter.
I checked the file it was in and the code looks fine to my unfamiliar eye. One post I saw suggested that the error means that the library was 32 bit trying to run on a 64 bit system. So I upgraded from PCL 1.6.0 to 1.8.1 (latest) in hopes of seeing a difference, but no change.
Another suggested that it meant PCDwriter didn't hold the right information for the various bits of code that reference it. But again, the code looks fine as far as I can tell.
I decided to try deliberately entering the path into the linker (don't ask why, desperation and unfamiliarity drive me to strange things) and while removing the 6 errors it replaced them with 1 saying "cannot specify -o when generating multiple output files".
Which I found odd, having just my Main function at this point. According to another person this was due to problems encountered when header files are in the list of files to be compiled. The solution being to simply remove the headers from the list.
So I removed them and returned to the error from before.
I also tried, though unfamiliar with how xCode would interact with it, to use the "Use PCL in your own project" instructions on the Dev website. cMake refused to make.
I'm not very experienced with importing these types of libraries, mostly I've worked with Arduino before, though the OpenCV library was beautifully simple to install and get running (thanks Devs).
Thank you for any help, I really appreciate it,
Sincerely, Noob
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'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.
I've been pulling my hair out trying to link my iOS app with an arm64 library.
The library in question is Crypto++. I've tried both the precompiled fat library that's in the wiki : http://www.cryptopp.com/wiki/IOS_(Command_Line). I've tried compiling the library myself, but I keep getting link errors of the following kind:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long, unsigned long)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libcryptopp.a(randpool.o)
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libcryptopp.a(modes.o)
The libcryptopp.a seems to be fine for armv7, but not for arm64 for some reason. If I exclude libcryptopp.a's 64 bit version from the linking process, it gives even more errors.
They both were compiled using -stdlib=libstdc++
What is going on?
(I need arm64 support because of tweak development reasons)
update sorry all - it turns out it was using the old libcryptopp.a, and not finding the libcryptopp.a properly. The .a was sourced from somewhere else, which has been fixed.
"std::__1::basic_string, std::__1::allocator >::__init(char const*, unsigned long, unsigned long)", referenced from: ... libcryptopp.a(randpool.o)
This library has been built, and depends on LLVM's C++ runtime libc++, and not GNU's C++ runtime libstdc++.
They both were compiled using -stdlib=libstdc++
You need to either rebuild libcryptopp.a against libstdc++, or link with -stdlib=libc++ (and build the rest of your code against libc++ as well).
If interested, the __1 is an inline namespace used for versioning. See What are inline namespaces for? and Where does the __1 symbol come from when using LLVM's libc++?.
I created an iOS framework with a combined, universal static C++ library from the Poco sources by using lipo and libtool. Essentially, what I do is :
compile Poco for iPhoneOS and iPhoneSimulator
for each architecture:
libtool -static -o libPoco.a libPocoFoundation.a libPocoNet.a libPocoJSON.a
lipo armv6/libPoco.a armv7/libPoco.a i386/libPoco.a -create -output universal/libPoco.a
create a framework from the generated fat library and includes
Look at besport/PocoMobile for more information.
Now, I tried using this framework in an app and everything sounded fine. But when I try to use a class from Poco, the linker spits out undefined symbols from both Poco and libstdc++ :
Undefined symbols for architecture i386:
"Poco::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Any const&)", referenced from:
Poco::Logger::warning(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Any const&) in MapStorage.o
"Poco::Message::Message(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&, Poco::Message::Priority)", referenced from:
Poco::Logger::log(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Message::Priority) in MapStorage.o
"std::string::c_str() const", referenced from:
Poco::ProcessImpl::launchByForkExecImpl(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, std::string const&, Poco::Pipe*, Poco::Pipe*, Poco::Pipe*, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&) in Poco(Process.o)
Poco::EnvironmentImpl::setImpl(std::string const&, std::string const&) in Poco(Environment.o)
Poco::EnvironmentImpl::hasImpl(std::string const&) in Poco(Environment.o)
Poco::EnvironmentImpl::getImpl(std::string const&) in Poco(Environment.o)
"std::string::empty() const", referenced from:
...
I verified with nm and libtool -info, and the library file seems to contain the right functions. The Objective-C++ files I have in the project compile fine as well if I don't do anything with Poco.
Does this have to do the libraries being C++ libraries? Any compiler flag I have to turn on?
Can libtool -static actually use .a libraries? Am I doing that right?