Two libraries extend EAGLview and I want to use them both. How? - objective-c

openFrameworks and cocos2d both have a wrapper for EAGLview.h, and of course you can't just use both. Just adding both libraries (libcocos2d.a and libofxiPhone_iphoneos_Release.a) to my project gives a linker error:
ld: duplicate symbol _OBJC_METACLASS_$_ES1Renderer in /Developer/of_007_iphone/apps/cwi007/iTicTacToe/libofxiPhone_iphoneos_Release.a(ES1Renderer.o) and /Developer/of_007_iphone/apps/cwi007/iTicTacToe/libs/libcocos2d.a(ES1Renderer.o) for architecture armv7
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 failed with exit code 1
I'm writing the core of my program in openFrameworks because it's easy and C++. I want to put a UI, transitions, menus etc. in with cocos2d because it's also easy and looks nice.
I tried
#define __OPENFRAMEWORKS__
in one .h file, and wrapping the other in
#ifndef __OPENFRAMEWORKS__
#endif
figuring I could "augment" the .h in openFrameworks with the extra bits added in by cocos2d, but then openFrameworks wouldn't build because it no longer had a definition for EAGLview.
Is there a best practice for working with two libraries like this that both tap into the same low-level functionality, in this case CoreAnimation? Can I write my own class that inherits from them both? Is there a way to excise one of the .h files from my project?

Try to include the cocos2d.h header where EAGLview.h is included in the original openFrameworks code (i.e. ofMain.h), or vice versa.

Related

Swift generated header with multiple targets

I am having trouble generating the swift header needed to use Swift classes from ObjC, when there are multiple targets with common code.
I created two targets My OSX App and My iOS App. These targets share common code where an ObjC class is calling a Swift class.
As described in Swift and ObjC in the same project I can add #import "My_iOS_App-Swift.h" to my ObjC class and compile it from the My iOS App target.
However, this doesn't compile from the My OSX App target, as the include needs to match the module name. It is looking for #import "My_OSX_App-Swift.h"but the common code does not use that include.
What is the correct way to mix/match Swift/ObjC in code that is shared between multiple targets? I could manually change every target to use a common MyApp-Swift.h, but that doesn't feel right and may cause other problems.
Set the Product Module Name setting in Build Settings to be the same across your modules
For example: $(PROJECT_NAME)
Or use fixed names if you have watch extensions for different targets like: Main_App and Watchkit
This causes the ###-Swift.h file that is generated has the same name across all modules. This also eliminates the need for adding/checking preprocessor micros.
From: Objective C to Swift header file with multiple targets

This class requires automatic reference counting

I am trying to add iRate from https://github.com/nicklockwood/iRate to my app.
After adding file i get this error before even running the project.
#import "iRate.h"
#import <Availability.h>
#if !__has_feature(objc_arc)
#error This class requires automatic reference counting
#endif
http://i.stack.imgur.com/amxPM.png
The solution in this issue in this link https://github.com/nicklockwood/iRate. It is for ARC Compatibility.
As of version 1.7, iRate requires ARC. If you wish to use iRate in a non-ARC project, just add the -fobjc-arc compiler flag to the iRate.m class. To do this, go to the Build Phases tab in your target settings, open the Compile Sources group, double-click iRate.m in the list and type -fobjc-arc into the popover.
If you wish to convert your whole project to ARC, comment out the
#error line in iRate.m, then run the Edit > Refactor > Convert to Objective-C ARC... tool in Xcode and make sure all files that you wish to use ARC for (including iRate.m) are checked.

NinjaMyApp : Duplicate symbol

I am developing one application which is working fine but when i try to include NinjaMyApp folder (using drag & drop), I get duplicate symbol error.
ld: duplicate symbol _OBJC_CLASS_$_InfoView in /Users/xyzpath/NinjaMyApp-v0.32/NinjaMyApp-v0.32/4mnow-1.32/4mnowLaunchPad/4mnowLaunchPad.a(InfoView.o) and /Users/xyzpath/NinjaMyApp-v0.32/NinjaMyApp-v0.32/4mnow-1.32/4mnowBasic/4mnowBasic.a(InfoView.o) for architecture i386
Thanks in advance.
I don't know anything about the static libraries you're using but apparently two of them have duplicate names for classes in them: LaunchPad.a and Basic.a. Perhaps they're not meant to be used together?
don't #include or #import .m files. Just add those .m files into the Target | Build Phases.
Don't add .h files into build phases,
but #import .h files wherever you need those functions.
The compiler knows that it's just a header file "for information only" and that the bodies of the functions will be available when it will compile the .m files and put them all into 1 executable
It seems that you include the class InfoView two time: Search in the project for the duplicate file and remove it. You can do it by searching the name in the project navigation search bars:
Looks like you've imported InfoView.m instead of .h

How do I include an Objective C category in a RubyMotion project

In my Xcode projects I have sometimes used a category for adding zoom level functionality to MKMapView. Now I want use the category in my RubyMotion project. The files are in the vendor dir and I have included them with
app.vendor_project('vendor', :static)
It looks like the compilation goes ok, but ld complains that
ld: in /Users/admin/gitrep/bgApp/vendor/build-iPhoneSimulator/libvendor.a,
archive has no table of contents for architecture i386
Does anyone know if this approach for including categories (and possibly also stand alone classes) work?
With Xcode, create a project as "Cocoa Touch Static Library" and put your codes into this project.
Put this project into your vendor/.
Then write like this in Rakefile to use in RubyMotion.
Rakefile
app.vendor_project('vendor/UIFoo-Bar',
:xcode,
:headers_dir => 'UIFoo-Bar')

Strange error when compiling iPad application(ld: duplicate symbol _OBJC_CLASS_$)

when i compile my project, i have this error :
ld: duplicate symbol _OBJC_CLASS_$_DNCloseButton in /Users/.../Library/Developer/Xcode/DerivedData/...Objects-normal/i386/DNCloseButton-7045D069F03DAA13.o for architecture i386
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang++ failed with exit code 1
I know that the problem is about the class DNCloseButton but i don't how to solve it ? thanks for your answers.
Ensure you've only declared the interface once, in a header file (.h), and imported that header file with #import and not #include.
Sometimes XCode cocks up a little bit and links the same file twice at the linker stage. To fi this:
Remove the file from your project (select the 'remove references' option) and then add it again.
Clean with shift-cmd-k
Build
Hope this helps!
This will happen if a source file is include twice in your Compile Sources Build Phase.
To check this in Xcode 4:
Select your Project from the file list.
Select your target from the left column.
Click on the Build Phases tab on the top bar.
In the search field, type in the name of the class that is causing the linker error. In the case of the question above, it is DNCloseButton (ignore the preceding _).
If the source file for the class appears twice in the Compile Sources list, delete one of the entries.
You might also get this error if you by accident #import the .m file instead of the .h file.
This may happen in the following cases.
You have put the same class implementation into two different files;
You actually have just one implementation of this class, however you are also linking in your project a framework or library containing a class whose name is exactly the same of yours.
Try finding in the whole project your class and make sure only one copy is available within your project.