NSClassFromString loading class from a library - iphone

For somewhat complex reasons, I'm needing to access a class from a library I'm writing externally via NSClassFromString. I've tested the method (NSClassFromString) on other libraries and it works with otherwise hidden/internal classes, but it won't work on mine. I build the library as a static library with the -ObjC flag, and I build the project with -ObjC as well. What do I need to do to get the library class to register properly with the lib so I can access it externally?
To be a bit more specific, I'm building a library with associated submodules. The user can add/remove submodules as needed, and I need the main lib to compile and run if they are missing, hence NSClassFromString on submodule classes and fail gracefully if they don't exist. I'm compiling the submodules into individual .a files.

Related

show error when compile lib that I wrapped for basic4android

I wrapped a source github for b4a with Eclipse.
I added core.jar but when I compile the project in b4a it shows this error:
trouble processing "java/com/lsjwzh/widget/materialloadingprogressbar/CircleProgressBar$OvalShadow.class": Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.
This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on.
However, you might actually be trying to define a class in a core namespace, the source of which you may have taken, for example, from a non-Android virtual machine project. This will most assuredly not work. At a minimum, it jeopradizes the compatibility of your app with future versions of the platform.
I changed package name from
java.com.lsjwzh.widget.materialloadingprogressbar
to
com.lsjwzh.widget.materialloadingprogressbar
Why show in error -
"java/com/lsjwzh/widget/materialloadingprogressbar/CircleProgressBar$OvalShadow.class"
?
I rebuilt the project in eclipse and compile with SimpleLibraryCompiler for b4a.
I forgot use
#DependsOn
for calling Additional jar in folder libs.

"Unknown type name" despite included framework

I'm trying (failing) to setup RestKit, which requires one Xcode project to be referenced inside of another. The RestKit framework file creates an NSRegularExpression and appropriately does a #import <Foundation/Foundation.h>. When I build, Xcode spits out "Unknown type name 'NSRegularExpression'".
I'm thinking there might be a circular reference to Core Foundation because I include it in my project and RestKit includes it in theirs? (Remember, the RestKit project is referenced inside of mine, as per their install instructions.)
Also worth noting: In my project build settings, I have the Header and Library search paths set to inside the RestKit/Build path, again, as per their instructions.
I assume you are building your project for iOS. If you included the RestKit.framework in your project, remove it. The .framework is meant to be used in Mac OS projects, add 'libRestKit.a' instead.
I realized I was making the build settings on the project instead of the target. Making sure I was changing paths and libraries on the target instead of the project alleviated all my woes!

Open Source for non-ARC (Automatic Reference Counting) and ARC Users

We have some open source libraries that are distributed via code into other projects via git modules with Xcode. Some of the projects would remain with explicit retains/release while other projects would like to leverage Automatic Reference Counting. Is there anyway for the same source to be compilable in Xcode projects with and without ARC? Would it work if it was compiled into a static library?
If you bundle a project that compiles your open source library as a static library, and the other projects link against your static library instead of compiling the source directly, then that would work. The other projects can embed your library's project file if they want, so that your library will get compiled before theirs, or you can just distribute the static library pre-compiled.

Xcode - deleted openFrameworks libraries, now can't compile and having trouble re-adding

I was 'cleaning up' a project and deleted some of the references to libs used with openFrameworks. Certain things weren't being used, or so I mistakenly thought... Panic in my project!
All sorts of errors, of course. But, XCode won't let me undo that sort of action. I've re-added the libs but the errors persist. Can someone explain to me what basic conceptual thing I'm missing?
Errors go like this [edited]:
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:61: error: 'glutInit' was not declared in this scope
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:62: error: 'GLUT_RGB' was not declared in this scope
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:62: error: 'GLUT_DOUBLE' was not declared in this scope
[UPDATE]. Two things to check: (1) Having a valid build of the oF library itself. Open library project, make sure it builds.
(2) Is the oF library (and all the other, dependent libraries such as Poco) being added in the Build Phases > Link Binary With Libraries section? Sometimes when you delete and then re-add a library, it doesn't get included on this list. Re-drag the library files here. That's what ultimately solved this for me.
Have you tried clean build? I got this error once when adding static libraries.
Found it: Had to manually add the appropriate libraries to be included under "Build Phases". Built the clean download of openFrameworks that way; afterward I could add that to projects referencing the library and build them!

How to build universal static library that works for os3.x and os4.x

Hi I'm trying to create a static library that can added to any ios project, but I can only get it to work such that if I build the library in ios3, it'll work for ios3 projects but not ios4 and vice versa.
The errors I get are:
Undefined symbols:
".objc_class_name_UIImage", referenced from:
literal-pointer#_OBJC#_cls_refs#UIImage in Test3-Release.a(TestViewController.o)
".objc_class_name_NSNotificationCenter", referenced from:
literal-pointer#_OBJC#_cls_refs#NSNotificationCenter in Test3-Release.a(Test.o)
So it looks like it's not finding Foundation and UIKit frameworks for the library?
Here's what I've done so far:
I have 2 projects: 1 is a library project with a library build target. The other is a Test Project that tries to use the library built in the first library.
1) Create a project with a static library target and added all of the implementation files
2) Added libraries like UIKit, Foundation, etc to the "Link Binary with Libraries folder and Set all the linked libraries to have a weak type in my library target.
3) Built the library, added it to my test project, along with my header files.
4) In my test project, I set other linker flags to -ObjC -all_load for all build configurations
When I compile it gives me a bunch of errors as if I didn't include any frameworks.
Anyone have any ideas on what I should do?
Hint (Maybe?)
I also noticed that adding any frameworks to the "Link Binary with Libraries" folder in my library target doesn't seem to do anything. I added CoreLocation to that folder, but when I try to compile in my Test Project it won't compile until I add CoreLocation to my Test Project Frameworks folder.
your dependent project (that uses static library) hassn't linked Framewrok libraries.
Just add to dependent project frameworks (uikIt,Foundation, etc) all will work fine.