-
July 10th, 2013, 04:59 PM
#1
LNK1120 error - VS2012 project using a VS2010 DLL
I have a third party DLL compiled with vc10 (VS2010).
It exports the following function:
Code:
bool myDLL_EXPORTS_API myFunction(std::vector<int>::const_iterator c)
{
return true;
}
My exe uses this DLL. I am trying to compile my exe with vc11 (vs2012).
Code:
#include "stdafx.h"
#include <vector>
#include "myDll_VC10\myDll_VC10.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int>::const_iterator c;
myFunction(c);
return 0;
}
I get the following linker error:
1>usingDLLvc10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl myFunction(class std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<int> > >)" (__imp_?myFunction@@YA_NV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@H@std@@@std@@@std@@@Z) referenced in function _wmain
1>C:\Work\Training\vectorReproduceBug\usingDLLvc10\Debug\usingDLLvc10.exe : fatal error LNK1120: 1 unresolved externals
Note: This code compiles and links if my exe is compiled with vc10 (VS2010).
How do I fix this linker error without the third party library compiled with vc11 (VS2012)?
-
July 11th, 2013, 01:46 AM
#2
Re: LNK1120 error - VS2012 project using a VS2010 DLL
Originally Posted by vincentB
Note: This code compiles and links if my exe is compiled with vc10 (VS2010).
How do I fix this linker error without the third party library compiled with vc11 (VS2012)?
Probably the ABI of std::vector has changed between vc10 and vc11. In that case, this isn't going to work with that function signature. You'll have to export the function using C calling convention. This can easily be done by converting the argument to a const int*.
Code:
extern "C" {
bool myDLL_EXPORTS_API myFunction(const int* c);
}
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
July 11th, 2013, 07:06 AM
#3
Re: LNK1120 error - VS2012 project using a VS2010 DLL
You cannot in any reliable form shape or way export functions from one DLL using template classes ...
and use those functions in a exe/dll compiled with a different version/brand of compiler.
if you want to use a lib/dll compiled with a different brand of compiler/linker/runtimelibrary, then this can only be done if that dll only exports stuff that does not rely on compiler/linker/runtime dependencies.
And an often overlooked one here is... if the 2 dll's (exe) aren't built as a unit and using the same runtime, then you can't even reliably new in the dll and delete in the other dll (exe) or vice versa. So you need to be careful with passing pointers from one dll to the other.
-
July 11th, 2013, 10:07 AM
#4
Re: LNK1120 error - VS2012 project using a VS2010 DLL
Originally Posted by vincentB
I have a third party DLL compiled with vc10 (VS2010).
It exports the following function:
Code:
bool myDLL_EXPORTS_API myFunction(std::vector<int>::const_iterator c)
To add to what others have mentioned:
A third-party DLL author would never write a prototype that uses proprietary classes such as std::vector. Even 'C' types such as FILE can't be passed between DLL and executable if they are built with different compilers and compiler options.
So whomever created this DLL either did not intend it to be "third-party" (i.e. it is actually part of a larger application, where the DLL is tied to this app), or they have specific instructions on where and how this DLL can be used. A bonafide third-party DLL would use the Windows types such as LONG, BOOL, LPCTSTR, etc. as parameters.
How do I fix this linker error without the third party library compiled with vc11 (VS2012)?[/B]
What if the internals of the vector class has changed between version VC10 and VC11? What magic are you going to use to make the two totally different vector classes compatible with each other?
So there is no way to fix the error unless you use the same compiler that built the DLL. The DLL can obviously only be used for the compiler it was built for. Not only that, the compiler options have to be the same for the both the building of the DLL and the application. Also, the DLL and app have to use the same heap and runtime.
Regards,
Paul McKenzie
-
July 11th, 2013, 10:48 AM
#5
Re: LNK1120 error - VS2012 project using a VS2010 DLL
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|