我正在使用Objective C++編寫框架,並且在設置單元測試時遇到了問題。用Xcode 4.x進行單元測試Objective-C++框架
僅編譯框架目標就可以正常工作。
但是,當我告訴Xcode的編譯和運行測試包,我得到:
Ld ~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug/TestFrameworkTests.octest/Contents/MacOS/TestFrameworkTests normal x86_64
cd "~/Projects/TestFramework"
setenv MACOSX_DEPLOYMENT_TARGET 10.7
"/Applications/Xcode 4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" -arch x86_64 -bundle -isysroot "/Applications/Xcode 4.5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" -L~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug "-F/Applications/Xcode 4.5.app/Contents/Developer/Library/Frameworks" -filelist ~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Intermediates/TestFramework.build/Debug/TestFrameworkTests.build/Objects-normal/x86_64/TestFrameworkTests.LinkFileList -mmacosx-version-min=10.7 -v -fobjc-arc -fobjc-link-runtime -fprofile-arcs -stdlib=libc++ -framework SenTestingKit -framework Cocoa -framework TestFramework -o ~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug/TestFrameworkTests.octest/Contents/MacOS/TestFrameworkTests
Apple clang version 4.0 (tags/Apple/clang-421.10.48) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
"/Applications/Xcode 4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -bundle -macosx_version_min 10.7.0 -syslibroot "/Applications/Xcode 4.5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" -o ~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug/TestFrameworkTests.octest/Contents/MacOS/TestFrameworkTests -L~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -filelist ~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Intermediates/TestFramework.build/Debug/TestFrameworkTests.build/Objects-normal/x86_64/TestFrameworkTests.LinkFileList -framework SenTestingKit -framework Cocoa -framework TestFramework -force_load "/Applications/Xcode 4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a" -framework Foundation -lobjc -lc++ "/Applications/Xcode 4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.0/lib/darwin/libclang_rt.profile_osx.a" -lSystem "/Applications/Xcode 4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.0/lib/darwin/libclang_rt.osx.a" -F~/Library/Developer/Xcode/DerivedData/TestFramework-axdefcbatoubjbbfqiyxildilobl/Build/Products/Debug "-F/Applications/Xcode 4.5.app/Contents/Developer/Library/Frameworks"
Undefined symbols for architecture x86_64:
"Foo::Bar::Bar()", referenced from:
-[FooBar_Tests testBaz] in FooBar_Tests.o
"Foo::Bar::baz() const", referenced from:
-[FooBar_Tests testBaz] in FooBar_Tests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我:
C++ Language Dialect: c++11
C++ Standard Library: libc++
上都構建目標(框架&測試包)集。
而我當然會鏈接到我的測試包目標中的框架。
此外,所有的框架標題都標記爲public。
我也嘗試將框架文件添加到測試包的目標並將它們排除。這些都沒有解決問題。
我對這裏出了什麼問題感到有些困惑,現在。有任何想法嗎?
這是怎麼了我的C++類是什麼樣子(種):
//FooBar.hh
namespace Foo {
class Bar {
public:
bool baz() const;
}
}
//FooBar.mm
#import "FooBar.hh"
namespace Foo {
bool Bar::baz() const {
return true;
}
}
而且這是我的測試案例:
//FooBar_Tests.hh
#import <SenTestingKit/SenTestingKit.h>
@interface FooBar_Tests : SenTestCase
@end
//FooBar_Tests.mm
#import "FooBar_Tests.hh"
#import <TestFramework/FooBar.hh>
//this one fails as well (compiles fine, fails one linkage):
//#import "FooBar.hh"
@implementation FooBar_Tests
- (void)testBaz {
Foo::Bar bar();
STAssertEquals(bar.baz(), true, nil);
}
編輯:拆分代碼成.hh
& .mm
文件。儘管如此,仍然有相同的錯誤。
符號缺失是Foo :: Bar :: Bar(double *,unsigned int)和Foo :: Bar :: getComponent(unsigned int)const。這真的是完整的測試代碼嗎?必須有別的東西。 – 2012-07-23 16:24:58
@AndréPareis:哦,看起來像我不小心張貼了一箇舊的錯誤日誌(我的_original_代碼)。在試圖弄清楚什麼是錯誤的時候,我最終將類的代碼改爲上面發佈的(完全相同的)簡單代碼,並且仍然有相同的錯誤(但是當然有新的函數名),所以問題保持不變。修復錯誤日誌以反映更改。 – mtree 2012-07-23 18:27:55