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
Related
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.
I recently started working on a podSpec file that integrates levelDB into my projects.
(https://github.com/iljaiwas/Podspecs/blob/master/LevelDBPodSpec/0.0.1/leveldb.podspec)
However, when I reference any C++ symbol from a .mm file in the main target, I get a linker error like this:
Undefined symbols for architecture x86_64:
"leveldb::DB::Open(leveldb::Options const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, leveldb::DB**)", referenced from:
-[IHLevelDBContext initWithPath:] in IHLevelDBContext.o
This is what the compiler invocation looks like
/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/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -F/Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -filelist /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Intermediates/LevelDBTest2.build/Debug/LevelDBTest2.build/Objects-normal/x86_64/LevelDBTest2.LinkFileList -mmacosx-version-min=10.7 -ObjC -fobjc-arc -fobjc-link-runtime -stdlib=libc++ -framework Cocoa -lPods -o /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug/LevelDBTest2.app/Contents/MacOS/LevelDBTest2
From my understanding, the missing ::Open call is included in libPods.a
nm libPods.a | grep "Open"
U __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
000000000005e5b1 s L___func__._ZN7leveldb6DBImpl24OpenCompactionOutputFileEPNS0_15CompactionStateE
00000000000099d0 T __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
0000000000060ba0 S __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_.eh
It seems I can get around the linker errors by changing the "Compiler" setting for the main app from Apple LLVM 4.2 to LLVM GCC 4.2, but this compiler chokes on Objective-C 2.0 features, like this:
expected a property attribute before 'strong'
Thanks for any pointers on what I might be doing wrong,
Ilja
You can also set the C++ config settings in the podspec file:
s.library = 'c++'
s.xcconfig = {
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
'CLANG_CXX_LIBRARY' => 'libc++'
}
Those settings selects to compile for C++ 2011 and adds the libc++ standard library.
The problem went away after I set the "C++ Standard Library" setting in both the application target and CocoaPods target to "compiler default". Seems they were set to incompatible values by default, which caused linker confusion afterwards.
I am trying to build LLVM and link it against libc++, but I can't get it to work. I downloaded the latest version (LLVM 3.2).
$ CXXFLAGS=-stdlib=libc++ LDFLAGS=-stdlib=libc++ ../llvm-3.2.src/configure
$ make
llvm[0]: Constructing LLVMBuild project information.
llvm[1]: Compiling APFloat.cpp for Release+Asserts build
llvm[1]: Compiling APInt.cpp for Release+Asserts build
(etcetera)
llvm[1]: Building Release+Asserts Archive Library libLLVMTableGen.a
llvm[2]: Compiling FileCheck.cpp for Release+Asserts build
llvm[2]: Linking Release+Asserts executable FileCheck (without symbols)
Undefined symbols for architecture x86_64:
"std::string::find_last_not_of(char, unsigned long) const", referenced from:
llvm::SMDiagnostic::print(char const*, llvm::raw_ostream&, bool) const in libLLVMSupport.a(SourceMgr.o)
"std::string::copy(char*, unsigned long, unsigned long) const", referenced from:
llvm::sys::Path::makeUnique(bool, std::string*) in libLLVMSupport.a(Path.o)
"std::string::find(char const*, unsigned long, unsigned long) const", referenced from:
llvm::sys::getDefaultTargetTriple() in libLLVMSupport.a(Host.o)
"std::string::find(char, unsigned long) const", referenced from:
llvm::sys::Program::FindProgramByName(std::string const&) in libLLVMSupport.a(Program.o)
(followed by a bunch of other related linker errors)
Complete output on Gist.
LLVM compiles and links fine with libstdc++, but not with libc++. I have no idea why it won't link with libc++; other programs just link fine. I am running OS X Mountain Lion and libc++ is in /usr/lib/libc++.1.dylib. The compiler used is Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn).
Trust me, I'm not expert in this area. But try this:
../llvm/configure --enable-libcpp
And in general I've found:
../llvm/configure --help
quite helpful.
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
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.