LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-02-2007, 06:20 PM   #1
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
undefined reference error


Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>

int connect_nonblocking(int sockfd, const struct sockaddr * saptr, socklen_t salen, int nsec)
{
	int flags, n, error;
	socklen_t len;
	fd_set rset, wset;
	struct timeval tval;
		
	flags = Fcntl(sockfd, F_GETFL, 0);
	Fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
	
	error = 0;
	if((n = connect(sockfd, (struct sockaddr *) saptr, salen)) < 0)
		if(errno != EINPROGRESS)
			return(-1);
		
	if(n == 0)
		goto done;
	
	FD_ZERO(&rset);
	FD_SET(sockfd, &rset);
	wset = rset;
	tval.tv_sec = nsec;
	tval.tv_usec = 0;
	
	if((n = Select(sockfd + 1, &rset, &wset, NULL, nsec ? &tval : NULL)) == 0)
	{
		close(sockfd);
		errno = ETIMEDOUT;
		return(-1);
	}
	if(FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset))
	{
		len = sizeof(error);
		if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
			return(-1);
	}
	else
		err_quit("select error: sockfd not set");
	
	done:
	Fcntl(sockfd, F_SETFL, flags);
	
	if(error)
	{
		close(sockfd);
		errno= error;
		return(-1);
	}
	return(0);
}
but when i try to compile it gcc say

"undefined reference to fcntl"

"undefined reference to select"


"undefined reference to err_quit"

can't figure it out please help.

regards,
Imran
 
Old 08-02-2007, 08:22 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You should not have fcntl and select capitalized. Try changing those and see what happens.
ta0kira
 
Old 08-02-2007, 08:34 PM   #3
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
thanks alot it worked
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference error jacques83 Programming 20 04-11-2013 07:23 AM
Getting undefined reference to main error?? Mistro116@yahoo.com Programming 14 07-29-2011 08:28 AM
undefined reference error bahadur Programming 5 07-25-2006 09:18 PM
Undefined reference error in MD5_Init() jacques83 Linux - Networking 0 11-11-2005 09:44 PM
undefined reference error Quest101 Programming 3 01-01-2005 12:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration