I've created an Xcode static library project using the files transpired by j2objc from our java code. The projects compiles and generates the .a files for iPhone and simulator, but when I add the static library to an app project and call some methods of the static library, I get this kind of compiler errors:
ld: Undefined symbols: OBJC_CLASS$_ComInterfacomSdkTaximeterTaximeterSdk, referenced from: in libTaximeterSdkLiteLib-simulator.a[x86_64]3
SdkLiteInterface is a class with the public methods that can be called by app using the library. This class is not generated by j2objc but created manually in the library project to create a public interface to the library:
@implementation SdkLiteInterface
+ (void) initSdkIOS {
ComInterfacomSdkTaximeterTaximeterSdk_init__();
}
And ComInterfacomSdkTaximeterTaximeterSdk is a j2objc transpiled class, created from the java class com.interfacom.sdk.taximeter.TaximeterSdk that has a method called init() that j2objc converts to The void ComInterfacomSdkTaximeterTaximeterSdk_init__() in the TaximeterSdk.m transfixed class.
The java method (simplified) is:
public synchronized static void init() {
try {
// call some internal methods
} catch (Exception e) {
// log info
}
}
And the method in the generated .m file (simplified): `
void ComInterfacomSdkTaximeterTaximeterSdk_init__() {
ComInterfacomSdkTaximeterTaximeterSdk_initialize();
@synchronized(ComInterfacomSdkTaximeterTaximeterSdk_class_()) {
@try {
// call some internal methods
}
@catch (JavaLangException *e) {
// log info
}
}
}
Any advise on how can I solve this problem will be much appreciated.
I've found a similar question ("j2objc Compile error: Undefined symbols for architecture arm64") but I don't know if it's the same case. There is another one question in stackoverflow (Linking to J2ObjC from another CocoaPod) but it points to the same answer, so I couldn't found any useful answer.
Although you're using j2objc here, there's nothing j2objc-related with this error, it's just regular Objective-C. Once compiled, all Objective-C class symbols start with "OBJC_CLASS$", so this error says that the linker can't find the ComInterfacomSdkTaximeterTaximeterSdk class. It's most likely that your project isn't linking in the library that defines that symbol, but it can also be that the expected library doesn't actually have it.
To check the first cause, check the link command in Xcode's build log, that there's a "-l" library argument with your library (named "lib.a"), and a "-L" path to the directory that library is in. For example, "foo/bar/libexample.a" is the library, then there should be both "-L foo/bar" and "-l example" flags.
If both flags are okay, then the library the class should be needs to be inspected. The easiest way to find which .o file is to find the header that defines "ComInterfacomSdkTaximeterTaximeterSdk_init__", then take the file name without any directory path and change the ".h" to ".o" (for foo/bar/Mumble.java, j2objc generates a foo/bar/Mumble.h and a foo/bar/Mumble.m, which the compiler turns into Mumble.o). Use
ar -t <library>to see the table of .o files in the library. If it's not there, then the library build needs to be fixed.