0

I am trying to compile some simple networking programs on freebsd 8 and running into compilation issues. I am creating a simple client-server programs but no function or structure from networking is not getting compiled.

For eg. I use standard socket() call to create a socket but I run into an error "Called object socket is not a function."

If I remove the network code then my toy program compiles. For simplicity I have just put a simple example which does not compile. :

#include <stdio.h>                        
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void main(){
 int socket = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
 printf("Could create sockets without any issues.\n");
}

I compiled it with "cc toy_prog.c -lc" and gave me the mentioned error.

agent.smith
  • 9,134
  • 9
  • 37
  • 49
  • what do you mean "my program is not able to link against the library (libc)"? Is this a restriction in the design/construction of your code OR do you mean the linker can't find libc OR ?? Error messages (properly formatted) included in you message will make it much easier for people to help you. Do you know about `make` and `makefile`? Only the simpilest projects can get by without a makefile. Good luck. – shellter Dec 17 '12 at 18:10
  • How are you calling socket? It has the signature ``int socket(int domain, int type, int protocol)``. Perhaps you could supply an extract of your code. – Kevin A. Naudé Dec 17 '12 at 18:10
  • please just put your code in your question. Good luck. – shellter Dec 17 '12 at 18:22

1 Answers1

3

A very simple error. You have defined a local variable with the same name as the external function you are trying to call (socket). Try the following and you will get the same error:

int f()
{
    return 0;
}

void main()
{
    int f = f();
}
Kevin A. Naudé
  • 3,992
  • 19
  • 20