Altera_Forum
Honored Contributor
19 years agoLinker error with BSD sockets
I am a definite newbie to Nios/uClinux but not a newbie to UNIX development in general. I have a "server" program that I developed and tested using cygwin for Windows, and now am trying to port over to Nios. I get linker errors like the sort shown below:
gc102.o(.text+0x94):/cygdrive/c/Altera/src/gc102/gc102.c:173: undefined reference to `gethostname' gc102.o(.text+0x9c):/cygdrive/c/Altera/src/gc102/gc102.c:174: undefined reference to `gethostbyname' gc102.o(.text+0xcc):/cygdrive/c/Altera/src/gc102/gc102.c:186: undefined reference to `bind' gc102.o(.text+0xe4):/cygdrive/c/Altera/src/gc102/gc102.c:192: undefined reference to `listen' gc102.o(.text+0x11c):/cygdrive/c/Altera/src/gc102/gc102.c:199: undefined reference to `accept' gc102.o(.text+0x370):/cygdrive/c/Altera/src/gc102/gc102.c:97: undefined reference to `stderr' The stderr one is a different issue, although I would like to solve the socket problem 1st since for the time being I can replace fprintf(stderr,"...') with printf() calls. I tried linking in the standard libsocket.a library by adding -lsocket, but then I get an error that the cross-compiler/linker is unable to locate the sockets library: /cygdrive/c/Altera/kits/nios2_51/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld: cannot find -lsocket By adding the -v (verbose) flag to the linker I determined that with my installation, the libs are in C:\Altera\kits\nios2_51\bin\nios2-gnutools\H-i686-pc-cygwin\nios2-elf\lib. When I go to that directory I see many familiar static libraries, like libm.a, libc.a, and so on, but no libsocket.a. What am I missing here? Or is there a different library I need to be linking to/ Any help would be most appreciated.