I am porting an old vc++6.0 application to vs2005, I am getting the following linker error and I have spent days trying to find a solution.
error LNK2019: unresolved external symbol _imp_CreateAwnService@52 referenced in function "public: int __thiscall CMainFrame::CreateAsaNetworkServices(void)"
There is a 3rd party C library with the following API defined
extern "C"
{
DLLAPI IAwnServ * AWNAPI CreateAwnService(HINSTANCE hInst,
const char *pszDId, const char *pszDLoc,
AWN_DIQUAL DiQual, AWN_DOQUAL DoQual, int Prio,
const char *pszLicStr, const char *pszInfo,
AWN_REPEAT Repeat=R_LAST, TIME_T Since=0,
BOOL bLogin=FALSE, BOOL bDeb=FALSE);
DLLAPI IAwnSend * AWNAPI CreateAwnSend(const IAwnSend *pSend = NULL);
DLLAPI IAwnData * AWNAPI CreateAwnData(const char *pData = NULL, int iLen = 0);
DLLAPI IAwnHeader * AWNAPI CreateAwnHeader(const IAwnHeader *pHeader = NULL);
DLLAPI IAwnReference * AWNAPI CreateAwnReference(const IAwnReference *pRef = NULL);
DLLAPI IAwnFile * AWNAPI CreateAwnFile(const char *pFile = NULL);
DLLAPI IAwnOrder * AWNAPI CreateAwnOrder( const IAwnOrder *pOrder);
DLLAPI IAwnVehicle * AWNAPI CreateAwnVehicle( const IAwnVehicle *pVehicle);
DLLAPI int AWNAPI AwnCmp( const IAwnSend *pSend1, const IAwnSend *pSend2);
DLLAPI TIME_T AWNAPI AwnGetNetTime( const char *NetTime);
DLLAPI int AWNAPI AwnSetNetTime( char *NetTime, TIME_T Time);
DLLAPI TIME_T AWNAPI AwnMakeQueryTime( int MonthsBack);
DLLAPI struct tm *AWNAPI AwnSplitTime( TIME_T Time);
DLLAPI TIME_T AWNAPI AwnMakeTime( tm *ptm);
}
#endif
The call to the API is as follows:
m_pIAwnService = CreateAwnService( AfxGetApp()->m_hInstance, .........)
I have checked all links includes etc and I cant seem to find the error.
Any help is much appreciated.
Looks like you're missing the import library for the dll, or the linker cannot find it, in the Linker -> Input -> Additional dependancies
The library paths can be set in Linker -> General -> Additional Library Directories
It may be that the header files try to automatically include the lib file using a #pragma, so you should again check that the linker can find the file.
Another thing to check would be to look at the DLL using dependancy walker and make sure the function you are trying to use really is @52 for the stack cleanup size. Perhaps the sizes of variable types have changed between the compiler versions (for e.g. the typedefs).
Is DLLAPI macro defined to __declspec(dllimport)
when you build your application?
If you do miss import library for your DLL, take a look at this MSDN article: How To Create 32-bit Import Libraries Without .OBJs or Source. This way you can make a load-time dynamic linking of third-party DLL for which you do not have import library supplied.
来源:https://stackoverflow.com/questions/7318362/linker-error-lnk2019-from-3rd-party-library