osx - Linking error, when building POCO library - c++

I'm trying to build poco library on osx 10.9 with clang++.
I'm running make CXXFLAGS+=-stdlib=libstdc++ CFLAGS+=-stdlib=libstdc++ LDFLAGS+=-stdlib=libstdc++.
It've successfully compiled all .o files:
** Compiling src/UUIDGenerator.cpp (release, shared) clang++ -Iinclude -I/Users/croco/Work/poco-1.6.0-all/CppUnit/include -I/Users/croco/Work/poco-1.6.0-all/CppUnit/WinTestRunner/include -I/Users/croco/Work/poco-1.6.0-all/Foundation/include -I/Users/croco/Work/poco-1.6.0-all/XML/include -I/Users/croco/Work/poco-1.6.0-all/JSON/include -I/Users/croco/Work/poco-1.6.0-all/Util/include -I/Users/croco/Work/poco-1.6.0-all/Net/include -I/Users/croco/Work/poco-1.6.0-all/Crypto/include -I/Users/croco/Work/poco-1.6.0-all/NetSSL_OpenSSL/include -I/Users/croco/Work/poco-1.6.0-all/Data/include -I/Users/croco/Work/poco-1.6.0-all/Data/SQLite/include -I/Users/croco/Work/poco-1.6.0-all/Data/ODBC/include -I/Users/croco/Work/poco-1.6.0-all/Data/MySQL/include -I/Users/croco/Work/poco-1.6.0-all/MongoDB/include -I/Users/croco/Work/poco-1.6.0-all/Zip/include -I/Users/croco/Work/poco-1.6.0-all/PageCompiler/include -I/Users/croco/Work/poco-1.6.0-all/PageCompiler/File2Page/include -stdlib=libstdc++ -DNDEBUG -O2 -fasm-blocks -fPIC -c src/UUIDGenerator.cpp -o
/Users/croco/Work/poco-1.6.0-all/Foundation/obj/Darwin/x86_64/release_shared/UUIDGenerator.o
But when linking, -stdlib flag doesn't used and i receive some errors like this:
Undefined symbols for architecture x86_64:
"std::basic_string,
std::allocator >::data() const", referenced from:
Poco::UnicodeConverter::convert(std::basic_string, std::allocator > const&,
std::string&) in UnicodeConverter.o "std::basic_string, std::allocator >::length() const",
referenced from:
Poco::UnicodeConverter::convert(std::basic_string, std::allocator > const&,
std::string&) in UnicodeConverter.o
What i'm doing wrong?

Well, my solution is to put -stdlib flag to build/config/Darwin-clang and configure build with required Darwin-clang config.

Related

Building with theos on OS X with libc++: undefined symbols for std::allocator and std::basic_string

This is a problem I've been having for over a year that I continue to return to every so often, and it's the main reason I have always been scared away from using theos(for building iOS tweaks). Today I have decided to try again, and I have made a test theos project once more and attempted to build it with 'make'. This is the sample code I'm attempting to build:
#include <string>
#include <cstdio>
struct Mine
{
std::string nice;
Mine(std::string p)
{
nice = p;
}
virtual void poop()
{
printf("%s", this->nice.c_str());
}
};
int main()
{
Mine* mine = new Mine("nice");
mine->poop();
return 0;
}
This is the basic Makefile I'm using to build this in theos:
GO_EASY_ON_ME=1
messages=yes
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tweak_test
tweak_test_CXXFLAGS = -stdlib=libc++ -std=c++11
tweak_test_LDFLAGS = -stdlib=libc++ -std=c++11
tweak_test_FILES = main.cpp
include $(THEOS_MAKE_PATH)/tweak.mk
Notice that I am in fact specifying that I would like to use the libc++ STL when building (I must use libc++ for the tweak I am building since the app that I am hooking uses it, and there would be runtime conflicts if they were different, namely due to libc++'s short string optimization feature, which makes its strings use up 24 bytes rather than 8 on libstdc++, among other things).
No matter what I do, however, I always get linker errors with std::string related functions. This is the output from theos, with verbose turned on so that execution is printed:
Ryans-MacBook-Air:tweak_test ryan$ make
> Making all for tweak tweak_test…
set -o pipefail; (/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going \
internal-library-compile \
_THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=tweak_test _THEOS_CURRENT_OPERATION=compile \
THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes)
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 2 "Compiling main.cpp (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -x c++ -c -I/opt/theos/include -include /opt/theos/Prefix.pch -DTARGET_IPHONE=1 -O0 -Wall -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -fmodules -fcxx-modules -fmodule-name=tweak_test -fbuild-session-file=/Users/ryan/tweaks/tweak_test/.theos/build_session -fmodules-prune-after=345600 -fmodules-prune-interval=86400 -fmodules-validate-once-per-build-session -I/opt/theos/vendor/include -I/opt/theos/include/_fallback -DDEBUG -ggdb -O0 -DTHEOS_INSTANCE_NAME="\"tweak_test\"" -arch armv7 main.cpp -o /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o)
==> Compiling main.cpp (armv7)…
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 3 "Linking tweak tweak_test (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -L/opt/theos/lib -L/opt/theos/vendor/lib -F/opt/theos/vendor/lib -framework CydiaSubstrate -dynamiclib -install_name "/Library/MobileSubstrate/DynamicLibraries/tweak_test.dylib" -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -Wl,-segalign,4000 -multiply_defined suppress -arch armv7 -stdlib=libc++ -std=c++11 -ggdb -O0 -o "/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib" /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o | (grep -v 'usr/lib/dylib1.o, missing required architecture' || true))
==> Linking tweak tweak_test (armv7)…
Undefined symbols for architecture armv7:
"std::string::c_str() const", referenced from:
Mine::poop() in main.cpp.262db704.o
"std::allocator<char>::allocator()", referenced from:
_main in main.cpp.262db704.o
"std::allocator<char>::~allocator()", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in main.cpp.262db704.o
Mine::Mine(std::string) in main.cpp.262db704.o
"std::string::operator=(std::string const&)", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 1
make[2]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [tweak_test.all.tweak.variables] Error 2
Note that when building with libstdc++ this builds correctly. I believe that the problem is with either being linked with clang rather than clang++ (doesn't appear to be), or that it is being linked with a different STL than what it had been compiled with (also does not appear to be the case, based on the above verbose output).
If someone could help me with this it would be a year-and-a-half old problem finally put to rest.
Thanks in advance!

Link error with boost-python installed by macports on Mavericks

I upgraded to maverics and now the macports version of boost-python doesn't work.
I installed ports: gcc48 and boost +python33.
I tried to compile this program with c++11 or without c++11:
#include <boost/python.hpp>
class A {};
BOOST_PYTHON_MODULE(libblah) {
boost::python::class_<A>("A");
}
I used cmake, but the build commands generated are below along with the linker error that I get:
[100%] Building CXX object CMakeFiles/a.dir/a.cc.o
g++ -Da_EXPORTS -std=gnu++0x -save-temps=obj -arch x86_64 -fPIC -I/Users/neil/nn/src -I/opt/local/include -I/opt/local/include/freetype2 -I/opt/local/Library/Frameworks/Python.framework/Headers -F/usr/local/Qt-5.2.0/lib -I/usr/local/Qt-5.2.0/lib/QtCore.framework/Headers -I/usr/local/Qt-5.2.0/mkspecs/macx-clang -I/usr/local/Qt-5.2.0/lib/QtGui.framework/Headers -I/System/Library/Frameworks/OpenGL.framework/Headers -I/usr/local/Qt-5.2.0/lib/QtOpenGL.framework/Headers -I/usr/local/Qt-5.2.0/lib/QtWidgets.framework/Headers -I/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I/Users/neil/nn/src/. -o CMakeFiles/a.dir/a.cc.o -c /Users/neil/nn/src/a.cc
Linking CXX shared module liba.so
g++ -std=gnu++0x -save-temps=obj -arch x86_64 -bundle -Wl,-headerpad_max_install_names -o liba.so CMakeFiles/a.dir/a.cc.o -L/opt/local/lib -L/Users/neil/nn/src /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/libpython3.3.dylib /opt/local/lib/libboost_python-mt.dylib -Wl,-rpath,/opt/local/lib -Wl,-rpath,/Users/neil/nn/src
Undefined symbols for architecture x86_64:
"boost::python::objects::function_object(boost::python::objects::py_function const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)", referenced from:
boost::python::api::object boost::python::detail::make_function_aux<void (*)(_object*), boost::python::default_call_policies, boost::mpl::vector2<void, _object*>, mpl_::int_<0> >(void (*)(_object*), boost::python::default_call_policies const&, boost::mpl::vector2<void, _object*> const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>) in a.cc.o
"boost::python::objects::register_dynamic_id_aux(boost::python::type_info, std::pair<void*, boost::python::type_info> (*)(void*))", referenced from:
void boost::python::objects::register_dynamic_id<A>(A*) in a.cc.o
ld: symbol(s) not found for architecture x86_64
How can I work around this bug without installing boost by myself. As with this Related question, the symbols in the library
nm libboost_python-mt.dylib | c++filt | grep boost::python::objects::function_object
are found:
0000000000013d60 T boost::python::objects::function_object(boost::python::objects::py_function const&)
0000000000013d00 T boost::python::objects::function_object(boost::python::objects::py_function const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)
However, they have std::__1 prefixes, which do not match what is expected in the undefined symbols errors.
I changed the compiler to clang++, and that worked. Would have preferred a better solution.

g++ ld: symbol(s) not found for architecture x86_64

I'm trying to compile the Sam Hare's Struck code.
I'm using mac OSX10.9, opencv 2.4.6 and Eigen 2.0.17.
Eigen and opencv headers are stored in /opt/local/include while opencv dylib in /opt/local/lib.
I modified the Hare's Makefile to work on this folder. When I type make on the terminal:
g++ -L/opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc src/Config.o src/Features.o src/HaarFeature.o src/HaarFeatures.o src/HistogramFeatures.o src/ImageRep.o src/LaRank.o src/MultiFeatures.o src/RawFeatures.o src/Sampler.o src/Tracker.o src/main.o src/GraphUtils/GraphUtils.o -o struck
I get these errors:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)",
referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o "cv::imread(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&,
cv::_InputArray const&)", referenced from:
LaRank::Debug() in LaRank.o
Tracker::Debug() in Tracker.o
_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)
Any ideas? Thanks!
I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command:
gcc -o exec main.o add.o
But my program is a C++ program. Using the g++ compiler solved my issue:
g++ -o exec main.o add.o
I was always under the impression that gcc could figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.
finally solved my problem.
I created a new project in XCode with the sources and changed the C++ Standard Library from the default libc++ to libstdc++ as in this and this.
I am getting the same error. I don't think it is a "fix", but my work-around is to also include the cpp file. So instead of just putting
#include "MyClass.h"
I have to put
#include "MyClass.h"
#include "MyClass.cpp"
I wrote my declarition in the .h file
class String
{
String (const char * cstr = 0);
};
and I used inline in another .cpp file (implementation)
inline String::String(const char * cstr)
{
//code ...
}
then I use g++ and get this:
Undefined symbols for architecture x86_64:
"String::String(char const*)", referenced from:
_main in test-d389f3.o
ld: symbol(s) not found for architecture x86_64
solution: do not write inline when declarition and implementation is independent.
When I using clang to compile a C++ program, I have the similar error.
But after I changing to use chang++, the compilation worked.

Linking C++ library (libtorrent) from Objective-C

I'm trying to use libtorrent library from Xcode 5.0 Objective-C Project without success.
I've built boost 1.54 and libtorrent-rasterbar (latest) from sources using LLVM 5.0, no problems with that. Also, via MacPorts I obtained pkg-config to get the proper cflags for libtorrent-rasterbar library. From my build settings, the output for pkgconfig libs and cflags were:
-DTORRENT_USE_OPENSSL -DWITH_SHIPPED_GEOIP_H
-DBOOST_ASIO_HASH_MAP_BUCKETS=1021
-DBOOST_EXCEPTION_DISABLE -DBOOST_ASIO_ENABLE_CANCELIO
-DBOOST_ASIO_DYN_LINK -DTORRENT_LINKING_SHARED -I/usr/local/include
-I/usr/local/include/libtorrent
-L/usr/local/lib -ltorrent-rasterbar
Naturally, I added those parameters to Xcode "Linker Flags" and "C/C++ Flags" settings.
Unfortunately, I cannot get my called functions to link right. This is a sample class I wrote in a testclass.cpp file:
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/create_torrent.hpp"
void testclass::addFilesFromPath(const char* path)
{
libtorrent::file_storage fs;
libtorrent::add_files(fs, path);
}
Tried to get called from a createpackage.mm file:
testclass* pPackage = new testclass();
testclass->addFilesFromPath([_sessionDir UTF8String]);
The linker cannot found the symbols, output is:
Undefined symbols for architecture x86_64:
"libtorrent::parent_path(std::__1::basic_string, std::__1::allocator > const&)",
referenced from:
libtorrent::add_files(libtorrent::file_storage&, std::__1::basic_string,
std::__1::allocator > const&, unsigned int) in
createpackage.o
"libtorrent::detail::add_files_impl(libtorrent::file_storage&,
std::__1::basic_string,
std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&,
boost::function, std::__1::allocator >)>, unsigned
int)", referenced from:
libtorrent::add_files(libtorrent::file_storage&, std::__1::basic_string,
std::__1::allocator > const&, unsigned int) in
createpackage.o
"libtorrent::complete(std::__1::basic_string, std::__1::allocator > const&)",
referenced from:
libtorrent::add_files(libtorrent::file_storage&, std::__1::basic_string,
std::__1::allocator > const&, unsigned int) in
createpackage.o
"libtorrent::filename(std::__1::basic_string, std::__1::allocator > const&)",
referenced from:
libtorrent::add_files(libtorrent::file_storage&, std::__1::basic_string,
std::__1::allocator > const&, unsigned int) in
createpackage.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 pretty puzzled. Checked that libtorrent-raster bar architecture is x86_64. Also, boost is built OK. I'm new to this C++ / Objetive-C code mixing approach.
Thanks.
EDIT 1:
I've resorted to a minimal sample. Made the following CPP file:
#include "libtorrent/file.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/create_torrent.hpp"
int main()
{
libtorrent::file_storage fs;
libtorrent::add_files(fs, ".");
}
At command line, tried:
c++ test.cpp $(pkg-config /usr/local/lib/pkgconfig/libtorrent-rasterbar.pc --cflags --libs) -lboost_system
Build is successful. So I wonder how to put all that pkg-config data into the proper target configurations in OSX.
Finally, problem was solved.
Let's check symbols comparing the produced object file and the symbols contained in libtorrent library.
nm createpackage.o|grep 'add_files'
U __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_N5boost8functionIFbS9_EEEj
00000000000002a0 S __ZN10libtorrent9add_filesERNS_12file_storageERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEj
00000000000018e0 S __ZN10libtorrent9add_filesERNS_12file_storageERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEj.eh
Compare with:
$ nm libtorrent-rasterbar.a | grep 'add_files'
00000000000002f0 T __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKSsS4_N5boost8functionIFbSsEEEj
0000000000006e68 S __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKSsS4_N5boost8functionIFbSsEEEj.eh
The difference as many could imagine seeing that output, it's that i'm using the LLVM Standard C++ library for my .mm files while libtorrent was compiled with GCC Stdlib, that's the reason of different symbols referring to char_traits, basic_string, etc.
So, changing in XCode Build Settings > Standard C++ Library to libstdc++ fixed the problem.

linking error when building Google test on mac (commandline)

I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating
ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
I have tried to make the issue as simple as possible:
I have a main function
cmtest.cc
#include <gtest/gtest.h>
/** Main entry point */
int main(int argc, char**argv, char**envArg)
{
testing::InitGoogleTest(&argc, argv);
return(RUN_ALL_TESTS());
}
really basic test code
CrazyTest.cc
#include <gtest/gtest.h>
TEST(CrazyTest, one) {
EXPECT_EQ(2, 2);
}
I use the following commands to build gtest and my test code.
g++ -o CrazyTest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0/include CrazyTest.cc
g++ -o cmtest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0/include cmtest.cc
g++ -o gtest-all.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0 -I/opt/gtest-1.6.0/include /opt/gtest-1.6.0/src/gtest-all.cc
ar rc libgtest.a gtest-all.o
ranlib libgtest.a
g++ -o cmtest -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 CrazyTest.o cmtest.o -lstdc++ -lgtest
The final build step gives me the following error and I am unable to figure out why. I am able to get the actual tests (not the simple one shown) to build on other OSs the mac OS (leopard) is giving me problems.
ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
"testing::Test::~Test()", referenced from:
CrazyTest_one_Test::~CrazyTest_one_Test()in CrazyTest.o
CrazyTest_one_Test::~CrazyTest_one_Test()in CrazyTest.o
"testing::internal::AssertHelper::~AssertHelper()", referenced from:
CrazyTest_one_Test::TestBody() in CrazyTest.o
"testing::Test::Test()", referenced from:
CrazyTest_one_Test::CrazyTest_one_Test()in CrazyTest.o
"testing::internal::GetTestTypeId()", referenced from:
__static_initialization_and_destruction_0(int, int)in CrazyTest.o
"testing::Test::TearDown()", referenced from:
vtable for CrazyTest_one_Testin CrazyTest.o
"testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)in CrazyTest.o
"testing::UnitTest::GetInstance()", referenced from:
_main in cmtest.o
"testing::internal::IsTrue(bool)", referenced from:
testing::internal::scoped_ptr<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >::reset(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)in CrazyTest.o
testing::internal::scoped_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::reset(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)in CrazyTest.o
"testing::UnitTest::Run()", referenced from:
_main in cmtest.o
"testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
CrazyTest_one_Test::TestBody() in CrazyTest.o
"testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
CrazyTest_one_Test::TestBody() in CrazyTest.o
"testing::AssertionSuccess()", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)in CrazyTest.o
"testing::Test::SetUp()", referenced from:
vtable for CrazyTest_one_Testin CrazyTest.o
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
__static_initialization_and_destruction_0(int, int)in CrazyTest.o
"testing::InitGoogleTest(int*, char**)", referenced from:
_main in cmtest.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccZQiF8k.out (No such file or directory)
I have defined -arch i386 and -arch x86_64 for everything I have built so I am unable to figure out what I have missed. I don't do a lot of programming on Macs and this particular issue has me stuck.
Any suggestions would be helpful.
Solution found. It turns out that the build instructions used are correct the issue was that on the computer that the build was being performed another developer had done some work with Google Test Framework 1.5 and they had installed the libraries on the computer in the compilers search path. This resulted in the compiler finding the other library first that was not compiled using multiple architecture options.
Compile gtest and your project with the same compiler (-flags).
If you compiled gtest with Apple g++ and meanwhile installed gcc with e.g. homebrew, linking to gtest will cause this error. This is exactly the reason why Google advices to integrate gtest statically linked in your project, and not to use precompiled binaries.
You might also have this problem if gmock and gtest are out of sync. I had similar build errors with gmock-1.6.0 and gtest-1.7.0:
../../../third_party/gmock/build/libgmock.a(gmock-all.cc.o): In function `testing::internal::ParseGoogleMockFlagValue(char const*, char const*, bool)':
gmock-all.cc:(.text+0x3b5c): undefined reference to `testing::internal::String::Format(char const*, ...)'
../../../third_party/gmock/build/libgmock.a(gmock-all.cc.o): In function `testing::internal::String::operator==(char const*) const':
gmock-all.cc:(.text._ZNK7testing8internal6StringeqEPKc[testing::internal::String::operator==(char const*) const]+0x33): undefined reference to `testing::internal::String::Compare(testing::internal::String const&) const'
collect2: ld returned 1 exit status
Switching to both 1.7.0 or both 1.6.0 fixed the problem.