Unresolved Externals errors when using external .lib file

R

robintw

Hi all,

I'm trying to use some functions which are in an external library file called qhdlc.lib from within my C++ .Net program. I have a header file for this library (qhdlc.h) and have set the library as an "additional dependency" in Project Properties->Linker->Input. Even though I have done all of that, I still get unresolved token errors for every function in the library.

Sadly, I do not have access to the source code for the library - but need to access it from my C++ .Net program. The library is written in ANSI C, and works fine when used from a program written in ANSI C and compiled with an ANSI C compiler.

I have no idea what to check next. I have some books on C++ .Net, but they don't seem to have any help, and I haven't been able to find anthing using Google.

Anyone got any ideas?

Robin
 
W

William DePalo [MVP VC++]

I'm trying to use some functions which are in an external library file
called qhdlc.lib from within my C++ .Net program. I have a header file for
this library (qhdlc.h) and have set the library as an "additional
dependency" in Project Properties->Linker->Input. Even though I have done
all of that, I still get unresolved token errors for every function in the
library.

Sadly, I do not have access to the source code for the library - but need
to access it from my C++ .Net program. The library is written in ANSI C,
and works fine when used from a program written in ANSI C and compiled
with an ANSI C compiler.

I have no idea what to check next. I have some books on C++ .Net, but they
don't seem to have any help, and I haven't been able to find anthing using
Google.

Anyone got any ideas?

It could be a problem of C++ name decoration, aka name mangling

At the top of the header for the library written in C add this (or create a
new header from the old with the modifications)

#ifdef __cplusplus
extern "C" {
#endif

and at the bottom add this

#ifdef __cplusplus
extern }
#endif

And rebuild the entire project.

Regards,
Will
 
R

robintw

Hi,

Thanks for the response. I've tried doing that and the unresolved externals errors have disappeared (hooray!) but there is a new fatal linker error:

LNK1104: cannot open file "libc.lib"

Any ideas what I should do? I've searched my whole project, and nowhere does it seem to reference libc.lib (obviously I can't check in the lib file because it is compiled and I do not have access to the source code).

Robin
 
W

William DePalo [MVP VC++]

Thanks for the response.

You are welcome.
I've tried doing that and the unresolved externals errors
have disappeared (hooray!) but there is a new fatal linker
error:

LNK1104: cannot open file "libc.lib"

I see.
Any ideas what I should do? I've searched my whole project,
and nowhere does it seem to reference libc.lib (obviously I
can't check in the lib file because it is compiled and I do not
have access to the source code).

I think that this means that the static library that you need specifies a
version of the runtime different from the one that you are using in the rest
of the project.

Try this: Go to the Linker Settings in your project's configuration. Choose
Input. In the text box labeled "Ignore Specific Library" enter

libc.lib

Relink.

Regards,
Will
 
R

robintw

Hi,

Thanks for the suggestion. I have tried that and now get the following linker errors:

LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _DigiLogicalOpen

LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _DigiLogicalOpen

LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _DigiLogicalOpen

I am pretty sure that the function DigiLogicalOpen is in the qhdlc.lib file - but is not one of the publically accessible functions from that file.

You say that maybe the library was compiled using a different version of the library - well, as far as I know, the library was compiled with a standard ANSI C compiler, not using anything .Net related at all.

Hope that helps, and thanks for the help,

Robin
 
C

Carl Daniel [VC++ MVP]

robintw said:
Hi,

Thanks for the suggestion. I have tried that and now get the
following linker errors:

LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced
in function _DigiLogicalOpen

LNK2019: unresolved external symbol __imp__RegQueryValueExA@24
referenced in function _DigiLogicalOpen

LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20
referenced in function _DigiLogicalOpen

I am pretty sure that the function DigiLogicalOpen is in the
qhdlc.lib file - but is not one of the publically accessible
functions from that file.

You say that maybe the library was compiled using a different version
of the library - well, as far as I know, the library was compiled
with a standard ANSI C compiler, not using anything .Net related at
all.

I looks like you need to add ADVAPI32.LIB to your linker inputs. That's
where RegCloseKey et al are decalred.

-cd
 
W

William DePalo [MVP VC++]

I am pretty sure that the function DigiLogicalOpen is in
the qhdlc.lib file - but is not one of the publically accessible
functions from that file.

Carl's suggestion is likely to get you over the last hurdle.
You say that maybe the library was compiled using a different
version of the library - well, as far as I know, the library was
compiled with a standard ANSI C compiler, not using anything
.Net related at all.

Well, there is not a single version of the library. There are several of
them. They differ as to whether they are implemented in a DLL or not,
whether they support multithreading or not, whether they have debug
information or not, etc.

The authors of your static library preferred one runtime, your project
requires another. I helped you tell the linker to ignore the static
library's preferred runtime.
... and thanks for the help,

You are welcome.

Regards,
Will
 

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

Top