I used to work with Pelles C many years ago, just started using it again and I get these messages.
It's a X86 Console project.
I have several extren structures and variables in my include files and while building the project I get:
POLINK: error: Unresolved external symbol '_RomRec'.
POLINK: error: Unresolved external symbol '_ItemCnt'.
POLINK: error: Unresolved external symbol '_SaleRec'.
Complier tab the setting are:
Runtime Library: Single Threaded LIB
Calling Conv: __cdel
Optimizations: none
Inlining: Default
"Define compatibility names" is checked
Does anybody have an idea
Thanks,
Gillian
If it's an old project used to compile with previous versions the problem could be the C standard C11 (you'll find it under the compiler tab of project options) that requires explicit declaration of externals.
Another reason can be a library compiled with previous runtime version.
BTW it's better if you post a small sample exposing the problem.
This is the include file with all the extern vars
extern int TtlSale, StateCnt, UserCnt, aa,
ItemCnt, PromoteCnt;
extern char buf[BufSize+1];
I put it under inside "incdir" directory under the project's root directory.
This is the include definitions in one of the programs
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include "incdir\prg_literals.h"
# include "incdir\prg_extern_vars.h"
After building you can see these vars as unresolved.
POLINK: error: Unresolved external symbol '_ItemCnt'.
POLINK: error: Unresolved external symbol '_buf'.
POLINK: error: Unresolved external symbol '_TtlSale'.
POLINK: error: Unresolved external symbol '_UserCnt'.
I started a new X86 Console project called "test".
Complier settings are:
Runtime Library: Single Threaded LIB
Calling Conv: __cdel
Optimizations: maximum speed
Inlining: Default
C standard: C11
"Define compatibility names" is checked
It has one program - main.c and on include file - extern_vars.h
main.c
--------
# include <stdio.h>
# include <stdlib.h>
# include "extern_vars.h"
int main (void)
{
ItemCnt = 0;
}
extern_vars.h
------------------
extern int ItemCnt;
When building the project I get the same message:
Building main.obj.
Building test.exe.
POLINK: error: Unresolved external symbol '_ItemCnt'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
Is not enough to declare as external a variable, you have also instantiate them.
On old compilers the extern variables were created in the common section during linking. Actually new standard compliance don't accept undefined variables.
See the example attached. We have 3 files:
Main.h
#include <stdio.h>
#include "extern_vars.h"
int main(int argc, char *argv[])
{
printf("The variable ItemCnt contains %d\n", ItemCnt);
return 0;
}
The include file "extern_vars.h"
extern int ItemCnt; //Here we only declare it as extern
And "instantiate.c"
#include <stdio.h>
#include "extern_vars.h"
int ItemCnt = 10; //Here we instantiate the variable
You can instantiate the variable in only one of the source files (.c) where you use them.
Thanks a lot, that helped.
I also have an extern structure defined inside an include file, how do i instantiate it?
static struct Site
{
char Sign[10];
char Name[10];
char StateName[StateSize + 1];
char StateCode[StateCodeSize + 1];
char SiteURL[SiteUrlSize + 1];
};
extern struct Site SiteRec[10];
I think i've managed to instantiate the extern structure.
I wrote this line inside instantiate.c
struct Site SiteRec[10];
Thanks,
Gillian
I'm happy you solved.
You're welcome.