You also need to be sure that the first class is loaded before, like: [declare -lib sender -lib receiver] else the receiver object won't load because of link error due to missing symbol "send_test_class".
Ugh, one more reason for having all objects in a single binary :-)
On 19.01.2021 23:31, Antoine Rousseau wrote:
hi,
I would say the problem comes from you declaring send_test_class as static in both files, so 2 independent variables are created.
What you can do is declaring send_test_class without "static" in the first file: t_class *send_test_class;
then using the "extern" keyword in the second file: extern t_class *send_test_class;
Even better, you could create a header file like "sender_test_class.h", in which you put both the "extern" class declaration and the definition of the t_send_test structure, so you don't have to repeat yourself (you'll still need to actually declare the class, without "extern", in the first file).
You also need to be sure that the first class is loaded before, like: [declare -lib sender -lib receiver] else the receiver object won't load because of link error due to missing symbol "send_test_class".
Le mar. 19 janv. 2021 à 21:39, Miller Puckette via Pd-dev <pd-dev@lists.iem.at mailto:pd-dev@lists.iem.at> a écrit :
That's indeed the difference - a c object like "send_test_class" can't be shared beteen different object modules loaded separately into Pd. This is one reason people have sometimes put multiple externals into a single object file. You could have both externs have the same "family name" (like "array define" and "array set") - then they can both be defined in the same C object file "binarytree.[extent]". cheers Miller On Tue, Jan 19, 2021 at 11:38:22AM -0800, Eric Lennartson wrote: > Hello all, > > I've been working on trying to send data between different externals, but > I'm not doing something quite right. I've looked at the code in d_global.c > as well as for send and receive. > The only difference I can see is that mine is not all in the same .c file > while in the pd source it is. > > Here's the external with the data. Just an int for now, but it will be > holding a binary tree later. > > static t_class *send_test_class; > typedef struct _send_test { > t_object x_obj; > t_symbol* name; > int value; > }t_send_test; > > static void *send_test_new(t_symbol *s, t_floatarg f) { > t_send_test *x = (t_send_test *)pd_new(send_test_class); > x->name = s; > x->value = f; > pd_bind(&x->x_obj.ob_pd, s); // bind to the name we're given > post("send_test created with name %s, and value %d", x->name->s_name, > x->value); > return(x); > } > > static void send_test_free(t_send_test *x) { > pd_unbind(&x->x_obj.ob_pd, x->name); // unbind when deleted > } > > void send_test_setup(void) { > send_test_class = class_new(gensym("send_test"), > (t_newmethod)send_test_new, > (t_method)send_test_free, > sizeof(t_send_test), > CLASS_NOINLET, > A_DEFSYM, > A_DEFFLOAT, > 0); > } > > And here's the receiver. > > static t_class *send_test_class; > > static t_class *rcv_test_class; > > typedef struct _send_test { > t_object x_obj; > t_symbol* name; > int value; > }t_send_test; > > typedef struct _rcv_test { > t_object x_obj; > t_symbol* name; > > int value; > } t_rcv_test; > > static void *rcv_test_new(t_symbol *s) { > t_rcv_test *x = (t_rcv_test *)pd_new(rcv_test_class); > x->name = s; > t_send_test* sender = (t_send_test*)pd_findbyclass(x->name, > send_test_class); > > x->value = sender->value; > post("sender value is %d", sender->value); > post("rcv_test created with name %s, and value %d", x->name->s_name, > x->value); > return(x); > } > > static void rcv_test_free(t_rcv_test *x) {} > > void rcv_test_setup(void) { > rcv_test_class = class_new(gensym("rcv_test"), > (t_newmethod)rcv_test_new, > (t_method)rcv_test_free, > sizeof(t_rcv_test), > CLASS_NOINLET, > A_DEFSYM, > > 0); > } > > What exactly is it that I'm doing wrong? > _______________________________________________ > Pd-dev mailing list > Pd-dev@lists.iem.at <mailto:Pd-dev@lists.iem.at> > https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$ <https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$> _______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at <mailto:Pd-dev@lists.iem.at> https://lists.puredata.info/listinfo/pd-dev <https://lists.puredata.info/listinfo/pd-dev>
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev