-1

socket() function used in my code returns -1. Inorder to know more about it example_socket() is added and add headerfile

#include<libexplain/socket.h>

While compiling -lexplain is also added. But i have below error

undefined reference to `explain_socket'

Code:

#include <libexplain/socket.h>
main(){
int sock;
if((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1){
              char message[5000];
        memset(message,0,5000);
                printf("\nSOCKET ERROR\n");
        printf("err: socket() failed");
        fprintf(stderr, "%s\n", explain_socket(AF_INET, SOCK_DGRAM, 0));
        exit(EXIT_FAILURE);
    }
}

Please help me to solve this problem.


[update from comment]

Compilation command:

cc xyz.c -lexplain -o xyz 
alk
  • 69,737
  • 10
  • 105
  • 255
student
  • 39
  • 1
  • 3

1 Answers1

0

Compilation command:

cc xyz.c -lexplain -o xyz 

You might like to specify libraries last on the command line:

cc xyz.c -o xyz -lexplain 
alk
  • 69,737
  • 10
  • 105
  • 255