Variables in User Created Library

Hello all,

I am writing a program and trying to separate some of the files into libraries so that the code is more manageable. I am currently having the problem that when I try to declare a variable outside of one of my functions but inside the library, I get the following error:

line 45 : MY_LIBRARY.LIB : Undefined (but used) global label portChannelMapping

I have read through the documentation and it says that if you are going to use variables, you should declare them in the body so that it doesn’t waste memory. I assume this means that you can use variables in a library.

If it makes any difference, I am using a pointer.

Any help or suggestions would be very much appreciated!


Well, I kept looking at the other library files and found my error. I was not declaring the variable inside any actual header. I had forgotten that the comments were more than just comments.

All I did was add all of the functions that needed access to the variable (all of them in this case) to the header and stuck the variable as an extern in the header. Then I declared it below. My final code looked something like this:

/*** BeginHeader function1, function2, function3,
function4, function5 */
int function1();
void function2();
void function3();
void function4();
void function5();

extern int my_array[4];
/*** EndHeader function1, function2, function3,
function4, function5 */

int my_array[4];

I sure hope this helps someone else, I was stuck on this for more than an hour and my hope was dwindling!