osx - link error with fcntl in macos -


there code sinppet using fcntl, goes trouble when linking:

#include <poll.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h>  #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <fcntl.h>  int main() {     struct addrinfo hints, *ai, *cur_ai;     int port, fd = -1;     memset(&hints, 0, sizeof(hints));     hints.ai_family = af_unspec;     hints.ai_socktype = sock_stream;      char portstr[10];     char hostname[] = "www.google.com";     snprintf(portstr, sizeof(portstr), "%d", port);     int ret = getaddrinfo(hostname, portstr, &hints, &ai);     if(ret)     {         printf("die");         return ;     }     printf("getaddrinfo !!!");      cur_ai = ai;     fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);     fcntl(fd, f_setfl, fcnt(fd, f_getfl) | o_nonblock);     ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);  } 

i compiled in macos:

qty:socket_lab qrtt1$ gcc main.c undefined symbols architecture x86_64:   "_fcnt", referenced from:       _main in cccndwem.o      (maybe meant: _fcntl) ld: symbol(s) not found architecture x86_64 collect2: ld returned 1 exit status 

how configure pass compile successfully? gcc version is:

qty:socket_lab qrtt1$ gcc --version i686-apple-darwin10-gcc-4.2.1 (gcc) 4.2.1 (apple inc. build 5666) (dot 3) copyright (c) 2007 free software foundation, inc. free software; see source copying conditions.  there no warranty; not merchantability or fitness particular purpose. 

if @ error returned linker should see problem, in code using fcnt when meant fcntl.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -