Frustrating LNK2001 issue with VC++ 6.0

W

walkerfx

Hi Everyone,

I have been trying resolve this issue for many hours and am not making
any progress. I have a DLL that I'm updating with some new 3rd party
libraries. However, there appears to be a conflict causing the
following link errors:
------------
error LNK2001: unresolved external symbol "void __cdecl operator
delete[](void *)" (??_V@YAXPAX@Z)
error LNK2001: unresolved external symbol __ftol2
error LNK2001: unresolved external symbol "void * __cdecl operator
new[](unsigned int)" (??_U@YAPAXI@Z)
-------------
And that's it, there are no other errors.

Generally it is my understanding that when there is an unresolved
external symbol, it simply means that I'm missing a .lib from my
project settings. In this case, I would think that adding msvcrt.lib
to the project would fix it, but it does not. I tried compiling this
both with and without default libraries with the same result.

To troubleshoot this problem I reduced my project to a very simple
example, which compiled fine. I then began adding back in my source
code one bit at a time until the problem cropped up again, but I still
have not been able to figure out exactly where it is coming from.

Any ideas?

Thanks in advance for any help!
 
T

Tom Widmer [VC++ MVP]

walkerfx said:
Hi Everyone,

I have been trying resolve this issue for many hours and am not making
any progress. I have a DLL that I'm updating with some new 3rd party
libraries. However, there appears to be a conflict causing the
following link errors:
------------
error LNK2001: unresolved external symbol "void __cdecl operator
delete[](void *)" (??_V@YAXPAX@Z)
error LNK2001: unresolved external symbol __ftol2
error LNK2001: unresolved external symbol "void * __cdecl operator
new[](unsigned int)" (??_U@YAPAXI@Z)
-------------
And that's it, there are no other errors.

Generally it is my understanding that when there is an unresolved
external symbol, it simply means that I'm missing a .lib from my
project settings.

It can mean you have the wrong .lib file (e.g. a different, incompatible
version), rather than a missing one.

In this case, I would think that adding msvcrt.lib
to the project would fix it, but it does not. I tried compiling this
both with and without default libraries with the same result.

To troubleshoot this problem I reduced my project to a very simple
example, which compiled fine. I then began adding back in my source
code one bit at a time until the problem cropped up again, but I still
have not been able to figure out exactly where it is coming from.

Any ideas?

Try changing the runtime library setting under
Project->Settings->C/C++->Code Generation (IIRC). The setting must match
that which the lib file was generated against.

Generally, you should not need to use the no default libraries setting.
Instead, you just need to make sure that the library settings match. See
also here:
http://msdn2.microsoft.com/en-us/library/f6xx1b1z(vs.71).aspx

Tom
 
W

walkerfx

walkerfx said:
Hi Everyone,
I have been trying resolve this issue for many hours and am not making
any progress. I have a DLL that I'm updating with some new 3rd party
libraries. However, there appears to be a conflict causing the
following link errors:
------------
error LNK2001: unresolved external symbol "void __cdecl operator
delete[](void *)" (??_V@YAXPAX@Z)
error LNK2001: unresolved external symbol __ftol2
error LNK2001: unresolved external symbol "void * __cdecl operator
new[](unsigned int)" (??_U@YAPAXI@Z)
Generally it is my understanding that when there is an unresolved
external symbol, it simply means that I'm missing a .lib from my
project settings.

It can mean you have the wrong .lib file (e.g. a different, incompatible
version), rather than a missing one.

In this case, I would think that adding msvcrt.lib
to the project would fix it, but it does not. I tried compiling this
both with and without default libraries with the same result.
To troubleshoot this problem I reduced my project to a very simple
example, which compiled fine. I then began adding back in my source
code one bit at a time until the problem cropped up again, but I still
have not been able to figure out exactly where it is coming from.
Any ideas?

Try changing the runtime library setting under
Project->Settings->C/C++->Code Generation (IIRC). The setting must match
that which the lib file was generated against.

Generally, you should not need to use the no default libraries setting.
Instead, you just need to make sure that the library settings match. See
also here:http://msdn2.microsoft.com/en-us/library/f6xx1b1z(vs.71).aspx

Tom

Thank you Tom, that is helpful information. I was finally able to
isolate the problem. It comes down to code that calls a static member
method of a class from a 3rd party library. It looks like this:
class::method(&id);

If I comment out the line, the link errors go away. I'm not sure how
to fix it though.

I have looked at my Code Generation settings as you suggested and they
are set the same as the example projects which build fine
(multithreaded DLL). I tried some different settings but they result
in another set of link errors. I have read through the LNK2001 page
you sent but it does not give any insight into static class methods,
only C style static variables and functions.
 
M

Masterchief

Have you also linked the third party lib?
What you describe is exactly the error you get when you use a function from
another lib and don´t link it.

Ronny

walkerfx said:
walkerfx said:
Hi Everyone,
I have been trying resolve this issue for many hours and am not making
any progress. I have a DLL that I'm updating with some new 3rd party
libraries. However, there appears to be a conflict causing the
following link errors:
------------
error LNK2001: unresolved external symbol "void __cdecl operator
delete[](void *)" (??_V@YAXPAX@Z)
error LNK2001: unresolved external symbol __ftol2
error LNK2001: unresolved external symbol "void * __cdecl operator
new[](unsigned int)" (??_U@YAPAXI@Z)
Generally it is my understanding that when there is an unresolved
external symbol, it simply means that I'm missing a .lib from my
project settings.

It can mean you have the wrong .lib file (e.g. a different, incompatible
version), rather than a missing one.

In this case, I would think that adding msvcrt.lib
to the project would fix it, but it does not. I tried compiling this
both with and without default libraries with the same result.
To troubleshoot this problem I reduced my project to a very simple
example, which compiled fine. I then began adding back in my source
code one bit at a time until the problem cropped up again, but I still
have not been able to figure out exactly where it is coming from.
Any ideas?

Try changing the runtime library setting under
Project->Settings->C/C++->Code Generation (IIRC). The setting must match
that which the lib file was generated against.

Generally, you should not need to use the no default libraries setting.
Instead, you just need to make sure that the library settings match. See
also here:http://msdn2.microsoft.com/en-us/library/f6xx1b1z(vs.71).aspx

Tom

Thank you Tom, that is helpful information. I was finally able to
isolate the problem. It comes down to code that calls a static member
method of a class from a 3rd party library. It looks like this:
class::method(&id);

If I comment out the line, the link errors go away. I'm not sure how
to fix it though.

I have looked at my Code Generation settings as you suggested and they
are set the same as the example projects which build fine
(multithreaded DLL). I tried some different settings but they result
in another set of link errors. I have read through the LNK2001 page
you sent but it does not give any insight into static class methods,
only C style static variables and functions.
 
T

Tom Widmer [VC++ MVP]

I've just noticed, that is a VC7 function, not a VC6 one, I think! You
need to get a version of the 3rd party library for VC6 - you've got the
VC7 version.

If there isn't one, you could try adding this code to a .cpp:

extern "C" long _ftol( double ); //defined by VC6 C libs
extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource );}

That leaves the new[]/delete[] errors. To fix those, you could try
adding a call to new[] and delete[] to your code, if you don't already
have any.

Tom
 
W

walkerfx

I've just noticed, that is a VC7 function, not a VC6 one, I think! You
need to get a version of the 3rd party library for VC6 - you've got the
VC7 version.

If there isn't one, you could try adding this code to a .cpp:

extern "C" long _ftol( double ); //defined by VC6 C libs
extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource );}

That leaves the new[]/delete[] errors. To fix those, you could try
adding a call to new[] and delete[] to your code, if you don't already
have any.

Tom

Yes, I believe you are right. I had read a discussion on another list
about the _ftol function with the same conclusion, doing a manual
'reroute' as you suggest.

The documentation for the libraries says that they can be used in
either VC6 or 7, though perhaps this is an oversight or nuance in VC6.
I have contacted the developers to get their help. At this point, I
can omit the code in question and move on and come back to it later.
Hopefully they have some idea of what is wrong.

Thanks for all your help!
 
W

walkerfx

Have you also linked the third party lib?
What you describe is exactly the error you get when you use a function from
another lib and don´t link it.

Ronny

Thanks Ronny. I went and checked again just to make sure. There are
only two 3rd party libraries to use and I have them both. Well there
is also a third MFC-flavored lib, but I am not using MFC and building
with that version doesn't make a difference.

I have never built a lib that exports C++ static methods, so I'm not
sure how they differ from plain C functions. It seems somewhat
arbitrary or at least esoteric that the link error is with __cdecl new
and delete caused by using a class that has nothing but static methods
in it. It's at least showing me an area I have some things to learn
about ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top