ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to add some threads to my distributed FTP code. I'm using the pthreads library. When I compile my code through gcc, here is the error I get:
..
gcc: -lpthread: linker input file unused because linking not done
gcc -O2 -g -lpthread -Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -D__USE_READLINE__ ruserpass.c -c
gcc: -lpthread: linker input file unused because linking not done
gcc cmds.o cmdtab.o domacro.o ftp.o glob.o main.o ruserpass.o -lreadline -lncurses -o ftp
cmds.o(.text+0x1171): In function `init':
/home/hussain/netkit-ftp-0.17/ftp/cmds.c:827: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
make: *** [ftp] Error 1
Any guidance on why I'm getting this error would be highly appreciated.
UPDATE : I fixed it, basically the issue was I was putting the "-lpthread" in the makefile at the wrong place. It should be before you make an executable!
Last edited by hussainahsan; 12-09-2006 at 02:04 AM.
Thanks for the response. I'm having another problem which is that I after I pass in a port to be used as a socket, I am unable to bind() on it again for sometime. Now I thought that by using close or shutdown on the sockfd, I would be able to use that port again. This doesn' seem to be true. Any clues on how to reuse the same port after I've done some data send/receive on it?
First, sockets have a tendency to stick around after they are supposed to be dead. For reusing the same port, accept() returns a brand new file descripter for communicating with a specific client.
Thanks for that link. It's quite useful. However, I tried this:
int yes=1;
if (setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
perror("setsockopt");
exit(1);
}
But after I bind, I still get the "Address already in use" error msg. Now I'm thinking that might have something to do with how I've written my code. I have a main program thread that creates (pthread_create) n threads to listen on n ports. This is not a thread pool so I want the threads to die after completing their job of listening and writing their contents onto file. Now in order make the threads exit, I tried using pthread_join right after I create them. But that doesn't seem to work. Any ideas as to where I should use pthread_join call? Could the threads being still alive after listening and outputting to file be the reason why the my program is unable to bind on the same port(s)?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.