<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Static linking :</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Le 05/08/2019 à 21:38, Johann Glaser a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:7d18f5340f01f2abecb1c251a0ffed4f4fdc22e2.camel@gmx.at">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div>Referring to your EMail to James, it seems that Vitaly even
got it working with static linking. Especially "$LINKLIB msvcrt"
and "$LINKLIB usb-1.0.dll.a" look promising. Hmm, OTOH he writes
of dynamically linked, I don't know.</div>
<div><br>
</div>
<div>Could you please also have a look at his comments in that
Github issue?</div>
</blockquote>
<p>For now I couldn't achieve static linking.</p>
<p>I couldn't find a reliable way to find the dependencies of
libusb-1.0 on other libraries, may be I would have to dig into the
makefile and autoconf files of libusb sources, but it seems
difficult.<br>
</p>
<p>I used MSYS2 (<a class="moz-txt-link-freetext" href="https://www.msys2.org/">https://www.msys2.org/</a>) in which I installed the
following packages:<br>
</p>
<pre> pacman -S mingw64/mingw-w64-x86_64-libusb
pacman -S mingw-w64-x86_64-headers-git
pacman -S mingw-w64-x86_64-crt-git
pacman -S mingw-w64-x86_64-gcc
In LibUsb.pas I changed the $LINKLIBs to (the errors removed by a particular $LINKLIB are after //Error: ) :
{$LINKLIB usb-1.0}
{$ifdef windows}
{$LINKLIB mingwex} //Error: Undefined symbol: __mingw_vsnprintf, __mingw_vsprintf, __mingw_vsscanf
//{$LINKLIB mingw32} //doesn't improve anything
{$LINKLIB kernel32} // Error: Undefined symbol: __imp_TlsGetValue, __imp_EnterCriticalSection, __imp_LeaveCriticalSection, ... +41 others
{$LINKLIB advapi32} // Error: Undefined symbol: __imp_OpenSCManagerA, __imp_OpenServiceA, __imp_CloseServiceHandle
//{$LINKLIB winpthread} //doesn't improve anything
//{$LINKLIB stdc++} //doesn't improve anything
{$LINKLIB gcc} //Error: Undefined symbol: ___chkstk_ms
{$LINKLIB crtdll} //Error: malloc, memcpy, ... + 37 others
//{$LINKLIB msvcrt} //same as crtdll, Error: malloc, memcpy, ... + 37 others{$else}
{$LINKLIB c}
{$endif}
Here are the errors of the compilation, it's the minimu I could obtain:
Hint: (11030) Start of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Free Pascal Compiler version 3.0.4 [2019/02/03] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling test1library.pas
(9015) Linking E:\03_travail\libusb\pas-libusb\src\examples\test1library.exe
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_default_context
Error: Multiple defined symbol .refptr.INVALID_WINFD
Error: Multiple defined symbol .refptr.pCancelIoEx
Error: Multiple defined symbol .refptr.__tens_D2A
Error: Multiple defined symbol .refptr.__hexdig_D2A
Error: Undefined symbol: atexit
Fatal: (10026) There were 8 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\lazarus\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode
</pre>
<br>
</body>
</html>