EmbDev.net

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


von ajay (Guest)


Rate this post
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

von Klaus W. (mfgkw)


Rate this post
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:
1
klaus@a64a:~ > lsexposym getaddrinfo gai_strerror inet_ntop freeaddrinfo stderr
2
Suche nach Symbol getaddrinfo
3
4
getaddrinfo gefunden in /usr/lib/libc.a:
5
Textsegment (Code):            getaddrinfo
6
7
8
getaddrinfo gefunden in /usr/lib/libanl.a:
9
Textsegment (Code):            getaddrinfo_a
10
11
12
getaddrinfo gefunden in /usr/lib/xen/libc.a:
13
Textsegment (Code):            getaddrinfo
14
15
16
getaddrinfo gefunden in /usr/lib/xen/libanl.a:
17
Textsegment (Code):            getaddrinfo_a
18
19
Suche nach Symbol gai_strerror
20
21
gai_strerror gefunden in /usr/lib/libc.a:
22
Textsegment (Code):            gai_strerror
23
24
25
gai_strerror gefunden in /usr/lib/xen/libc.a:
26
Textsegment (Code):            gai_strerror
27
28
Suche nach Symbol inet_ntop
29
30
inet_ntop gefunden in /usr/lib/libc.a:
31
Textsegment (Code):            inet_ntop
32
33
34
inet_ntop gefunden in /usr/lib/xen/libc.a:
35
Textsegment (Code):            inet_ntop
36
37
Suche nach Symbol freeaddrinfo
38
39
freeaddrinfo gefunden in /usr/lib/libc.a:
40
Textsegment (Code):            freeaddrinfo
41
42
43
freeaddrinfo gefunden in /usr/lib/xen/libc.a:
44
Textsegment (Code):            freeaddrinfo
45
46
Suche nach Symbol stderr
47
48
stderr gefunden in /usr/lib/libcrypto.a:
49
Textsegment (Code):            OPENSSL_stderr
50
51
52
stderr gefunden in /usr/lib/libc.a:
53
Data (initialized):            _IO_2_1_stderr_
54
Data (initialized):            _IO_stderr
55
Data (initialized):            stderr
56
57
58
stderr gefunden in /usr/lib/xen/libc.a:
59
Data (initialized):            _IO_2_1_stderr_
60
Data (initialized):            _IO_stderr
61
Data (initialized):            stderr
62
63
64
stderr gefunden in /usr/lib/libdbus-1.a:
65
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.

von Klaus W. (mfgkw)


Rate this post
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.

von Clifford S. (clifford)


Rate this post
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

von Andreas S. (andreas) (Admin)


Rate this post
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.

von Klaus W. (mfgkw)


Rate this post
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...

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.