Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Typical problem linking DLL 1

Status
Not open for further replies.

shinosuke

Programmer
Feb 14, 2003
2
ES
Hello
I need help with this.
I build a DLL with MS Visual c++ 6. The library exports a function in this way: _declspec(dllexport) _stdcall int f(int a,char **b);
Let's call the DLL A.DLL.
The DLL compiles correctly, and with the DUMPBIN utility I see it is exporting function f.
Now, I'm programming an example aplication that imports this function and calls it. I create a project, and add the
A.LIB library to Project->settings->Link->Libraries, and the directory where it is to Proj->Settings->Links->Input->Additional Library Path.
The program is as simple as this:

_declspec(dllimport) int _stdcall f(int argc,char**argv);

int main(int argc, char* argv[])
{
f(argc,argv);
return 0;
}

I keep getting this error:
error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall f(int,char * *)" (__imp_?f@@YGHHPAPAD@Z)
I've tried to change the calling convention to _cdecl, to create a a.def file to export the function with other name, to copy the libraries to the new project directory, to add the a.dll instead of a.lib to the import libraries(then I get a: "fatal error LNK1136: invalid or corrupt file"), to add the lib and dll files to the project directly(in Add Files to Project), and different combinations of this changes. Also tried creating a new project from scratch, still getting the same problem.


 
While you compille a dll, VisualC++ generate usually a .lib file. Any of projects you want to use this dll, you should link them with this .lib file. Ion Filipski
1c.bmp


filipski@excite.com
 
try putting extern "C" in the below ,
_declspec(dllimport) int _stdcall f(int argc,char**argv);

so, as to see if you have any isues with the "C" and "C++" functions

(or) in your def , you could simply call
_declspec(dllimport) int f(int argc,char**argv);
_declspec(dllimport) extern "C" int f(int argc,char**argv);


hope this helps

 
That worked, thanks, though I had to put it this way, extern "C" must precede the declaration:

extern "C" _declspec(dllimport) int _stdcall f(int argc,char**argv)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top