我正在与j2objc一起玩,以查看是否可以在项目中使用番石榴。
我的项目非常简单:为j2obcj(https://github.com/google/j2objc/wiki/Xcode-Build-Rules)配置的单视图应用程序,在appDelegete.m
中添加了自定义行
#include "java/util/ArrayList.h"
#include "com/google/common/collect/Lists.h"
[...]
[ComGoogleCommonCollectLists newArrayList];
尝试编译它会产生错误:
Undefined symbols for architecture x86_64:
"_JavaxAnnotationMetaWhenEnum_initialized", referenced from:
+[ComGoogleCommonBaseCharMatcher __annotations_removeFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_retainFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_replaceFromWithJavaLangCharSequence_withChar_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_replaceFromWithJavaLangCharSequence_withJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimLeadingFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimTrailingFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
...
"_JavaxAnnotationMetaWhenEnum_values_", referenced from:
+[ComGoogleCommonBaseCharMatcher __annotations_removeFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_retainFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_replaceFromWithJavaLangCharSequence_withChar_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_replaceFromWithJavaLangCharSequence_withJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimLeadingFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
+[ComGoogleCommonBaseCharMatcher __annotations_trimTrailingFromWithJavaLangCharSequence_] in libguava.a(CharMatcher.o)
...
"_OBJC_CLASS_$_JavaxAnnotationCheckForNull", referenced from:
objc-class-ref in libguava.a(Ints.o)
objc-class-ref in libguava.a(AndroidInteger.o)
"_OBJC_CLASS_$_JavaxAnnotationCheckReturnValue", referenced from:
objc-class-ref in libguava.a(CharMatcher.o)
objc-class-ref in libguava.a(Joiner.o)
objc-class-ref in libguava.a(Splitter.o)
objc-class-ref in libguava.a(CacheBuilder.o)
objc-class-ref in libguava.a(BaseEncoding.o)
objc-class-ref in libguava.a(UnsignedLong.o)
objc-class-ref in libguava.a(UnsignedInteger.o)
...
"_OBJC_CLASS_$_JavaxAnnotationMetaWhenEnum", referenced from:
objc-class-ref in libguava.a(CharMatcher.o)
objc-class-ref in libguava.a(Joiner.o)
objc-class-ref in libguava.a(Splitter.o)
objc-class-ref in libguava.a(CacheBuilder.o)
objc-class-ref in libguava.a(BaseEncoding.o)
objc-class-ref in libguava.a(UnsignedLong.o)
objc-class-ref in libguava.a(UnsignedInteger.o)
...
"_OBJC_CLASS_$_JavaxAnnotationNullable", referenced from:
objc-class-ref in libguava.a(Equivalence.o)
objc-class-ref in libguava.a(FunctionalEquivalence.o)
objc-class-ref in libguava.a(Functions.o)
objc-class-ref in libguava.a(Joiner.o)
objc-class-ref in libguava.a(Objects.o)
objc-class-ref in libguava.a(Optional.o)
objc-class-ref in libguava.a(PairwiseEquivalence.o)
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
似乎在链接时有问题,
When.o
中没有libjre_emul.a
。我尝试运行以下行没有任何问题,只是为了检查
javax
包是否在那里#include "javax/xml/parsers/SAXParser.h"
[...]
[[JavaxXmlParsersSAXParser alloc] init];
还要检查
SAXParser.i
是否在libjre_emul
中$ otool -o lib/libjre_emul.a | grep .o\): | grep SAXParser
lib/libjre_emul.a(SAXParser.o):
lib/libjre_emul.a(SAXParserFactory.o):
lib/libjre_emul.a(SAXParserFactoryImpl.o):
lib/libjre_emul.a(SAXParserImpl.o):
但是在尝试
When
的情况下#include "javax/annotation/meta/When.h"
[...]
[JavaxAnnotationMetaWhenEnum values];
我收到类似于番石榴的错误
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_JavaxAnnotationMetaWhenEnum", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
检查
libjre_emul
后,没有When.o
otool -o lib/libjre_emul.a | grep .o\): | grep When
我的设置是:
J2OBJC_HOME = ./bin/j2objc-0.9.5;
HEADER_SEARCH_PATHS = $(inherited) "${J2OBJC_HOME}/include";
LIBRARY_SEARCH_PATHS = $(inherited) "${J2OBJC_HOME}/lib";
OTHER_LDFLAGS = $(inherited) -l"z" -l"jre_emul" -l"guava" -l"icucore" -framework "Security" -ObjC;
我尝试了其他版本(0.9.5、0.9.4、0.9.3、0.9),但错误仍然存在。
总之,据我所知,无法将guava与j2objc一起使用,因为它取决于缺少的符号。
希望有人能证明我错了吗?我真的很想开始在实际项目中使用j2objc!
提前致谢!圣诞节快乐!
最佳答案
尝试链接jsr305库(-ljsr305),因为它定义了上面引用的javax.annotation注释。