Katie Jurek Katie Jurek - 1 year ago 56
C Question

C compiling - "undefined reference to"?

I am making a reliable data transfer protocol and have the function prototype

void tolayer5(int, char data[]);

With the

struct msg {
char data[20];

struct pkt {
int seqnum;
int acknum;
int checksum;
char payload[20];

And when I call the function in this format:

tolayer5(A, packet.payload);

is an
is a
struct pkt
, I get the error "undefined reference to
'tolayer5(int, char*)'
. Can you help me see what I'm missing here?

void tolayer5(int AorB, char data[])
int i;
if (TRACE>2)
printf("TOLAYER5: data received:");
for (i=0; i<20; i++)

Thank you all for helping with the original issue! :) When trying to fix that one, however, I ran into an infinite loop that I think has something to do with me addressing characters in an array incorrectly (it's been awhile since I've done
like this. Can you help me to find where I'm creating an infinite loop?

I have updated the above code to what I'm now working with. Notice the main changes have been to my function:

void tolayer5(int AorB, char data[])

And this line inside the function:
since now it's just:


Answer Source

seems you need to link with the obj file that implements tolayer5()

Update: your function declaration doesn't match the implementation:

      void tolayer5(int AorB, struct msg msgReceived)
      void tolayer5(int, char data[])

So compiler would treat them as two different functions (you are using c++). and it cannot find the implementation for the one you called in main().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download