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

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
×
×
  • Create New...