Jump to content

[solved] Linker error when trying to use global variables as array-index


Recommended Posts

Posted

I'm using this code:

unsigned int FX1;
unsigned int FX2;
const unsigned char FX_Names[10][11] = {"THRU", "F:92 LP", "F:92 BP", "F:92 HP", "F:T2 L/H", "F:T2 L/W", "Delay", "Reverb", "Flanger", "BeatMasher"};
int FX_Values[10] = {0,10,20,30,40,50,60,70,80,90};

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after startup to initialize the 
// application
/////////////////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
	FX1 = 5;
	MIOS_SRIO_UpdateFrqSet(1);
	MIOS_SRIO_NumberSet(4);


}
void DISPLAY_Tick(void) __wparam
{
	//int n = 5	=> works
	//or
	//int n = FX1	=> does not work
	MIOS_LCD_CursorSet(0x00);
	MIOS_LCD_PrintCString("FX 1: ");
	MIOS_LCD_PrintCString( (FX_Names[n]) );


}
Now I have the following problem: If i Initialize the var n in the display_tick function everything works well, but if i use FX1 instead (global var) i get a linker error:
Makefile generated.
Makefile.bat generated.
Assembling MIOS SDCC wrapper
==========================================================================
Compiling pic18f452.c
==========================================================================
Compiling main.c
==========================================================================
Linking project
error: missing definition for symbol "__mulint", required by "_output\main.o"
ERROR!

I don't know why it should use that function.

Has anyone an idea?

Posted

Hello!

Mulint is the function used by SDCC when you need to multiply an integer, which you do when calculating the array address from the index. In order to have this function, you need to include LIBSDCC in your linker script.

Alas, that is about to be/has been phased out, I removed the documentation from the wiki last night, as the new MIOS/GPUtils structure includes it automatically. You could consider looking at the new structure in SVN.

Anyway, in the meantime, grab the library from here and read the readme :)

Posted

Hi,

does it work, when you're avoiding the number in your var-name?

so don't do this:

 int FX1;

but instead:

 int fxOne;

if this doesn't fix your problem, you're using a multiplication somewhere ( "*" ), but haven't imported the sdcclib (as stryd_one already wrote)

Best,

Michael

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...