a1ien / libusb1-sys

MIT License
13 stars 10 forks source link

About calling convention when compile with MSVC #4

Closed zoumi closed 4 years ago

zoumi commented 4 years ago

These are symbols that usb.lib export, they are _stdcall:


0AE 00000000 UNDEF  notype       External     | __imp__TlsGetValue@4
0AF 00000000 SECT7  notype ()    External     | _libusb_init@4
0B0 00000380 SECT7  notype ()    External     | _libusb_exit@4
0B1 000005D0 SECT7  notype ()    External     | _libusb_set_debug@8
0B2 00000630 SECT7  notype ()    External     | _libusb_get_version@0
0B3 00000640 SECT7  notype ()    External     | _libusb_has_capability@4

These are error msg cargo output, the linker is looking for _cedcl:

          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.15.rcgu.o) : error LNK2019: unresolved external symbol _libusb_exit referenced in function __ZN69_$LT$rusb..context..ContextInner$u20$as$u20$core..ops..drop..Drop$GT$4drop17h2fc6aff0d62a1c36E
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.15.rcgu.o) : error LNK2019: unresolved external symbol _libusb_init referenced in function __ZN74_$LT$rusb..context..GlobalContext$u20$as$u20$rusb..context..UsbContext$GT$6as_raw28_$u7b$$u7b$closure$u7d$$u7d$17h44b14972d58f65c5E
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.8.rcgu.o) : error LNK2019: unresolved external symbol _libusb_has_capability referenced in function __ZN4rusb14has_capability17hd32571b34734b9aaE
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.8.rcgu.o) : error LNK2019: unresolved external symbol _libusb_set_debug referenced in function __ZN4rusb13set_log_level17he490545ae88dc1cbE
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.8.rcgu.o) : error LNK2019: unresolved external symbol _libusb_open_device_with_vid_pid referenced in function __ZN4rusb24open_device_with_vid_pid17h17a2b0eeace84d33E
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _libusb_get_version referenced in function __ZN4rusb7version7version17haf10513ba643efdaE
          librusb-b93ac347174b3335.rlib(rusb-b93ac347174b3335.rusb.1jaepzl0-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _libusb_get_device_list referenced in function __ZN4rusb11device_list46DeviceList$LT$rusb..context..GlobalContext$GT$3new17he68b205dceec1079E
zoumi commented 4 years ago

If I change these lines in libusb.h:

#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#define LIBUSB_CALL WINAPI
#else
#define LIBUSB_CALL
#endif

to #define LIBUSB_CALL it will compile.

a1ien commented 4 years ago

Did you try use vcpkg?

zoumi commented 4 years ago

I had tried before.But vs2019 is required by vcpkg. I don't want to install vs2019.

a1ien commented 4 years ago

hmm... on appveyor I use 2017 MSVC https://github.com/a1ien/libusb1-sys/blob/master/.appveyor.yml#L1

zoumi commented 4 years ago

Thank you for your tip