-1

I've been working with the same code with my school for weeks now. I don't know what I do that fixes thee issues, all I know is that whenever I add code, they come right back. I've read everything off MSDN, I've read almost everything here about linkers and setting things up, I still do not know. Please help me. I understand the issue is with the linker not connecting the header file to the library?

int TCPEchoed(SOCKET fd){
    char    buf[BUFSIZE];
    int clientData;
    clientData = recv(fd, buf, sizeof buf, 0);
    while (clientData != SOCKET_ERROR && clientData > 0) 
    {
        buf[clientData] = '\0';
        fprintf(stderr, buf);
        clientData = recv(fd, buf, sizeof buf, 0);
    }
    if (clientData == SOCKET_ERROR)
    {
        fprintf(stderr, "echo recv error: %d\n", GetLastError());
    }
    closesocket(fd);
    return 0;
}

This is the latest function that brings about the terrible error. "error LNK2019: unresolved external symbol "int __cdecl TCPechoed(unsigned int)" (?TCPechoed@@YAHI@Z) referenced in function "void __cdecl TCPecho(char const *,char const *)" (?TCPecho@@YAXPBD0@Z)"

I move stuff around and I am able to find out that the error is caused by this line.

_beginthread((void (*)(void *))TCPechoed, STKSIZE,  (void *)s);

When I toss it into the main function, I get the error occurs in the main function. I have the function declared at the top as:

int TCPechoed(SOCKET fd);

I would love if someone could assist me on this problem, and teach me what it is that is going wrong so I never have to post about this again.

Thanks.

Brian5193
  • 129
  • 1
  • 3
  • 10
  • 1
    Your definition uses the function name `TCPEchoed` (note the capital "E"). The linker is looking for a function with a lower-case "e". – Lilshieste Apr 17 '14 at 19:45
  • Beware that casting functions is undefined, at least in C++. You should use a function with the proper signature and cast its argument inside the functioninstead. If you happen across a platform where `sizeof(SOCKET) != sizeof(void*)`, which is pretty likely, you could end up with very curious bugs. – molbdnilo Apr 17 '14 at 19:48

1 Answers1

2

C and C++ are case-sensitive. You declared a TCPechoed with lowercase E, but your actual function is called TCPEchoed with uppercase E. You need to fix one or the other.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435