J
Jaco Naude
Hi,
I'm using a static library in my application which links fine except
for a few global variables. The static library only contains a bunch
of .cpp and .h files and the global variables are defined as follows:
extern unsigned mgl_numg, mgl_cur;
extern float mgl_fact;
extern long mgl_gen_fnt[516][6];
extern short mgl_buf_fnt[246080];
const float mgl_fgen = 4*14;
extern mglTeXsymb mgl_tex_symb[];
This gives the following linker errors:
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"short * mgl_buf_fnt" (?mgl_buf_fnt@@3PAFA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"float mgl_fact" (?mgl_fact@@3MA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"struct mglTeXsymb * mgl_tex_symb" (?mgl_tex_symb@@3PAUmglTeXsymb@@A)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"long (* mgl_gen_fnt)[6]" (?mgl_gen_fnt@@3PAY05JA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"unsigned int mgl_cur" (?mgl_cur@@3IA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"unsigned int mgl_numg" (?mgl_numg@@3IA)
When I remove the extern keywords the linker errors are gone, except
for the mgl_tex_symb[] variable. Removing the extern keyword are not
an acceptable solution though since these variables are used by
another .cpp file in the library.
Is there something special about linking to global variables in a
static library? Should they be defined in the header which is included
in the main program as well? The library is a third party library so I
do not really want to start changing things in it, hopefully this can
be avoided by doing something in the header.
My environment is Visual Studio 2008 and both the application and
library is compiled with it.
Thanks
Jaco
I'm using a static library in my application which links fine except
for a few global variables. The static library only contains a bunch
of .cpp and .h files and the global variables are defined as follows:
extern unsigned mgl_numg, mgl_cur;
extern float mgl_fact;
extern long mgl_gen_fnt[516][6];
extern short mgl_buf_fnt[246080];
const float mgl_fgen = 4*14;
extern mglTeXsymb mgl_tex_symb[];
This gives the following linker errors:
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"short * mgl_buf_fnt" (?mgl_buf_fnt@@3PAFA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"float mgl_fact" (?mgl_fact@@3MA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"struct mglTeXsymb * mgl_tex_symb" (?mgl_tex_symb@@3PAUmglTeXsymb@@A)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"long (* mgl_gen_fnt)[6]" (?mgl_gen_fnt@@3PAY05JA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"unsigned int mgl_cur" (?mgl_cur@@3IA)
1>mathgl.lib(mgl_font.obj) : error LNK2001: unresolved external symbol
"unsigned int mgl_numg" (?mgl_numg@@3IA)
When I remove the extern keywords the linker errors are gone, except
for the mgl_tex_symb[] variable. Removing the extern keyword are not
an acceptable solution though since these variables are used by
another .cpp file in the library.
Is there something special about linking to global variables in a
static library? Should they be defined in the header which is included
in the main program as well? The library is a third party library so I
do not really want to start changing things in it, hopefully this can
be avoided by doing something in the header.
My environment is Visual Studio 2008 and both the application and
library is compiled with it.
Thanks
Jaco