MISC 001
back
Q.Error message "[LinkerError] Unresolved
external 'xxxx_xxxx __stdcall' referenced from xxxxxxxxxx ˇ§ with
Borland C++ Builder
Q: Error message "xxxx.obj : error LNK2001:
unresolved external symbol "xxxxxxxxxxx"(?xxxxx@@xxxxx)ˇ¨ with Microsoft Visual C++
ˇ@
Ans:
Code
will generate this error message if it references something (like
a function, variable, or label) that the linker can't find in all
the libraries and object files it searches. In general, there are
two reasons this error occurs:
1.
What the code asks for doesn't exist (the symbol is spelled incorrectly
or uses the wrong case)
2.
What the code asks for the wrong thing (the user using mixed versions
of the librariesˇXsome from one version of the product, others from
another version).
Otherwise, the naming conventions are different between C and C++,
because of C++ decoration of external
symbols. The different naming conventions may also cause
the error message occurs. By causing C++ to drop name decoration,
the extern "C" syntax makes it possible for a C++ module
to share data and routines with other languages.
The
most of the DLL files of our products are written in Microsoft Visual
C++ 4.0/5.0, and uses the C naming conventions. Thus, if the userˇ¦s
program is in C++ syntax, the header file must like followings:
#define EXPORTS extern "C" __declspec (dllimport)
EXPORTS WORD CALLBACK xxxxx_GetDriverVersion(WORD
*wDriverVersion);
These
declarations make the compiler to use the C naming conventions to
refer these functions.
The
user must not change the naming convention if the code is in C syntax.
Thus, the header file must like followings:
#define EXPORTS
EXPORTS WORD CALLBACK xxxxx_GetDriverVersion(WORD
*wDriverVersion);
A
few of the DLL files of our products are uses the C++ naming conventions
for some reasons. Thus, the userˇ¦s program must use the C++ syntax
and the user also must not change the naming conventions. Thus,
the header file must like followings:
#define EXPORTS
EXPORTS WORD CALLBACK xxxxx_GetDriverVersion(WORD
*wDriverVersion);
We
will unify the naming conventions of overall DLL files of our products
by C naming conventions to reduce these problems.
Note:
If the user uses the Microsoft Visual C++ for the development tools,
ensure to use the parameters -Tc or -TC makes the VC compiler with C syntax, and use the parameters -Tp or -TP makes the VC compiler with C++ syntax.
ˇ@
Written by David Chen
Date:2002/12/24 |