[英]C++ does not compile (link?) in XCode 4.2
I have a very small program in Xcode only displaying a label and changing the text of the label in the viewWillAppear method. 我在Xcode中有一个非常小的程序,仅显示标签并在viewWillAppear方法中更改标签的文本。 The label.text should come from a C++ library with a function like this: label.text应该来自具有以下功能的C ++库:
int getNumber(){
return 42;
}
The problem is, that including the class with #import "TestLibMain.h" in my *.mm(!) class and using the function with 问题是,在我的* .mm(!)类中包含带有#import“ TestLibMain.h”的类,并在
TestLibMain *tlb = new TestLibMain();
int myInt = tlb->getNumber();
NSString *myString = [NSString stringWithFormat:@"%d",myInt];
doesn't invoke a compiler error, but a linker error: 不会调用编译器错误,但是会调用链接器错误:
Undefined symbols for architecture i386: "TestLibMain::getNumber()", referenced from: -[tbViewController buttonPressed:] in tbViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 架构i386的未定义符号:“ TestLibMain :: getNumber()”,引用自:tbViewController.o中的-[tbViewController buttonPressed:] (使用-v查看调用)
My impression is, that the cpp-class has not been compiled. 我的印象是,cpp类尚未编译。
I tried a lot of things around, but somewhere it's hanging. 我尝试了很多事情,但是它挂了。 It's all in the same directory, I use the .mm extension, everything fine, but always this linker error. 它们都在同一个目录中,我使用.mm扩展名,一切正常,但始终出现此链接器错误。 Getting crazy :-) 变得疯狂 :-)
Mac OS X Lion, XCode 4.2 Mac OS X Lion,XCode 4.2
Any ideas? 有任何想法吗?
int getNumber() {
return 42;
}
in a .cpp
or .mm
defines getNumber()
as a free function. 在.cpp
或.mm
将getNumber()
定义为自由函数。 This: 这个:
int TestLibMain::getNumber() {
return 42;
}
defines getNumber()
as a member of TestLibMain
. 将getNumber()
定义为TestLibMain
的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.