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.
Related
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!
I'm working on a Mac. I installed libprotobuf with brew install protobuf --c++11.
17:51 $ brew info protobuf
protobuf: stable 2.6.1 (bottled), devel 3.0.0-beta-4, HEAD
Protocol buffers (Google's data interchange format)
https://github.com/google/protobuf/
/usr/local/Cellar/protobuf/2.6.1 (149 files, 7.0M) *
Built from source on 2016-08-02 at 17:42:15 with: --c++11
libprotobuf.dylib lives in /usr/local/Cellar/protobuf/2.6.1/lib.
I wrote the following dummy app hoping to invoke this constructor:
// test.cc
#include <string>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
int main() {
std::string s{"hello"};
google::protobuf::io::StringOutputStream sos(&s);
}
When I compile the app, I get an undefined reference error:
17:55 $ g++ -L/usr/local/Cellar/protobuf/2.6.1/lib -std=c++14 test.cc -lprotobuf
Undefined symbols for architecture x86_64:
"google::protobuf::io::StringOutputStream::StringOutputStream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
_main in ccyQlDM5.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
When I check the .dylib for StringOutputStream, it's a little wonky.
17:56 $ nm /usr/local/Cellar/protobuf/2.6.1/lib/libprotobuf.dylib | c++filt | grep "StringOutputStream(std::"
000000000000e3ac T google::protobuf::io::StringOutputStream::StringOutputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
000000000000e398 T google::protobuf::io::StringOutputStream::StringOutputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
Why is basic_string namespace-prefixed by ::__1 in my list of symbols for that .dylib? How can I fix this?
If this isn't a problem (perhaps an artifact of unmangling), why am I still receiving an undefined reference to a constructor call I know to be defined?
I'm using gcc 5.3.0 to compile test.cc.
As referenced in the comments, Homebrew was building with clang instead of g++.
I removed the protobuf installed by brew, checked out and built the source, copied the new .dylib to /usr/local/lib and it worked fine.
I'm trying to use the gcc command to compile and run a .cpp file to test google protobuf.
CPP_TEST.cpp
#include "GameInfo.pb.h"
int main() {
// ...
}
GameInfo.pb.h generated by protoc
#ifndef PROTOBUF_GameInfo_2eproto__INCLUDED
#define PROTOBUF_GameInfo_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
// ...
and my files in folder looks like this
- test
CPP_TEST.cpp
GameInfo.pb.h
GameInfo.pb.cc
// the lib file for protobuf
libprotobuf.a
// the srouce code of protobuf
- google
- protobuf
// ...
- stubs
common.h
// ...
and then I tried to compile the .cpp file
gcc CPP_TEST.cpp -l ./google -o OUT_CPP_TEST
But get the error:
#include <google/protobuf/stubs/common.h>
'google/protobuf/stubs/common.h' file not found with <angled> include; use "quotes" instead
I think it is an error with the gcc compiler flag but can not figure out why...
Any advice will be appreciated, thanks :)
UPDATE:
After changing the command to
gcc CPP_TEST.cpp -I./ -o OUT_CPP_TEST
The file is ok to compiler and run.
But if I add a code to the main function :
game::info::GameInfo gameInfoOut;
And compiler it will fail with:
Undefined symbols for architecture x86_64:
"game::info::GameInfo::GameInfo()", referenced from:
_main in CPP_TEST-9245ef.o
"game::info::GameInfo::~GameInfo()", referenced from:
_main in CPP_TEST-9245ef.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So I tried to add the libprotobuf.a file to gcc command
gcc CPP_TEST.cpp -L./ -lprotobuf -I./ -o CPP_TEST_OUT
But I am still getting the same error:
Undefined symbols for architecture x86_64:
"game::info::GameInfo::GameInfo()", referenced from:
_main in CPP_TEST-0e3576.o
"game::info::GameInfo::~GameInfo()", referenced from:
_main in CPP_TEST-0e3576.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
UPDATE:
I tried to complier and link all the files step by step like:
gcc -c -I./ GameInfo.pb.cc
gcc -c -I./ GameEnum.pb.cc
gcc -c -I./ CPP_TEST.cpp
and link
gcc CPP_TEST.o GameInfo.pb.o GameEnum.pb.o -L./ -lprotobuf -o main
And now I am getting bunch of errors like:
Undefined symbols for architecture x86_64:
"___dynamic_cast", referenced from:
game::info::RoleInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::RoleInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
game::info::ItemInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::ItemInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
game::info::GameInfo const* google::protobuf::internal::dynamic_cast_if_available<game::info::GameInfo const*, google::protobuf::Message const*>(google::protobuf::Message const*) in GameInfo.pb.o
google::protobuf::FileDescriptorSet const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::FileDescriptorSet const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::FileDescriptorProto const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::FileDescriptorProto const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::DescriptorProto_ExtensionRange const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::DescriptorProto_ExtensionRange const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
google::protobuf::DescriptorProto const* google::protobuf::internal::dynamic_cast_if_available<google::protobuf::DescriptorProto const*, google::protobuf::Message const*>(google::protobuf::Message const*) in libprotobuf.a(descriptor.pb.o)
...
"___gxx_personality_v0", referenced from:
game::enumeration::protobuf_AssignDesc_GameEnum_2eproto() in GameEnum.pb.o
google::protobuf::GoogleOnceInit(long*, void (*)()) in GameEnum.pb.o
Dwarf Exception Unwind Info (__eh_frame) in GameEnum.pb.o
game::info::protobuf_AssignDesc_GameInfo_2eproto() in GameInfo.pb.o
game::info::protobuf_AddDesc_GameInfo_2eproto() in GameInfo.pb.o
game::info::RoleInfo::RoleInfo() in GameInfo.pb.o
game::info::RoleInfo::RoleInfo(game::info::RoleInfo const&) in GameInfo.pb.o
// more here
It is really weird since the I can complier and run it successfully in the xcode with all the GameInfo.pb.h/cc GameEnum.pb.h/cc, libprotobuf.a and "google source".
gcc doesn't know the include directory of google headers until you mention the path using -I flag not -l. As google directory is in the current working directory so no need to pass ./google for -I.
g++ -I./ CPP_TEST.cpp -o OUT_CPP_TEST
or else you can just use what your error suggestion said (use quotes instead of angles) because your file hierarchy matches this suggestion.
#include "google/protobuf/stubs/common.h"
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.
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.