-
Notifications
You must be signed in to change notification settings - Fork 145
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
Cygwin build issue, libusb related? #906
Comments
Unfortunately, both libusb 0.1 and Win32 libusb appear to use the same
|
Related question: would it make sense / be more maintainable / portable to include these libraries in the project (whether binaries or source; preferably source, for obvious reasons)?
|
Its a little hard to troubleshoot from here, but it looks like you are running into a header naming problem between libusb and the Windows SDK, which both ship Also, you may ask the libusb team for help. I am curious myself how they think this is supposed to work. I have not tried the Cygwin build in a while, but it did work for me the last time I worked on this. Perhaps the include order is different on my PC. I will try it some other day to see if it still works. That said, Cygwin is not my priority, as native builds work well on Windows. Also, one common mistake is that people mix build systems. The automake build just puts intermediate files in the src folder, which screws up the CMake build. So, make sure you have a clean repo:
No. It may help you in this specific case, but libraries are a good thing. |
Does the CMake logic search for that header file? The autoconf scripts did consider it (but arguably, probably also in the wrong order - |
That seems to be the case. I got a successful build by: Do ahead of cmake commands: Change in dfu.h, micronucleus.c, pickit2.c, usb_libusb.c, usbasp.c, usbtiny,c: to just #include <lusb0_usb.h> Obviously, easier solved by resolving -DHAVE_LUSB0_USB_H in the cmake, but I don't know cmake. Or, I suppose renaming w32api/usb.h wouldn't have needed the extra editing. Oops. And moving root in front of /w32api in the include order should seem to work, too. Is it... bad? to rename package files like this?? |
Yes. We have
That said, AFAIK, lusb0_usb.h is only used by libusb-win32. I documented the different combinations in the table found here: https://github.com/avrdudes/avrdude/wiki/The-story-on-libusb-for-Windows
Possibly. check_include_file, or better, the include folders and order baked into the compiler are still a mystery to me. Sometimes the wrong usb.h is picked up, sometimes not. |
I am one of the admins of libusb, libusbk and libusb-win32 (not the developer but on support and testing side). I agree that WinUSB (with MS OS descriptor) and libusb-1.0 API is the way to go for USB Debuggers/Programmers. But I just want to clarify a few points.
Ref: libusb-win32 1.2.7.3 was released on 13-Nov-2021 with signed kernel driver libusb0.sys
Ref: libusbk 3.1.0.0 was released on 19-Jul-2021 even though the kernel driver libusbk.sys was still the old 3.0.7 release.
|
Unlikely to happen. libusb-0.1 "just works", and it would need volunteers for such a change, to rewrite a lot of code – and test all this in the end, on all supported platforms, with all affected programmers. In the end, doing all that work for no gain other than replacing one API by another one, i.e. there won't be any improvements for end-users by that change. |
If the decision is to keep libusb-0.1 API, then the other possibility is to ditch libusb-win32 and use libusb-compat-0.1 under Windows. |
BTW I do not see the point of using Cygwin to build avrdude. There is no issue to build native 32bit/64bit avrdude under MSYS2 mingw32/mingw64. MSYS2 has the libusb-compat-0.1 formula built-in. |
@mcuee Nothing more than, I already had GCC 10 installed there, and saw Cygwin "recommended" on the Wiki. |
Well, one question above was whether changing the include instructions in |
@mcuee I do not understand how a Windows source file that does a In the context of building on Windows, wouldn't it be a good idea to rename (or alias) libusb's |
I do not know much about CMake, but there is no issue building under MSYS2 MinGW64 or MinGW32 with either libusb-win32 or libusb-compat-0.1 installed.
|
Based on the above, I belive there is no issue now at least under MSYS2.
Last time Travis (libusb-win32 previous developer, current libusbk developer) changed the libusb-win32 usb.h header file name to prevent the conflict with Windows DDK usb.h file. |
You can see there is no issues under MSYS2. If there is an issue under Cygwin, I am not using Cygwin myself so I have no comments there. However, it seems to come with libusb.pc file. So I think it should work as well if you use pkg-config. |
BTW, cygwin listed libusb-1.0 and libusb-win32 as ORPHANED. And the version of libftdi1 and hidapi are pretty old. Of course you can build these dependencies by yourself but I really do not see any advantages of using Cygwin compared to MSYS2 mingw32/mingw64 build. |
https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-Windows-using-Cygwin
|
Just want to make it clear.
BTW, by libusb we normally mean "libusb-1.0" as of now. Another thing, I see that you have local fork of libftdi (https://github.com/avrdudes/libftdi) and hidapi (https://github.com/avrdudes/libftdi). I understand you have the local fork because of Visual Studio build (https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-Windows-using-Visual-Studio). Still you may want to get the changes integrated upstream. libftdi is anyway using CMake. hidapi has also moved to CMake. As for your local fork of libusb-win32 (https://github.com/avrdudes/libusb), I am not so sure we will adopt CMake. I will say probably not as the official build method is still Windows DDK/WDK. And we have moved quite a bit far from libusb-1.0.26 release. So you may still want to keep the local fork. It will also be greatly appreciated that you update a bit on the wiki page on libusb (https://github.com/avrdudes/avrdude/wiki/The-story-on-libusb-for-Windows). It is mostly correct but I just want to point out that libusb-win32 and libusbk are not really unmaintained. The other thing is that under Linux there is two options for libusb-0.1 (mostly libusb-compat-0.1, but some distros like Debian/Ubuntu may still have the legacy libusb-0.1 due to some corner cases problems of libusb-compat-0.1). You can also use libusb-compat-0.1 under Windows (but may be a bit problematic if using Visual C but no problem under MSYS2). Ref: Debian/Ubuntu bug report to replace libusb-0.1 with libusb-compat-0.1 |
Exactly, "recommended" in scare quotes. (Should I have used double double quotes?..) Notably, the Wiki doesn't say "NOTE: Cygwin does not build fully because XXX", so I saw no reason not to. Anyway, I got my build, it works, and it is portable by the way, as long as you include all the dependencies (to wit: cygelf-0.dll, cygftdi1-2.dll, cyghidapi-0.dll, cygiconv-2.dll, cygintl-8.dll, cygncursesw-10.dll, cygreadline7.dll, cygusb-1.0.dll, cygusb0.dll, cygwin1.dll). I also since found @mariusgreuel 's release which Just Works(R) (and doesn't have the quirk that you have to enter the port as /dev/ttySx :P ). |
@mcuee I guess what I wanted to point out in the Wiki is that a Windows kernel driver is a critical component in terms of system stability and security, and that a community driven project cannot provide the support that Microsoft can provide for WinUSB. libusb0.sys was great at the time it was created, however, somewhere between then and now, a transition from libusb0.sys to winusb.sys should have happend. However, v1.2.6.0 is still out there, very popular in the Arduino community, yet causing trouble. It certainly does no longer match my expectations, which is why I speak very critical of libusb0.sys in the Wiki. I did change the offending sentence slightly, though. |
Well, a library is userland and thus not a kernel driver ... I'd also disagree about the support statement, based on experience, but I agree that "usb.h" was certainly not a good choice, being a too generic name. Basically, libusb sits on top of kernel drivers, and all it does is to abstract the different OS driver APIs. That allows for a system-independent USB programming world. Without such an abstraction, each and every project that wants to use USB has to provide its own #ifdef spaghetti in order to handle multiple different OSes. |
On Un*x, this is true. On Windows, libusb-win32 (which is now part of libusb) ships the kernel-mode driver libusb0.sys (and libusbK.sys), which is what I was talking about. |
I totally understand your points in the following page even though I am not that happy with some of the words and some facts need to be corrected.
Correct.
Incorrect. a) libusb-win32 project libusb0.dll supports libusb0.sys and libusb.sys but not WinUSB. It will greatly appreciated people to test out and and report issues of using libusb-1.0.dll with libusb0.sys to libusb project.
I understand this point. Still more experienced user can easily swap between libusb0.sys, libusbk.sys and WinUSB using Zadig.
I agree. I will highly recommend moving from libusb-0.1/libusb-win32 API to libusb-1.0 API.
Actually libusb0.sys is not really that buggy (main problem is integration of libusb0.sys support in libusb-1.0.dll) but yes I agree WinUSB should be the way to go. libusb0.sys was developed much earlier than WinUSB. |
libusb-win32 is a sperate project from libusb. It has the library part (libusb0.dll) and kernel driver part (libusb0.sys) Ref: https://github.com/libusb/libusb/wiki/Windows#about
|
https://github.com/libusb/libusb/wiki/FAQ#libusbwin32_libusbK_and_libusb_project == libusb-win32, libusbK and libusb project == Take note [https://sourceforge.net/p/libusb-win32/wiki/Home/ libusb-win32] and [http://libusbk.sourceforge.net/UsbK3/index.html libusbK] projects are separate projects and both of them use [https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel libusb-win32 mailing list] for technical support. Unlike libusb which is a cross-platform project, libusb-win32 and libusbK project are both Windows only project. libusb-win32 project includes libusb0.sys (Windows WDM kernel driver in device driver mode or filter driver mode) and libusb0.dll (libusb-win32 API, library). libusb-win32 API is a superset of the libusb-0.1 API supported by libusb-compat. libusb0.dll supports device using libusb0.sys and libusbK.sys. libusbK projects includes libusbk.sys (Windows KMDF kernel driver) and libusbK.dll (libusbK API, library). libusbK API is Windows only and libusbk.dll supports device using libusbK.sys, libusb0.sys and WinUSB. libusb Windows backend can support device using libusbK.sys (and libusb0.sys driver -- not recommended due to issues) through libusbk.dll provided by libusbK project. If libusbk.dll is present, it will use libusbK.dll as the intermediate library to support device using WinUSB driver. If libusbK.dll is not present, then it will directly talk to device using WinUSB using WinUSB API. libusb Windows also supports device using generic HID driver or usbdk driver. In summary, there is no Windows kernel driver involved in the libusb project. It is purely a user space library. It supports multiple kernel drivers. |
@mariusgreuel |
The other thing is that libftdi-0.1 has not been maintained for quite some time (no updates since 23-Dec-2014). It will be good to move to libftdi-1.0 whenever possible. For FTDI device, usually the vendor FTDI driver is provided, so it is anyway needed to use Zadig to switch drivers if one wants to use libftdi-0.1 or libftdi-1.0. So there is no benefit to use libftdi-0.1 at all. |
@mcuee The whole discussion about libusb* is getting a bit silly. What I wrote in the wiki is in the context of avrdude on Windows, and while not a 100% accurate, it is correct in that context: I say 'libusb0.sys is not maintained', you say 'maintained, but not updated in ten years'. Really, to an end-user like me it is the same thing. We can go on like this forever. My Wiki article does not claim to be 'The definite libusb analysis'. My idea was to transport some useful background info for a frustrated avrdude Windows users with the intend of troubleshooting. Further, I want to steer people away from using the kernel-mode driver libusb0.sys, and instead make use of the WinUSB driver, without having to use tools such as Zadig. |
Leaving the OT, this thread is about the header conflict |
No problem -- skipping the libusb disucssion. It is good to sort out the issue first. |
I think this is a better way: In that case, the user can easily select the library to use.
In this case, people will also have the freedom to use the library to use for the VS build, no need to follow this one. To me the following build instruction is very special and not seen in other projects using CMake. Ref: #955 (comment) |
@mariusgreuel Maybe this can be closed as the OP can build within Cygwin. The other issues have already been discussed in the other threads. |
Close this for now. Improvements on usb.h vs lusb0_usb.h detection can be discussed in the future. |
I followed the build instructions as best I could (they aren't specific about which versions to enable in the package manager; apparently it's the -devel packages with include files) and, whether using build.sh or the cmake strings instructed, the build crashes and burns on dfu.c. I have:
-- Configuration summary:
-- DO HAVE libelf
-- DO HAVE libusb
-- DO HAVE libusb_1_0
-- DO HAVE libhidapi
-- DON'T HAVE libftdi
-- DO HAVE libftdi1
-- DISABLED doc
-- DISABLED parport
-- DISABLED linuxgpio
-- DISABLED linuxspi
and then from the build command,
...
[ 24%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
In file included from /cygdrive/e/MinGW/avrdude-6.4/avrdude/src/dfu.h:28,
from /cygdrive/e/MinGW/avrdude-6.4/avrdude/src/dfu.c:33:
/usr/include/w32api/usb.h:27:9: error: unknown type name ‘PVOID’
27 | typedef PVOID PIRP;
| ^~~~~
and a million other errors after there. I'm guessing it wasn't supposed to read the w32api include. But what else could it read? There's only one usb.h to choose from, right?
Running build.sh, I currently get the error:
Consolidate compiler generated dependencies of target libavrdude
[ 1%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
In file included from /cygdrive/e/MinGW/avrdude-6.4/avrdude/src/avrftdi.c:41:
/cygdrive/e/MinGW/avrdude-6.4/avrdude/src/avrftdi_private.h:10:12: fatal error: libusb.h: No such file or directory
10 | # include <libusb.h>
| ^~~~~~~~~~
This after editing the cmake cache, which seems like a bad idea to me, but I saw this recommended elsewhere, and apparently it doesn't autodetect changes in missing files?
The text was updated successfully, but these errors were encountered: