我正在玩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!
提前致谢!圣诞快乐!
答案 0 :(得分:4)
尝试在jsr305库(-ljsr305)中进行链接,因为它定义了上面引用的javax.annotation注释。