C++ linkage errors

Last Edited By Krjb Donovan
Last Updated: Mar 11, 2014 07:51 PM GMT

Contents

Question

Hello Vijayan,

I am new to c++ and I am trying to compile a program thats already available. But, while doing so, I come across this particular error.

====*********ERROR*********=====

1>ADD1.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct SOUTPUTS * sout" (__imp_?sout@@3PAUSOUTPUTS@@A) 1>ADD1.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) short __cdecl hspflash(float * const,double,double,short,double,float * const,float * const,float *,float *,float *,float *,float *,float *,float * const,float *,float * const)" (__imp_?hspflash@@YAFQAMNNFN00PAM11111010@Z) referenced in function "void __cdecl add1(void)" (?add1@@YAXXZ) 1>ADD1.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct SINPUTS * sinp" (__imp_?sinp@@3PAUSINPUTS@@A) 1>ADD1.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) short nsin" (__imp_?nsin@@3FA) 1>ADD1.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) short nc" (__imp_?nc@@3FA) 1>ADDK.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) short nc" (__imp_?nc@@3FA) 1>ADDK.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) float __cdecl vp(short,double)" (__imp_?vp@@YAMFN@Z) referenced in function "void __cdecl addk(float *,float *,double,double,float *)" (?addk@@YAXPAM0NN0@Z) 1>c:\documents and settings\andy patrachari\my documents\visual studio 2010\Projects\usradd\Debug\usradd.dll : fatal error LNK1120: 6 unresolved externals

======================

I have absolutely no idea what this error mean. I thought that the objects mentioned in the error messages have not been defined and I checked the header files in the project. The objects mentioned in the file were defined as EXTERN in the header file. I am unable to proceed in my work. Any suggestions and ideas will be appreciated.

Thanks,

Andy

Answer

Yes, you do have the header file (.h file) containing the declarations of the exported functions from the dll.

You also need to link with the import library (typically this has a .lib extension). If the dll that you are trying to use is called abcd.dll, specify the import library abcd.lib as a library to link with. The import library is created when the DLL is built, and if it is a third-party dll, would be part of the distribution. If you are using Visual Studio or Visual C++ Express, you can just add the import library to your project.

Once the executable is created, to run it operating system must be able to locate the DLL file. The simplest way to do this is to add the directory containing the dll to your PATH environment variable (or copy the dll file to one of the directories that is searched to locate dlls).

For more information, see: http://msdn.microsoft.com/en-us/library/d14wsce5.aspx

Advertisement

©2021 eLuminary LLC. All rights reserved.