0

I'm having a problem with a pesky linker error and would appreciate tips to find a resolution.

The way I understand the error, the linker is having trouble finding the implementation for the function named 'read' in class 'BFStream'. The code includes a header for the class BFStream. There is an import library QRFound.lib which receives exported functions from QRFound.dll. The dll and the lib are both in the lib directory on the file system. The lib directory is provided in the project properties in two locations: VC++ Directories->Library Directories and Linker->Additional Library Directories. The QRFound.lib is specified in Linker->Input->Additional Dependencies and is first in the list.

I know that QRFound.dll contains the implementation for BFStream::read because I used dependency walker to view it. But the C++ decorations are slightly different from the linker error which has me suspicious: ?read@BFStream@@QAE_NPADH@Z

The linker error is:

1>     Creating library C:\MyProj\Debug\MyDisplay.lib and object C:\MyProj\Debug\MyDisplay.exp
1>MyCmdReceiver.obj : error LNK2001: unresolved external symbol "public: bool __thiscall BFStream::read(char *,__int64)" (?read@BFStream@@QAE_NPAD_J@Z)
kevincw01
  • 69
  • 2
  • 8
  • 1
    What is the provenance of QRFound.dll? It might be that it was built with a different C++ compiler, and in general, exporting C++ interfaces from DLLs is a terrible idea: stick to C interfaces or use COM instead. – richard.albury Jun 13 '12 at 14:36

2 Answers2

3

Running the undname.exe utility on your symbol produces:

Undecoration of :- "?read@BFStream@@QAE_NPADH@Z"
is :- "public: bool __thiscall BFStream::read(char *,int)"

So, yes, clearly a mismatch on the last argument, __int64 doesn't match int. You didn't post the actual declaration of the method so I can't come up with a decent guess how this mismatch occurred. I suspect it is some kind of macro soup problem.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • looks like streamsize is defeined in iosfwd, a VS header as `typedef _Longlong streamsize;` So I'm guessing I need to specify 32-bit somewhere since I'm on a 32-bit platform. Not sure where that would go... – kevincw01 Jun 13 '12 at 16:00
  • So _Longlong is defined to _LONGLONG which is defined as __int64 in yvals.h (also a VS header). Still looking for the property to change this to 32-bit – kevincw01 Jun 13 '12 at 16:04
  • can I do that without the dll source? – kevincw01 Jun 13 '12 at 16:11
  • I found an msdn article that suggests that vs2010 thinks my platform is 64-bit which is why it's defining streamsize as __int64 instead of int. http://msdn.microsoft.com/en-us/library/11zy8h28.aspx – kevincw01 Jun 13 '12 at 16:17
  • So since I cannot recompile the dll, I changed the second parameter function definition of the header to int from streamsize and it linked successfully. – kevincw01 Jun 13 '12 at 18:53
0

I suspect you're calling a DLL built with a different compiler.

If you have the source to the DLL, build it with your current compiler: the name mangling will be consistent and you should be able to resolve the issue.

If you don't have the source to the DLL, see if it has a COM interface.

richard.albury
  • 177
  • 1
  • 4