unresolved external symbol/using an external dll

S

Scott Allen

Hello,

I'm new to C++ development and I'm trying out figure out the cause of
an 'unresolved external symbol' error that I'm receiving when
compiling. Here is some history on what I'm doing:

I have an existing VC++ project that mostly just reads a SQL Server
database does some work on the data and insert the results into
another table. I have the need to incorproate some functionality from
a certain dll named cedb300.dll. cedb300.dll is an unsupported
Microsoft dll that allows the reading and writing of Windows CE
databases to a disk (as opposed to an actual device). I have a list of
function signatures that are externally available from this dll.

I only have access to the dll, so I used a program called 'DLL to Lib'
(http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
file from the dll. This appeared to be successful. I copied both the
cedb300.dll and cedb300.lib files into my VC++ project directory and
added cedb300.lib to 'Projects->Settings->Link->Object/library
modules'

I add a call in my VC++ project to one of the functions in
cedb300.dll, but when I try to compile I get a 'unresolved external
symbol' error message. Naturally, removing the call to the function
causes the error to go away and my app compiles.

So, being new to VC++, I'm not sure if there's some more code I need
to add to my source to allow me to call functions from an external
dll, or if VC++ is simply not able to access the .lib files or if the
lib file is corrupted, or all of the above.

Is there something else I need to add to my code/project to allow me
to call functions from an external dll? Or is there another tool
someone can recommend to create a lib from a dll?

Thanks very much,
-Scott
 
C

Carl Daniel [VC++ MVP]

I suspect that you have a calling convention problem. The linker of course
tells you the complete name of the undefined symbol, what you need to do is
dumpbin /exports on the DLL (or dumpbin /symbols on the lib) and find the
name in the library that you think should match the undefined external.
Once you have those names, post back with both names and someone can figure
out what's wrong (it's probably something like lack of __stdcall on your
function prototypes).

-cd
 
K

Karthik

Scott said:
Hello,

I'm new to C++ development and I'm trying out figure out the cause of
an 'unresolved external symbol' error that I'm receiving when
compiling. Here is some history on what I'm doing:

I have an existing VC++ project that mostly just reads a SQL Server
database does some work on the data and insert the results into
another table. I have the need to incorproate some functionality from
a certain dll named cedb300.dll. cedb300.dll is an unsupported
Microsoft dll that allows the reading and writing of Windows CE
databases to a disk (as opposed to an actual device). I have a list of
function signatures that are externally available from this dll.

I only have access to the dll, so I used a program called 'DLL to Lib'
(http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
file from the dll. This appeared to be successful. I copied both the
cedb300.dll and cedb300.lib files into my VC++ project directory and
added cedb300.lib to 'Projects->Settings->Link->Object/library
modules'

I add a call in my VC++ project to one of the functions in
cedb300.dll, but when I try to compile I get a 'unresolved external
symbol' error message. Naturally, removing the call to the function
causes the error to go away and my app compiles.

So, being new to VC++, I'm not sure if there's some more code I need
to add to my source to allow me to call functions from an external
dll, or if VC++ is simply not able to access the .lib files or if the
lib file is corrupted, or all of the above.
Check out project options to the lib file that you are using.
Also make sure that you pass the relevant /libpath switch option with
the directory so that the linker can locate the lib file for linking.

HTH
 
M

Michael J. Salamone [eMVP]

Actually Windows CE only has cdecl calling convention.

Use dumpbin /exports on the library file. And then dumpbin /relocations on
the .obj file that calls the function.

Most likely you need to have the functions declared with extern "C". You
probably have a problem with name mangling. If so, you would see mangled
names when you dumpbin the .obj file.

--

Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
 
C

Carl Daniel [VC++ MVP]

Michael said:
Actually Windows CE only has cdecl calling convention.

I got the impression that the OP is using code to read a CE database outside
WinCE. The presence or absense of extern "C" may very well be the problem
as well - good point.

-cd
 
S

Scott Allen

Thanks for your responses. I found a link on the web that suggested
adding 'extern "C"' to the beginning of the function definitions in my
header file (a windows ce header named WINDBASE.H). This seemed to
solve my problem. I'm now able to compile and access the functions in
the lib file from within my application. Some functions throw a
runtime error, but I think that can be fixed.

The thing I'm confused about is that it seems that I should be able to
use just 'extern' instead of 'extern "C"'... the fact that the
function come from a C/C++ library should be the default, right?

Thanks, -Scott
 
M

Michael J. Salamone [eMVP]

You're right - I didn't read closely enough.

So, it's one of the two - the calling convention or the name mangling.
Dumpbin will shed light.

If you see _ and something like @8 at the end of a name, it's stdcall,
otherwise cdecl. If it's name mangling, you'll know it when you see it -
lot's of extra characters in front and in back of the name. And, it just
might be both. You'll have to adjust the declarations in your header file
appropriately.

--

Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
 
J

John Harrison

Scott Allen said:
Thanks for your responses. I found a link on the web that suggested
adding 'extern "C"' to the beginning of the function definitions in my
header file (a windows ce header named WINDBASE.H). This seemed to
solve my problem. I'm now able to compile and access the functions in
the lib file from within my application. Some functions throw a
runtime error, but I think that can be fixed.

The thing I'm confused about is that it seems that I should be able to
use just 'extern' instead of 'extern "C"'... the fact that the
function come from a C/C++ library should be the default, right?

Thanks, -Scott

There is no language called C/C++, AFAIK its an invention of job recruitment
agencies. In reality C and C++ are two different languages and C++ typically
needs to be told that an external function has been compiled as C.

john
 
S

Scott Allen

Thanks everyone!

John Harrison said:
There is no language called C/C++, AFAIK its an invention of job recruitment
agencies. In reality C and C++ are two different languages and C++ typically
needs to be told that an external function has been compiled as C.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top