EmbDev.net

Forum: ARM programming with GCC/GNU tools Newbie needs help with linking object files into a library


Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
I need some help.

I've compiled all my object files fine, but when it comes to linking
them into a library I get many similar errors, for example: undefined
reference to 'log'

I've specified -lc -lgcc, are there any other libraries I need to link
with?
I noticed that without -lc and -lgcc I get alot more errors, so those
two arguments have definately helped.

Cheers
Jonathan

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
jonathan ymessa wrote:
> I need some help.
>
> I've compiled all my object files fine, but when it comes to linking
> them into a library I get many similar errors, for example: undefined
> reference to 'log'
>
> I've specified -lc -lgcc, are there any other libraries I need to link
> with?
> I noticed that without -lc and -lgcc I get alot more errors, so those
> two arguments have definately helped.
>
> Cheers
> Jonathan

You don't 'link' object files to create a library. The linker is for
creating executables - it attempts to resolve all external references. A
librray is just a collection of object files in an archive. You use ar
(arm-elf-ar.exe) rather than ld (arm-eld.ld.exe) to create a library.

If on the other hand you actually meeant to create an executable image,
then it might help if you could post the entire compile log.

If the undefined reference to 'log' refers to the log() function in
<math.h>, then you will also need to link libm.a (argument: -lm ) - but
again, only if you wanted to create an executable.

Clifford

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
Hi Clifford, I notice my question is identical to this forum posting
http://en.mikrocontroller.net/topic/64670, though it should be noted
that his final question remains unanswered

I've dled glibc-2.3.6, though this wont configure on my system as it
first says you must configure in a seperate build directory.

Upon making a build directory, and placing the configure file it says
(approximately) "Build System is i686-pc-cygwin, and GNU C lib is not
available for this platform, have a nice day"

Which doesnt really help me a great deal.

I appreciate any feedback / comments you may have, I dont think posting
the compile log is necessary as it is similar to the guy in the topic I
mentioned, except i've included every imaginable library I could find on
this system into my libtool file.

All the best
Jonathan

Author: Stefan (Guest)
Posted on:

Rate this post
0 useful
not useful
Clifford Slocombe wrote:
> If the undefined reference to 'log' refers to the log() function in
> <math.h>, then you will also need to link libm.a (argument: -lm ) - but
> again, only if you wanted to create an executable.

Jonathan, did you try linking your program (i think 'library' in your
original post is a error, you can archive object files in a library, but
not link object files in a library) with additional -lm parameter in
makefile? What was the result: undefined reference to 'log' is gone or
not?

Stefan

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
jonathan ymessa wrote:
> Hi Clifford, I notice my question is identical to this forum posting
> http://en.mikrocontroller.net/topic/64670, though it should be noted
> that his final question remains unanswered
>
You think it is identical? He was trying to link a program, you said you
were creating a library (you have not really clarified that point, and
it remains ambiguous). His problem was answered, in his last post he
still had missing syscall stubs which I had already explained to him.

> I've dled glibc-2.3.6, though this wont configure on my system as it
> first says you must configure in a seperate build directory.
>
> Upon making a build directory, and placing the configure file it says
> (approximately) "Build System is i686-pc-cygwin, and GNU C lib is not
> available for this platform, have a nice day"
>
> Which doesnt really help me a great deal.
>
glibc is not suited to embedded systems. It requires a linux operating
system. WinARM is provided with Newlib (as pre-built archives) which is
a portable and retargetable C library (hence the user supplied syscall
stubs). You do not need to provide an alternate library.

> I appreciate any feedback / comments you may have, I dont think posting
> the compile log is necessary as it is similar to the guy in the topic I
> mentioned, except i've included every imaginable library I could find on
> this system into my libtool file.
>
Since it takes next to no effort to post the log, why not!? If it is
'similar' to the referenced log, then the answers are provided in that
thread (which is porbably why the OP has not since posted to that
thread). Besides, when you have a problem you cannot solve yourself,
that is not the time to start second guessing those that may be able to
help you by not provideing the information requested. The log tells us
exactly what you are trying to do, and exactly what is going wrong. For
example we could tell if you are really trying to create a library or a
program! i.e. It would clarify your question without you even saying
another word. In fact it would often be possible to get an answer to a
problem by only posting the log and nothing else; it is a clear and
unambiguous description of the problem, which prose descriptions often
lack (as in this case). It should be the forst thing you post. There are
many subtleties in the log that can provide useful information;
'similar' is not really a useful metric when debugging.


Clifford

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
Stefan wrote:
> Clifford Slocombe wrote:
>> If the undefined reference to 'log' refers to the log() function in
>> <math.h>, then you will also need to link libm.a (argument: -lm ) - but
>> again, only if you wanted to create an executable.
>
> Jonathan, did you try linking your program (i think 'library' in your
> original post is a error, you can archive object files in a library, but
> not link object files in a library) with additional -lm parameter in
> makefile? What was the result: undefined reference to 'log' is gone or
> not?
>
> Stefan

Yeah your right about that, the errors I get now are system dependent (I
think), thus I'll need to look at the newlib, (which is what clifford
was saying).

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
You will have to forgive my terminology, I come from a background of
complete reliance on Microsoft VS.NET 2005, also the reason I didnt post
the log is cause I dont know where it exists :S:$.

My task is to compile 3 libraries for an x-scale processor (compiling
for arm is fine as the instruction set is similar). Because the
libraries/header files that come with Windows Mobile 5.0 aren't
sufficient for me to compile the three .lib files from the .c files, I'm
forced to find an alternative.

So far I'm able to create the objects for each .c file.

Heres a pic of my errors (still couldnt find that log file :$)
http://img56.imageshack.us/img56/3112/errors3kz.jpg

I'm trying that newlib idea, i'll tell you how I get on

Author: Stefan (Guest)
Posted on:

Rate this post
0 useful
not useful
These errors from your screenshot are a FAQ.

You have to provide these functions for your target system. Often these
functions are collected in a file named syscalls.c or syscall.c in
newlibs source sys/<architecture> folder of in several single files in
the same folder.

Stefan

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
jonathan ymessa wrote:
> You will have to forgive my terminology, I come from a background of
> complete reliance on Microsoft VS.NET 2005, also the reason I didnt post
> the log is cause I dont know where it exists :S:$.
>
The log is whereever you put it! The 'log' is simply all the text that
is output during compilation. How you capture this may depend on what
IDE if any you are using. If using the tools from the command line, you
can use redirection or simply copy&patse from the console window; right
click the window, select "Mark", drag the mouse over the text to select
(the window will scroll automatically if necessary) press enter, this
places the text into the paste buffer. If using an IDE of some kind the
text may be redirected to a window, then just copy it from there.

> My task is to compile 3 libraries for an x-scale processor (compiling
> for arm is fine as the instruction set is similar). Because the
> libraries/header files that come with Windows Mobile 5.0 aren't
> sufficient for me to compile the three .lib files from the .c files, I'm
> forced to find an alternative.
>
X-Scale is and ARM processor, not just similar. You should compile
with -mcpu=xscale to generate code that takes specific advantage of teh
xscale architecture.

So you are building a library? In which case you should not be using the
linker, and the syscalls are irellevant (at least for the library - but
may still need them to produce programs that use the library). What
toolchain are you using? The WinARM tools are probably not appropriate
for targetting Windows Mobile targetting.
Consider:
http://win-ce.voxware.com:28575/Development%20Tool...
(although it seems a little old perhaps).

Note also that in GNU, the convention for libraries is to prefix them
'lib' and to use the extension'.a', hence the standard c library is
called libc.a. The linker makes use of this convention to male sense of
the command line option -lc - it adds an implicit prefix and extension
to find libc.a.



> So far I'm able to create the objects for each .c file.
>
> Heres a pic of my errors (still couldnt find that log file :$)
> http://img56.imageshack.us/img56/3112/errors3kz.jpg
>
> I'm trying that newlib idea, i'll tell you how I get on

Well that answers the question about the log; what you posted was a
picture of one! You can copy & paste it from the console as I described.
It also indicates that you are still attempting to 'link' the code (with
ld), when you should be creating a library with ar - as mentioned in the
first response!

Clifford

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
Atm I'm using cygwin on winxp, I'm not able to right/left click the
command line. So I'm not sure how to get the output to text other than
taking a screenie

Currently I'm using a raid0 with winxp, w/o partitioning my hdd theres
no way to install linux so gnuwince isn't really an option to the best
of my knowledge (hence the use of cygwin)

The api that i'm porting to arm comes with huge 'makefile' (I just had
to tell it the correct names of the c compiler etc), thus I assume it
knows what its doing, though I may have to disect the beast or use the
exes on the command line

Cheers for you feedback guys, much appreciated
Jonathan

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
jonathan ymessa wrote:
> Atm I'm using cygwin on winxp, I'm not able to right/left click the
> command line. So I'm not sure how to get the output to text other than
> taking a screenie
>
The bash shell in Cygwin is still just a Win32 console, the technique
should work regardless. Try clicking on the [C:\] icon on the top-left
of the window title bar, and select "Edit->Mark".

> Currently I'm using a raid0 with winxp, w/o partitioning my hdd theres
> no way to install linux so gnuwince isn't really an option to the best
> of my knowledge (hence the use of cygwin)
>
You might consider attempting to build GNUWINCE from source in the
Cygwin environment.  If the project has complied with the GPL you should
be able to get all you need to do that.

> The api that i'm porting to arm comes with huge 'makefile' (I just had
> to tell it the correct names of the c compiler etc), thus I assume it
> knows what its doing, though I may have to disect the beast or use the
> exes on the command line
>
Yes, but not just any compiler perhaps! Also you ar enow chanihng your
story, you "assume it knows what its doing", but you have already had to
tell it the libraries to link (not just the tool names). It may work for
building libraries I suppose, but you will not be able to produce WinCE
executables using just any GCC build, it will need to produce WinCE PE
format executables. And you will probably not be able to link GCC
produced libraries with anything other than a GCC compiler (although I
think the Intel X-Scale compiler will do, but if you had that you would
be using it!). What are you porting the API from? Was the makefile
written with portability in mind?

Your makefile may know what it is doing, but it appears to be attempting
to create an executable, which is not a library - you have still not
really clarified that point. Perhaps it is building a test application
as well as the libraries, in which case you may find the libraries are
already built.

All this (i.e. what are you trying to build) could be answered by
posting the full log, after a make clean/make all.


Having said all that, I think that you may be getting yourself into more
trouble than you need with this. A better approach may be to step back
explain exactly what it is you are trying to achieve: - i.e. what is the
library/API (is it open source, proprietary, something you made, from a
third party etc.)? What is it curently targetted on? What are you trying
to port it to? etc. That way someone may be able to propose an
appropriate toolchain, such as Microsoft's free tools or Intel's
compiler.

You should also be precise about what toolchain you are attempting to
use. Because this is the WinARM forum I assumed you were using WinARM
(which someone may correct me but I believe is not ideally suited to
Windows CE/Pocket PC/Mobile development); this in not always the case on
this forum, but I would expect anyone using anything else to consider I
germane to mention the nature of their build enviromnent and toolchain.

Clifford

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
Cheers Clifford for your post, your correct in saying I need to develop
for Windows CE (which I may have needed to clarify earlier). The API i'm
using is sphinx2, which can compile adequately on win32, there is a
pocketsphinx version, which suggests GNUWINCE as a compiler, though I
didnt use this as I had found WinARM (which I believed was an acceptable
substitute), and Wasabi (an sdk for an intel x-scale compiler), both of
which can exist in windows, the later using cygwin, (i've done a little
experimentation with wasabi, though not enough to determine whether its
what I need).

The pocketsphinx version comes with a configure file (I just ran this
and is said that my c compiler cannot create executables, so maybe I
might need to use something other than WinARM, or build GNUWINCE for
cygwin as you suggest, though I reckon my best bet is to try the wasabi
sdk), it also comes with a Makefile.in and Makefile.am, though i'm not
sure what to do withe these.

The documentation suggests I run ./autogen.sh, though I'll need to
install autoconf/libtool and automake (which ill do first as this may be
the right direction I need).

Jonathan

Author: Jonathan Ymessa (jony)
Posted on:

Rate this post
0 useful
not useful
Jonathan Ymessa wrote:
> The pocketsphinx version comes with a configure file (I just ran this
> and is said that my c compiler cannot create executables)

This was a problem in my environment variables, been resolved :)

> Jonathan

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.