<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>
      <blockquote type="cite">
        <div>You also need to be sure that the first class is loaded
          before, like:</div>
        <div>[declare -lib sender -lib receiver]</div>
        else the receiver object won't load because of link error due to
        missing symbol "send_test_class".</blockquote>
      Ugh, one more reason for having all objects in a single binary :-)</p>
    <div class="moz-cite-prefix">On 19.01.2021 23:31, Antoine Rousseau
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAOCG5HwbQ8YJi-P_FoAU+hPR9RshWFJWV2PJ-Mwxn9iLRmT+cw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <div>hi,</div>
          <div><br>
          </div>
          <div>I would say the problem comes from you declaring
            send_test_class as static in both files, so 2 independent
            variables are created.</div>
          <div><br>
          </div>
          <div>What you can do is declaring send_test_class without
            "static" in the first file:</div>
          <div>
            <div dir="ltr">t_class *send_test_class;</div>
            <div dir="ltr"><br>
            </div>
            <div>then using the "extern" keyword in the second file:</div>
            <div>extern t_class *send_test_class;</div>
            <div><br>
            </div>
            <div>Even better, you could create a header file like
              "sender_test_class.h", in which you put both the "extern"
              class declaration and <br>
            </div>
            <div>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).<br>
            </div>
            <div><br>
            </div>
            <div>You also need to be sure that the first class is loaded
              before, like:</div>
            <div>[declare -lib sender -lib receiver]</div>
            <div>else the receiver object won't load because of link
              error due to missing symbol "send_test_class".<br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">Le mar. 19 janv. 2021 à 21:39,
          Miller Puckette via Pd-dev <<a
            href="mailto:pd-dev@lists.iem.at" moz-do-not-send="true">pd-dev@lists.iem.at</a>>
          a écrit :<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">That's
          indeed the difference - a c object like "send_test_class"
          can't<br>
          be shared beteen different object modules loaded separately
          into Pd.  This<br>
          is one reason people have sometimes put multiple externals
          into a single<br>
          object file.<br>
          <br>
          You could have both externs have the same  "family name" (like<br>
          "array define" and "array set") - then they can both be
          defined in the<br>
          same C object file "binarytree.[extent]".<br>
          <br>
          cheers<br>
          Miller<br>
          <br>
          On Tue, Jan 19, 2021 at 11:38:22AM -0800, Eric Lennartson
          wrote:<br>
          > Hello all,<br>
          > <br>
          > I've been working on trying to send data between
          different externals, but<br>
          > I'm not doing something quite right. I've looked at the
          code in d_global.c<br>
          > as well as for send and receive.<br>
          > The only difference I can see is that mine is not all in
          the same .c file<br>
          > while in the pd source it is.<br>
          > <br>
          > Here's the external with the data. Just an int for now,
          but it will be<br>
          > holding a binary tree later.<br>
          > <br>
          > static t_class *send_test_class;<br>
          > typedef struct _send_test {<br>
          >    t_object  x_obj;<br>
          >    t_symbol* name;<br>
          >    int value;<br>
          > }t_send_test;<br>
          > <br>
          > static void *send_test_new(t_symbol *s, t_floatarg f) {<br>
          >    t_send_test *x = (t_send_test
          *)pd_new(send_test_class);<br>
          >    x->name = s;<br>
          >    x->value = f;<br>
          >    pd_bind(&x->x_obj.ob_pd, s); // bind to the
          name we're given<br>
          >    post("send_test created with name %s, and value %d",
          x->name->s_name,<br>
          > x->value);<br>
          >    return(x);<br>
          > }<br>
          > <br>
          > static void send_test_free(t_send_test *x) {<br>
          >    pd_unbind(&x->x_obj.ob_pd, x->name); //
          unbind when deleted<br>
          > }<br>
          > <br>
          > void send_test_setup(void) {<br>
          >    send_test_class = class_new(gensym("send_test"),<br>
          >                                 
          (t_newmethod)send_test_new,<br>
          >                                 
          (t_method)send_test_free,<br>
          >                                  sizeof(t_send_test),<br>
          >                                  CLASS_NOINLET,<br>
          >                                  A_DEFSYM,<br>
          >                                  A_DEFFLOAT,<br>
          >                                  0);<br>
          > }<br>
          > <br>
          > And here's the receiver.<br>
          > <br>
          > static t_class *send_test_class;<br>
          > <br>
          > static t_class *rcv_test_class;<br>
          > <br>
          > typedef struct _send_test {<br>
          >    t_object  x_obj;<br>
          >    t_symbol* name;<br>
          >    int value;<br>
          > }t_send_test;<br>
          > <br>
          > typedef struct _rcv_test {<br>
          >    t_object  x_obj;<br>
          >    t_symbol* name;<br>
          > <br>
          >    int value;<br>
          > } t_rcv_test;<br>
          > <br>
          > static void *rcv_test_new(t_symbol *s) {<br>
          >    t_rcv_test *x = (t_rcv_test *)pd_new(rcv_test_class);<br>
          >    x->name = s;<br>
          >    t_send_test* sender =
          (t_send_test*)pd_findbyclass(x->name,<br>
          > send_test_class);<br>
          > <br>
          >     x->value = sender->value;<br>
          >     post("sender value is %d", sender->value);<br>
          >     post("rcv_test created with name %s, and value %d",
          x->name->s_name,<br>
          > x->value);<br>
          >     return(x);<br>
          > }<br>
          > <br>
          > static void rcv_test_free(t_rcv_test *x) {}<br>
          > <br>
          > void rcv_test_setup(void) {<br>
          >    rcv_test_class = class_new(gensym("rcv_test"),<br>
          >                                               
          (t_newmethod)rcv_test_new,<br>
          >                                               
          (t_method)rcv_test_free,<br>
          >                                               
           sizeof(t_rcv_test),<br>
          >                                               
           CLASS_NOINLET,<br>
          >                                                 A_DEFSYM,<br>
          > <br>
          >                                                 0);<br>
          > }<br>
          > <br>
          > What exactly is it that I'm doing wrong?<br>
          <br>
          > _______________________________________________<br>
          > Pd-dev mailing list<br>
          > <a href="mailto:Pd-dev@lists.iem.at" target="_blank"
            moz-do-not-send="true">Pd-dev@lists.iem.at</a><br>
          > <a
href="https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$</a>
          <br>
          <br>
          <br>
          <br>
          <br>
          _______________________________________________<br>
          Pd-dev mailing list<br>
          <a href="mailto:Pd-dev@lists.iem.at" target="_blank"
            moz-do-not-send="true">Pd-dev@lists.iem.at</a><br>
          <a href="https://lists.puredata.info/listinfo/pd-dev"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.puredata.info/listinfo/pd-dev</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Pd-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a>
<a class="moz-txt-link-freetext" href="https://lists.puredata.info/listinfo/pd-dev">https://lists.puredata.info/listinfo/pd-dev</a>
</pre>
    </blockquote>
  </body>
</html>