Board index » cppbuilder » Problem linking 3rd party package

Problem linking 3rd party package


2006-03-11 02:49:59 AM
cppbuilder18
Hello everybody,
I'm trying to use Aducom's TSQLite components with BCB 2006. I managed
to install the statically linked version (i.e., one that does not use
the sqlite dll but links the objects statically to it) without a
problem, and the design package works as expected.
When I try to create a simple app, however, I get the following linker
error:
[Linker Error] Error: Unresolved external 'wsprintfA' referenced from
C:\BDSPROJECTS\SQLITE\ASQLITE3.LIB|ASGSQLite3
The ASGSQLite3.pas file has the following line:
function _wsprintfA:integer; external 'user32.dll' name 'wsprintfA';
I'm pretty sure this is one of those underscore (or lack of) linking
issues, but I have no idea on how to deal with it in this case, where
the offending part comes from a Pascal source file.
Any help will be greatly appreciated,
--
Ken
 
 

Re:Problem linking 3rd party package

Craig Farrell wrote:
Quote
Hi,

>
>The ASGSQLite3.pas file has the following line:
>
>function _wsprintfA:integer; external 'user32.dll' name 'wsprintfA';
>

Is it winsock? You might have to add a lib like wsock32.lib to the
project (or soemthing like that).
Nope. It's a 3rd party SQL database. I tried explicitly linking
user32.lib from the SDK, to no avail.
I think I have to include an extern __cdecl wsprintfA() somewhere in
the C source code, I guess.
--
Ken
 

Re:Problem linking 3rd party package

Hi,
Quote

The ASGSQLite3.pas file has the following line:

function _wsprintfA:integer; external 'user32.dll' name 'wsprintfA';

Is it winsock? You might have to add a lib like wsock32.lib to the
project (or soemthing like that).
--Craig
 

{smallsort}

Re:Problem linking 3rd party package

Hi,
Quote
>>The ASGSQLite3.pas file has the following line:
>>
>>function _wsprintfA:integer; external 'user32.dll' name 'wsprintfA';
>>
That is odd; why they added the external symbol reference to the .pas
with an underscore, and odder, that the error has no underscore.
A couple of ideas:
You can look in ..\source\win32\rtl\win\Windows.pas to see how
the VCL adds an external reference for that method (no underscore).
You can look at how the symbol is linked to in C++ programs:
tlib ..\lib\import32.lib, import32.lst
This shows the symbol for C++ is _wsprintfA
If altering the .pas file does not help, you could try the
brute force method of an alias is a .def file, e.g.
;;Def file
IMPORTS
wsprintf = User32._wsprintfA
Windows.pas shows it stdcall so that's another puzzle. Does Pascal
wrap Windows API? You are right, it seems like cdecl on this side
and winuser.h shows it as cdecl too.
--Craig
 

Re:Problem linking 3rd party package

Hi Craig,
Craig Farrell wrote:
Quote
That is odd; why they added the external symbol reference to the .pas
with an underscore, and odder, that the error has no underscore.
I think I know the reason for the first - in order to avoid a dynamic
link to the sqlite dll, the package statically link a bunch of
c-compiled object files, and my guess is that one of those object files
references wsprintfA, and being a C compiler the underscore was
prepended in the library. Why the error has no underscore is beyond my
grasp. Yes, I'm that dumb. :)
Quote
A couple of ideas:
You can look in ..\source\win32\rtl\win\Windows.pas to see how
the VCL adds an external reference for that method (no underscore).
You can look at how the symbol is linked to in C++ programs:
tlib ..\lib\import32.lib, import32.lst

This shows the symbol for C++ is _wsprintfA
That is the problem, AFAICS: for the ObjectPascal the function name is
_wsprintfA, but when it links the underscore seems to be lost.
Quote
If altering the .pas file does not help,
If I try to cut the underscore off or comment out the line, the package
doesn't compile.
Quote
you could try the
brute force method of an alias is a .def file, e.g.
;;Def file
IMPORTS
wsprintf = User32._wsprintfA
But what to should I add this def file?
Quote
Windows.pas shows it stdcall so that's another puzzle. Does Pascal
wrap Windows API? You are right, it seems like cdecl on this side
and winuser.h shows it as cdecl too.
A puzzle wrapped in an enigma... :)
--
Ken
 

Re:Problem linking 3rd party package

Hi Craig,
Craig Farrell wrote:
Quote
;;Def file
IMPORTS
wsprintf = User32._wsprintfA
I just changed the first reference above to "wsprintfA" and added the
.def file to my C++ project, and this di the trick. Thanks a lot, but
I'm still hunting for a more elegant solution. :)
--
Ken