Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:06:13+00:00 2026-05-23T12:06:13+00:00

There is a code sinppet using fcntl, but it goes into trouble when linking:

  • 0

There is a code sinppet using fcntl, but it goes into 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 it in macos:

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

How do I configure it to pass compile successfully?
My 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.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:06:14+00:00Added an answer on May 23, 2026 at 12:06 pm

    If you look at the error returned by the linker you should see your problem, in your code you are using fcnt when you most likely meant fcntl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is code for save button, but I can't see any code behind the
is there ready code snippet for using pop-up modal div without using jquery?
I'm using mvvm light to build a Silverlight application. Is there a code snippet
I am using Drupal Webform 6.x-2.9 - is there a way (some code snippet
Is there a better solution (using less code) for the following code snippet. It
I am creating custom code snippet templates using DevExpress' CodeRush. Is there anyway for
Is there any differences between following code snippets? I'm using VS 2010, .NET 4,
I read the Use AsyncCallback , there is this code snippet: using System; using
Is there a way to create an auto property via code snippet using ReSharper?
There is a code snippet presented in The Pragmatic Programmer on page 143 as:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.