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 3225288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:19:20+00:00 2026-05-17T16:19:20+00:00

I wrote a test program like this: #include <sys/socket.h> int main( void ) {

  • 0

I wrote a test program like this:

#include <sys/socket.h>
int main( void ) {
    int  sock = socket(AF_INET, SOCK_DGRAM, 0);
    return 0;
}

And tried to compile it:

$ /tool/sunstudio/bin/cc test.c
Undefined                       first referenced
 symbol                             in file
socket                              test.o
ld: fatal: Symbol referencing errors. No output written to a.out

The output is “symbol socket is not referenced”.

Kindly give me the direction so that I can resolve this.

  • 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-17T16:19:21+00:00Added an answer on May 17, 2026 at 4:19 pm

    Here’s the question.

    I wrote a test program like this:

    #include <sys/socket.h>
    int main( void ) {
        int  sock = socket(AF_INET, SOCK_DGRAM, 0);
        return 0;
    }
    

    And tried to compile it so (this is the output that really helps, you have to remember that modern compilers really try their best to help you fix any problems):

    $ /tool/sunstudio/bin/cc test.c
    Undefined                       first referenced
     symbol                             in file
    socket                              test.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    

    Now, from the output we can see that the symbol socket is not referenced. So if you type man socket you will get the following from the man page:

    SYNOPSIS
         cc [ flag ... ] file ... -lsocket  -lnsl  [ library ... ]
    

    The -l flag indicates that to use this function you need to also link the named library. In this case you are being told to add -lsocket -lnsl to the cc command line as follows:

    $ /tool/sunstudio/bin/cc test.c -lsocket -lnsl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small test program with a sample class containing also self-defined constructor,
Hey guys i wrote a quick test. I want delete to call deleteMe which
I just lost 50% of my answer on a test because I wrote the
I see lots of TDD practitioners following this cycle: 1) Write your test as
I'm new to unit testing and nUnit (2.48). I'd like to write a test
I wanted to write a program that test if two files are duplicates (have
I need to write test cases for my application. I've chosen NUnit. Please let
Do you write one test per function/method, with multiple checks in the test, or
I am wondering should I write unit test for everything. There are some classes
I am trying to write a unit test for an action method which calls

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.