Xcode 6 - compile and use gtest 1.7 - xcode

About a week ago I moved from Windows and Visual Studio to Mac and Xcode. I want to be able to work on my project on Mac, so I decided to port it.
First of all I need test to work on Mac and Google provides instructions about how to do so. After I build test with my Xcode, I can see three files in the output directory: test.framework, libgtest_main.a and libgtest.a.
Documentation says I need to link test.framework with my project. So, I create new console app project and link it with test.framework file.
Unfortunately my build fails with about 70+ issues. After I link librettist.a to my project, it fails with only 2 issues. Here they are:
Undefined symbols for architecture x86_64:
"testing::internal::EqFailure(char const*, char const*,
std::__1::basic_string,
std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&,
bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ(char const*, char const*, int const&, int const&) 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)
As I understood, linker cannot resolve symbols. If I link my project with libgtest_main.a it changes nothing and this error is still here. So, how can I fix it?

I had the same problem and was unable to figure out why this isn't being created. It does work fine on some 32 bit code, so I'm equally puzzled.
That said, the sample in the gtest package has the following comment:
EXPECT_EQ(expected, actual) is the same as EXPECT_TRUE((expected) ==
(actual)) except that it will print both the expected value and the
actual value when the assertion fails. This is very helpful for
debugging. Therefore in this case EXPECT_EQ is preferred.
and the same is true for ASSERT_EQ and ASSERT_TRUE. So if you make the substitution, you lose some information in the case of failure, but at least you can use it.

Related

LD: (null): Assertion failed: ("dylib not assigned ordinal"), function compressedOrdinalForAtom, file OutputFile.cpp,

After some editing my Xcode 5.1.0 source files I suddenly get this linker error:
0 0x1059b5f93 __assert_rtn + 144
1 0x105a1d7f5 ld::tool::OutputFile::compressedOrdinalForAtom(ld::Atom const*) + 281
2 0x105a1e469 ld::tool::OutputFile::addDyldInfo(ld::Internal&, ld::Internal::FinalSection*, ld::Atom const*, ld::Fixup*, ld::Fixup*, ld::Fixup*, ld::Atom const*, ld::Atom const*, unsigned long long, unsigned long long) + 2261
3 0x105a14496 ld::tool::OutputFile::generateLinkEditInfo(ld::Internal&) + 1322
4 0x105a0f952 ld::tool::OutputFile::write(ld::Internal&) + 116
5 0x1059b6c40 main + 1012
A linker snapshot was created at:
/tmp/keytech PLM-2014-03-05-101905.ld-snapshot
ld: Assertion failed: (0 && "dylib not assigned ordinal"), function compressedOrdinalForAtom, file /SourceCache/ld64/ld64-236.3/src/ld/OutputFile.cpp, line 3454.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have absolute no idea what this means?
I already tried to:
Delete the derived data folder
Clean Files and build files
Cosed and reopen Xcode
Made sure no Linker Optimizer are active: No dead Code Stripping, No Link Time Optimization.
I also have excluded some of my latest changed code. With no result.
Googleing the error did not find any useful information.
Does anybody have an idea?
In my case the linker error was gone after I switched in the Build Settings "OSX Deployment Target" from "10.7" to "10.8".
This looks like an open bug at llvm, which has been passed to Apple (and is therefore in a black hole).
No other information appears to be available so you need to step back in your development (via git) to figure out what triggered it, and then contribute any information you glean to llvm (via the bug reporter).
Not an answer, but I don't believe there is an answer to this issue...
I had this bug for a while.
The way I eventually fixed it was by trying to compile in Xcode 4.6
Once I tweaked my project to compile there, I got the much more helpful error:
Undefined symbols for architecture x86_64:
"_Gestalt", referenced from:
_GetOS in main.o
that led me to adding the coreservices framework (which was required by a third party framework I was adding), and from there, my project compiled just fine on xcode 5 & 6
so - that may not be the framework you need, but the approach may help you.
I ran into this too, but only for release builds. By process of elimination, I was able to get the release builds working by setting the Link-Time Optimization build setting to NO (LLVM_LTO = NO) under Apple LLVM – Code Generation.

Google Test and XCode 4.6

Problem with google test in XCode 4.6.3
Hello all,
I have integrated google tests into my XCode project, and basic command line tool for
unit testing seems to work fine (guest.framework added, DYLD_LIBRRY_PATH set correctly).
However, as soon as I add to object fixture EXPECT_EQ(0, Object.PublicMember) type
test, I get following linker error.
Ld /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug/UnitTest normal x86_64
cd /Users/rinkevic/Development/VeloxChemX
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug -F/Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug -F/Users/rinkevic/Development/Frameworks -F/Users/rinkevic/Development/VeloxChemX/../../Library/Frameworks -F/Users/rinkevic/Development/VeloxChemX/../Frameworks -filelist /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Intermediates/VeloxChemX.build/Debug/UnitTest.build/Objects-normal/x86_64/UnitTest.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ -framework gtest -framework OpenCL -o /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug/UnitTest
Undefined symbols for architecture x86_64:
"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::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in TestCartMom.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 suggestion what I am doing wrong?
I had the same problem.
Choose libstdc++ in both projects.
It's because the build options of your unit test project is different with the gtest project.
Make sure the build options such as "Apple LLVM - Language" & "Apple LLVM - Language - C++" are all the same.
Another solution is outlined here: http://dennycd.me/google-test-xcode-mac-osx/ which brings some sanity to the situation by not using a framework but instead installing into /usr/local.
Remember that the libs must be renamed to start with 'lib', for example libgtest.a.
Also remember that you must link to both libgtest.a and libgtest_main.a. Without the latter, you will get a complaint about missing the main method.
The same comments regarding the c++ dialect and the library are applicable, but I found it very hard to control these while producing the framework and trying to link to that.
By default General.xcconfig points to 10.4 SDK, changing it to 10.10 fixed issue for me

OSX linking program: undefined symbols for x86_64

I have a program that runs correctly when using .png files.
I'm trying to convert it to support OpenEXR.
The program is compiled with macports g++-mp-4.5, and links against macports's openexr1.7.
Relevant parts of the compile line:
/opt/local/bin/g++-mp-4.5 ... -I/opt/local/include/OpenEXR -I/opt/local/include/OpenEXR file.cc ...
-L/opt/local/lib -lIlmImf -lHalf ...
When run, it does this when it tries to call the exr library:
libc++abi.dylib: terminate called throwing an exception
When it is changed to link with the .a files
/opt/local/lib/libIlmImf.a /opt/local/lib/libHalf.a
it gives a link error
Undefined symbols for architecture x86_64:
"Iex::throwErrnoExc(std::basic_string, std::allocator > const&)", referenced from:
Imf::(anonymous namespace)::writeLineOffsets(Imf::OStream&, std::vector > const&) in libIlmImf.a(ImfOutputFile.o)
Imf::StdIFStream::StdIFStream(char const*) in libIlmImf.a(ImfStdIO.o)
Imf::(anonymous namespace)::checkError(std::basic_istream >&, long) in libIlmImf.a(ImfStdIO.o)
After searching, it seems that this (*undefined symbols for x86_64*) is a common problem for linux-style mac development, and does not appear to be specific
to openexr. However after reading various posts, I still do not understand what the solution is!
Here is a post on the exact problem, however the solution is not explained in enough detail for me to understand:
http://lists.nongnu.org/archive/html/openexr-devel/2011-08/msg00007.html

Qt4.8 + CMake 2.8.5 on OSX 10.5.8 can't link

I'm using Qt4.8 on OSX Leopard and instead of qmake+QtCreator I want to compile a very simple project using CMake on OSX to understand how to do a package.
While the very same project compiles and links smoothly under Linux, under my OSX box, this is the error message I always get in the linking phase:
ld warning: in /Library/Frameworks//QtGui.framework/QtGui, file is not of required architecture
ld warning: in /Library/Frameworks//QtCore.framework/QtCore, file is not of required architecture
Undefined symbols:
"QWidget::mousePressEvent(QMouseEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QObject::childEvent(QChildEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QWidget::actionEvent(QActionEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QCoreApplication::translate(char const*, char const*, char const*, QCoreApplication::Encoding)", referenced from:
etcetera etcetera.
This happens for every project I want to compile with cmake.
Any idea of what's going on?
Check what architecture (i386,x86_64) is being used by cmake (CMAKE_OSX_ARCHITECTURES). Try suggesting the architecture to cmake:
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64

Trouble linking Tim Bolstad's Core Audio Example

I'm probably missing something simple, but I'm getting the following linker error when trying to build:
Undefined symbols for architecture i386:
"CAStreamBasicDescription::CAStreamBasicDescription()", referenced from:
-[AudioController initializeAUGraph] in AudioController.o
-[AudioController .cxx_construct] in AudioController.o
"CAStreamBasicDescription::AsString(char*, unsigned long) const", referenced from:
CAStreamBasicDescription::PrintFormat(__sFILE*, char const*, char const*) const in AudioController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I can't figure out what's going on here as the compiler is finding CAStreamBasicDescription.h just fine. I've seen suggestions of clearing the framework search path when encountering this type of error, but there's nothing in that path. Probably something simple, but I feel like I'm drinking from a fire hose. Thanks!
Have you added CAStreamBasicDescription.cpp to your project also? It's part of the unofficial Core Audio SDK, so it isn't available unless you compile it yourself.

Resources