我正在玩 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),但错误仍然存在。
总之,据我所知,没有办法将番石榴与 j2objc 一起使用,因为它取决于缺少的符号。
希望有人能证明我错了吗?我真的很想在实际项目中开始使用 j2objc!
提前致谢!圣诞节快乐!