EmbDev.net

Forum: ARM programming with GCC/GNU tools socket programming on ViperLite


Author: ajay (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi All,
Sorry in advance if this is not the relevant forum
I'm developing on a Eurotech ViperLite board
Processor : Intel Xscale PXA255
Corss Compiler Toolchain : arm-elf-gcc-3.4.4
Host : Ubuntu 9.04

I'm trying to make a socket programming appilcation
and so far, havent managed to build it
Compile and Link command:
arm-elf-gcc -I/usr/include -o showip showip.c -L/usr/lib -lgcc -lc
Errors:
 incompatible /usr/lib/libc.a when searching for -lc
/tmp/ccysaoud.o(.text+0x84): In function `main':
: undefined reference to `getaddrinfo'
/tmp/ccysaoud.o(.text+0xa0): In function `main':
: undefined reference to `gai_strerror'
/tmp/ccysaoud.o(.text+0x140): In function `main':
: undefined reference to `inet_ntop'
/tmp/ccysaoud.o(.text+0x184): In function `main':
: undefined reference to `freeaddrinfo'
/tmp/ccysaoud.o(.text+0x19c): In function `main':
: undefined reference to `stderr'

I think its because I'm not linking in the libraries
for network programming, but I've tried -L/usr/lib, -L/lib
and -L/usr/local/lib.
Any other path for the libraries? or anything else I'm missing,

Ajay

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
I don't know your system, but in similiar cases I use a handmade
script lsexposym, which searches in some standard dirs for
a given name in libs. It works with find, nm, grep and so on.
Call it with the names you search for and it outputs the
libs which export the symbols you gave on the command line.
By default libs are searched in /usr/lib and /lib and recursively in
all sub dirs of the both.

On my system it gives:
klaus@a64a:~ > lsexposym getaddrinfo gai_strerror inet_ntop freeaddrinfo stderr
Suche nach Symbol getaddrinfo

getaddrinfo gefunden in /usr/lib/libc.a:
Textsegment (Code):            getaddrinfo


getaddrinfo gefunden in /usr/lib/libanl.a:
Textsegment (Code):            getaddrinfo_a


getaddrinfo gefunden in /usr/lib/xen/libc.a:
Textsegment (Code):            getaddrinfo


getaddrinfo gefunden in /usr/lib/xen/libanl.a:
Textsegment (Code):            getaddrinfo_a

Suche nach Symbol gai_strerror

gai_strerror gefunden in /usr/lib/libc.a:
Textsegment (Code):            gai_strerror


gai_strerror gefunden in /usr/lib/xen/libc.a:
Textsegment (Code):            gai_strerror

Suche nach Symbol inet_ntop

inet_ntop gefunden in /usr/lib/libc.a:
Textsegment (Code):            inet_ntop


inet_ntop gefunden in /usr/lib/xen/libc.a:
Textsegment (Code):            inet_ntop

Suche nach Symbol freeaddrinfo

freeaddrinfo gefunden in /usr/lib/libc.a:
Textsegment (Code):            freeaddrinfo


freeaddrinfo gefunden in /usr/lib/xen/libc.a:
Textsegment (Code):            freeaddrinfo

Suche nach Symbol stderr

stderr gefunden in /usr/lib/libcrypto.a:
Textsegment (Code):            OPENSSL_stderr


stderr gefunden in /usr/lib/libc.a:
Data (initialized):            _IO_2_1_stderr_
Data (initialized):            _IO_stderr
Data (initialized):            stderr


stderr gefunden in /usr/lib/xen/libc.a:
Data (initialized):            _IO_2_1_stderr_
Data (initialized):            _IO_stderr
Data (initialized):            stderr


stderr gefunden in /usr/lib/libdbus-1.a:
Textsegment (Code):            _dbus_pipe_is_stdout_or_stderr

Note:
- "Suche nach Symbol ..." means "searching for symbol ..."
- "... gefunden in ..." means "... found in ..."

I append lsexposym so you might search on your Linux if you like.
Unfortunately it is commented in german and outputs in german too,
but perhaps you might find it useful now or later.

----

My assumption is you use the wrong dirs. On your command line
you say "-L/usr/lib". This will use the libs for your running system.

For cross compiling you will have the libs to be used in the
system you compile for probably not in /usr/lib but in
something like /usr/lib/arm... or anywhere else.

If the libs for cross compiling are in a dir beneath /usr/lib
then lsexposym will find them.

If not use "lsexposym -p /some/other/dir getaddrinfo..." to
search in /some/other/dir additionally or use
"lsexposym -p - -p /some/other/dir getaddrinfo..." to search
only in /some/other/dir.

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
and not to forget:
I assume you use not only the wrong dirs for searching the libs but
for searching include files as well.

 Think about "... /usr/include ..." in your command line.

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
I would say that you have provided insufficient information about your 
toolchain/target. The BSD socket API is part of the GNU C library, but 
unless your target is running Linux it is unlikely that your toolchain 
is using that. In fact since you have explicitly linked libc.a, I would 
say definitely.

Most OS-less (or bare metal) GNU cross-compilers use the Newlib C 
library, which provides only the ISO C library, not POSIX or other OS 
dependent extensions. In this case you will have to provide a 
third-party networking library.

Also in most cases you do not need to explicitly link libgcc.a or 
libc.a. By doing so you force a specific version to be linked, which may 
not be appropriate. The toolchain can select library variants based on 
the target, the worst possible case is that you link the host libraries!

Clifford

Author: Andreas Schwarz (andreas) (Admin) Flattr this
Posted on:

Rate this post
0 useful
not useful
@Klaus: please post long source codes as an attachment, not in the text. 
Anyway, your script probably wouldn't help Ajay, because it lists all 
the libraries on the host; he needs a library for the target system of 
his cross compiler.

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
It will help to find the files; it is up to him to think about
which of the listed files are for the host system and which are for
cross compiling.

And yes, I tried to attach the file, but after sending it was not
there. So I posted it inline. No problem for me; I still have it here...

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.