Reputation: 33
I was given the task to refactor a very old project, and in these current days i'm checking the dependencies of the executables because for some reasons, they changed since 2009, passing from 4 to 14. To be more specific, my job is to keep the dependencies as they were before 2009, but with the changes to the code occuring until today.
I tracked down the instruction that was causing the trouble. It'a function inside a library used by the project:
chain(str, pps)
char *pps;
char *str;
{
int pp = 0;
pp = atoi(pps);
// ic sunt leones.
If i comment or replace atoi with an assignment of an integer like 0, 1 or 3, the library compile fine, but the executable that is using this .lib gives me these errors:
nafxcw.lib(wincore.obj) : error LNK2001: unresolved external symbol __imp__InitCommonControls@0 nafxcw.lib(wincore.obj) : error LNK2001: unresolved external symbol __imp__DragAcceptFiles@8 nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol _ClosePrinter@4 nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol _DocumentPropertiesA@24 nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol _OpenPrinterA@12 nafxcw.lib(filecore.obj) : error LNK2001: unresolved external symbol __imp__SHGetFileInfoA@20 nafxcw.lib(filecore.obj) : error LNK2001: unresolved external symbol _GetFileTitleA@12
If otherwise i use a different value for the assignment, like 2, 4 or every other integer, everything compile correctly and work.
Any advice? What's happening here? Why this strange behaviour?
EDIT: apparently the problem is not the atoi. If i use an home made function that do anything and accept a char* and return an int or replacing directly the second parameter of the function chain with an int and assigning it directly i still receive the same errors.
Upvotes: 1
Views: 584
Reputation: 52659
the only thing I can think of is that the simplified function is being compiled out of existence, and the linker is then helpfully assuming that there is no code to link with in the library, and so it is being dropped, unfortunately it being the only thing that is forcing includes of those MFC libraries.
I have no idea why its even requiring stuff like OpenPinter - which is included in winspool.h (via windows.h) except to say that it sounds like you have a nasty MFC-based mess to sort out. It was never much good WRT tidy builds due to its dependence on specific includes specified in specific order.
Upvotes: 0
Reputation: 1321
You can try this :
include ('limits.h');
int my_getnbr(char *str)
{
int i;
long nbr;
int neg;
neg = 0;
nbr = 0;
i = 0;
if (str[0] == '-')
{
neg = 1;
str++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nbr = nbr * 10 + (str[i++] - '0');
if (nbr > INT_MAX)
return (0);
}
return (neg ? (int)nbr * -1 : (int)nbr);
}
It's just a home made atoi like.
Edit : INT_MAX by Alter Mann. Edit bis : if (nbr > INT_MAX) by Alter Mann again :)
Upvotes: 1