Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Linker error with BSD sockets

Altera_Forum
Honored Contributor II
1,322 Views

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.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
605 Views

Hi squreshi, 

Welcome. 

You need to link with libc for Nios II uClinux. 

 

There is a Nios Wiki now, http://nioswiki.jot.com/wikihome (http://nioswiki.jot.com/wikihome) . 

You can work on Linux. There is a Nios II cross compiler built with uClibc for uClinux. 

You can install binary toolchain, http://nioswiki.jot.com/wikihome/operating...binarytoolchain (http://nioswiki.jot.com/wikihome/operatingsystems/binarytoolchain) . 

Use uClinux-dsit to build your kernel, 

http://nioswiki.jot.com/wikihome/operating...ems/uclinuxdist (http://nioswiki.jot.com/wikihome/operatingsystems/uclinuxdist

And compile your app, 

http://nioswiki.jot.com/wikihome/operating...ms/compilehello (http://nioswiki.jot.com/wikihome/operatingsystems/compilehello)
0 Kudos
Altera_Forum
Honored Contributor II
605 Views

Thanks for the tip, that worked out for me. At first I was confused because the linker was already pulling in libc.a, just not the right libc.a. I had to update my link line as so: 

 

nios2-elf-gcc -o <some executable> {object files} -v -l/cygdrive/c/altera/kits/nios2_51/bin/eclipse/plugins/com.microtronix.nios2linux.uclibc_1.4.0/lib -lc 

 

When I search for all the libc.a files under the nios2_51, I end up with many different copies, presumably for different configurations. Is there a document somewhere that describes the differences between ...\nios2_51\bin\nios2-gnutools\H-i686-pc-cygwin\nios2-elf\lib\mhw-mulx, ...\nios2_51\bin\nios2-gnutools\H-i686-pc-cygwin\nios2-elf\lib\mno-hw-mul, and so on? 

 

Thx, 

 

-SQ 

 

 

--- Quote Start ---  

originally posted by hippo@May 24 2006, 10:21 PM 

hi squreshi, 

welcome. 

you need to link with libc for nios ii uclinux. 

 

there is a nios wiki now, http://nioswiki.jot.com/wikihome (http://nioswiki.jot.com/wikihome) . 

you can work on linux. there is a nios ii cross compiler built with uclibc for uclinux. 

you can install binary toolchain, http://nioswiki.jot.com/wikihome/operating...binarytoolchain (http://nioswiki.jot.com/wikihome/operatingsystems/binarytoolchain) . 

use uclinux-dsit to build your kernel, 

http://nioswiki.jot.com/wikihome/operating...ems/uclinuxdist (http://nioswiki.jot.com/wikihome/operatingsystems/uclinuxdist

and compile your app, 

http://nioswiki.jot.com/wikihome/operating...ms/compilehello (http://nioswiki.jot.com/wikihome/operatingsystems/compilehello

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15566) 

--- quote end ---  

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
605 Views

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

When I search for all the libc.a files under the nios2_51, I end up with many different copies, presumably for different configurations. Is there a document somewhere that describes the differences between ...\nios2_51\bin\nios2-gnutools\H-i686-pc-cygwin\nios2-elf\lib\mhw-mulx, ...\nios2_51\bin\nios2-gnutools\H-i686-pc-cygwin\nios2-elf\lib\mno-hw-mul, and so on?[/b] 

--- Quote End ---  

 

They are libs for different compiler option, ie multilib. 

eg, with/out hw mul, mulx , etc. 

 

You can find gnu tools doc in the nios2 dir.
0 Kudos
Reply