Hi Charles,
Thanks for replying!
I don't believe it's a problem calling C functions, you just have to declare them with 'extern "C"' to avoid name mangling (I think??).
The issue is, when I want to use C++ I have to switch the implementation file to ".mm", which is a Objective-C++ file. As soon as I do this Xcode starts complaining about 'class_addmethod()' in my setup function. The weird thing is that it only applies to 'class_addmethod()'. For example, 'class_addbang()', 'class_new()' all work fine.
It seems like it's an issue only with this function, and it looks like class_addMethod is already a function used by Objective-C https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html I think maybe there's some namespace issues, but I have no idea how to resolve this.
wrote wrapper functions to export a C-callable public interface to C++
functions.
Yep, this is what I'm doing now. A bit annoying because I was so close :)
Thanks for your help!
Cheers, Joe
On 27 April 2012 04:10, Charles Henry czhenry@gmail.com wrote:
Hi guys
The part that I don't get is how to call C functions from C++? I don't think I've even tried that before. Have you? Joe: I've built externals that just call C++ functions that I declared with extern "C" or wrote wrapper functions to export a C-callable public interface to C++ functions. Best suggestion I've got is to identify which functions you've got are going to be public and which ones are private and plan out how you're going to declare them.
Chuck
On 4/26/12, Ed Kelly morph_2016@yahoo.co.uk wrote:
Hi Joe,
Have you thought of using ofxPd?
I'm involved in the creation of an app for the iPhone right now, and
we're
using ofxPd from Dan Wilcox: https://github.com/danomatika/ofxPd Since Openframeworks is a bunch of C++ wrappers for various libraries,
ofxPd
adds Pd to the libraries that you can work with in C++. Then you can call the setup function within the xcode build, and your
object
will work in libpd (i.e. ofxPd) in the app environment. Bear in mind that Apple do not like GnuGPL licensed stuff, so I've
created
BSD licensed versions of some of my own Pd externals for this project.
And the app works. We're in the final stages now, so I'll post to the
list
when it's complete! Best, Ed
Gemnotes-0.1alpha: Live music notation for Pure Data http://sharktracks.co.uk/
From: Joe White white.joe4@gmail.com To: pd-list pd-list@iem.at Sent: Thursday, 26 April 2012, 16:51 Subject: [PD] [Pd] Compile external with C++ compiler?
Hi all,
Thought I might as well ask this here because you guys know everything :)
I'm writing an external to be built into an iOS app that's running Pd.
The
catch is I need to interface with a C++ library within the external.
The external builds and runs fine if I'm using the C compiler (in Xcode)
but
I can't access the C++ library functions. If I switch it to compile in
C++
(by changing the objective-c file from .m to .mm) then I can use the C++ library functions but it complains that it can't find 'class_addmethod'
'No matching function for call to
'class_addmethod'
I've tried declaring the setup function as C code like Katja explains on
her
site: extern "C" void external_tilde_setup(void) { } But that still didn't seem to work. I was also going through the list and found this thread but I'm not sure if it's the right approach. Plus I'm
more
of an audio guy than programmer :)
Any ideas would be much appreciated.
Thanks, Joe -- Follow me on Twitter @diplojocus
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list