Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #4

Open
VitalyArtemiev opened this issue Jul 5, 2019 · 6 comments
Open

Windows support #4

VitalyArtemiev opened this issue Jul 5, 2019 · 6 comments

Comments

@VitalyArtemiev
Copy link

Hello.

I am trying to get these headers (from lubusb-1.0 branch) to work under Windows (currently just trying to compile your example project test1library).
In the LibUsb unit there are the following lines:

{$LINKLIB c}

{$LINKLIB usb-1.0}

As far as I understand, there is no access to libc on windows. Other questions on similar topics suggest replacing libc with libmsvcrt. I've replaced the above code with the following:

{$ifdef windows}
  {$linklib msvcrt}
{$else}
  {$LINKLIB c}
{$endif}

{$LINKLIB usb-1.0}

Of course, this gets rid of the "Import library not found for c" error, however instead I get errors about undefined symbols (seems like every symbol defined in LibUsb unit):

test2controlsync.pas(120,52) Hint: Variable "DescrConf" does not seem to be initialized
test2controlsync.pas(136,52) Hint: Variable "DescrIntf" does not seem to be initialized
test2controlsync.pas(153,50) Hint: Variable "DescrEP" does not seem to be initialized
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_CONTROL_TRANSFER$crc40A776B7
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_INIT$PLIBUSB_CONTEXT::=::\LONGINT
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_EXIT$PLIBUSB_CONTEXT
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_SET_DEBUG$PLIBUSB_CONTEXT$LONGINT
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_GET_VERSION::=::\PLIBUSB_VERSION
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_HAS_CAPABILITY$LONGWORD::=::\LONGINT
Error: Undefined symbol: LIBUSB_::=::\_LIBUSB_ERROR_NAME$LONGINT::=::\PCCHAR

...
etc.

I don't know if this is connected to the libc/libmsvcrt issue or if this is a separate problem. I'm quite a noob when it comes to header translation, linking etc. Do you have any pointers as to which direction I need to be digging?

I am using the latest lazarus/FPC build and the latest version of libusb from https://libusb.info/
(BTW, in your readme file the link to linkusb site no longer works).

@hansiglaser
Copy link
Owner

hansiglaser commented Jul 6, 2019 via email

@VitalyArtemiev
Copy link
Author

I have not changed anything in the source file except for the libc part. The macro is there and is highlighted as active. I've also tried to replace all 'extdecl' modifiers with 'stdcall' outright just now, but that didn't have any effect either.

Maybe it's the compiler version? I'll try with 2.6.0 tomorrow and see if that works.

@VitalyArtemiev
Copy link
Author

VitalyArtemiev commented Jul 7, 2019

I've solved (or, rather, sidestepped) the problem. I replaced the libusb-1.0.a file that I was linking against with libusb-1.0.dll.a and libusb-1.0.dll and also changed the stdcall key word in the windows macro to cdecl. So now, I guess, I am linking dynamically instead of statically? I still would like to know how to link statically but I guess it works, so you may close the issue.

The part of source file I changed now looks like this:

{$macro on}
{$ifdef windows}
  {$define extdecl:=cdecl}
{$else}
  {$define extdecl:=cdecl}
{$endif}

Interface

Uses CTypes;

{$ifdef windows}
  {$linklib msvcrt}
{$else}
  {$LINKLIB c}
{$endif}

{$LINKLIB usb-1.0.dll.a}     

(I understand that the macro now does nothing, but I left it like that in case I need to tamper with it further)

If you want, I'll submit a pull request, but it's not the proper way to do it, so I don't think I should.

@hansiglaser
Copy link
Owner

hansiglaser commented Jul 8, 2019 via email

@Zaaphod
Copy link

Zaaphod commented Aug 10, 2019

Hi Hansi,
I'm wondering if you plan to include the changes to make pas-libusb compatible with windows?
I would be happy to do whatever further testing on windows is needed.
James

@hansiglaser
Copy link
Owner

Hi James!

As discussing in our Freepascal thread I'll be happy to include all changes. When you are satisfied with your work in your fork, just send a pull request.

Thanks
Hansi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants