Sign in to follow this  
Followers 0
jeb

problem with the linker (even with libsdcc)

6 posts in this topic

hello

there is a problem with the linker, even with libsdcc.lib      in /lib and set up in the .lkr file.

always the same problem :

error: missing definition for symbol "_sprintf", required by "_output\main.o"

i can include : #include "sprintf.c"

but then it is another file that makes problem  : _vfprintf

then i include : #include "vfprintf.c"

then it is another one ....

then i include the .c file

then another one...

this can continue very long !

is it normal that one should include all these .c files for the different functions when one needs

to use a function ???!  ???

i gave the example with printf, but with memcpy, etc. it's the same !

thanx

Share this post


Link to post
Share on other sites

Hi jeb,

no, there is no problem with the linker, there is a problem with your code.

you haven't read the libsdcc.lib README.txt from TK, haven't you? :P ;) ;)

1) printf prints a string to the console/a file/the buffer.

what console/file/buffer exactly do you want to use on the PIC18F?

2) if you can avoid it, don't use the lib. as you just found out, it blows the code extremely. I coded a lot for mios, but I never ever have been in the situation to need the lib.

regards,

Michael


This is a special variant of libsdcc.lib which complies to following

MIOS specifics:

  o udata_ovr located to 0x010

  o FSR1 and FSR0 pointer related registers swapped

The use of this library is required whenever pointer operations' date=' multiplications,

divisions, etc. are used, and the linker misses the appr. functions

--------------------------------------------------------------------------------

Integration guide

=================

Follow these steps to integrate the library into the MIOS C project:

  o create a 'lib' directory within the root directory of your project

  o copy the 'libsdcc.lib' file into this directory

  o open the "project.lkr" file of your project and add following

    line below the "LIBPATH" entry:

---

FILES lib/libsdcc.lib

---

  o type "make" in order to build the project

Thats all :)

Share this post


Link to post
Share on other sites

Hi Jeb,

Here's just a bit of explanation of C from the "theoretical" standpoint, maybe you already know that but ok let's give it a try...

Normally, it is .h that you should include in your c files, not .c.

The header file (.h) contains the definition of the function i.e. its name, parameters, ...

The source code file (.c) contains the actual function with its code.

When compiled the .c becomes an object file (.obj) and linking all the .obj files together leads to the executable.

You can also find libraries (.lib) that put together a collection of object files. It's an easy way to add several files in one shot.

Usually, functions like printf are grouped in a library stdlib.lib and the definitions are contained in some common headers like stdio.h, stdlib.h, ... The header files must be included in your code and the lib files added to your project/link_script/... so that the linker can find them.

Note that this was about C in general, you should of course follow the advice of audiocommander for the current error you have.

Best regards,

Lall

Share this post


Link to post
Share on other sites

Hi,

thanx for all answers.

I have read the libsdcc.lib README.txt from TK !!

> 1) printf prints a string to the console/a file/the buffer.

> what console/file/buffer exactly do you want to use on the PIC18F?

sorry, i wanted to speak about "sprintf" which outputs not to the console but to a string.

but the problem is the same when i use for example "memcpy", even with the libsdcc

configured as in the README.TXT...

regards,

jeb

Share this post


Link to post
Share on other sites

Hi Jeb,

I've never used TK's varian lib so I'm a bit guessing in the dark but when I look at the library files from TK, I can't see any mention of sprintf.

I believe that this function is not part of TK's variant which is maybe the root of the problem as the sprintf is actually in this library. The problem is that the library that you must include for MIOS compatiblity does not contain this function so you're a bit stuck.

What I'm a bit surprised about though is the error that you get here. It really looks like you've not included stdio.h in which sprintf is defined. At least let's say the error you get is the kind of error that a C compiler should generate in that case.

If the function is defined but it cannot find it because it's not in a lib or in a source file then the linker should complain about an "unreference symbol" error as it's most of the time called.

Do I understand correctly that you have the same error with the original sdcclib.lib and with TK's one? If so then I would really not understand if it would not be a problem of include files.

Best regards,

Lall

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0