Errors while cross compiling OpenOCD on Ubuntu for Windows

in /home/user/freedom-e-sdk I type the following the commands

mkdir -p work/build/openocd/

cd /home/user/freedom-e-sdk/openocd

autoreconf -i

cd /home/user/freedom-e-sdk/work/build/openocd/

/home/user/freedom-e-sdk/openocd/configure --enable-jtag_vpi --prefix=/home/user/freedom-e-sdk/work/build/openocd/prefix --disable-werror

make

The above commands do work. However when I switch to cross compiling I use the commands below

/home/user/freedom-e-sdk/openocd/configure --prefix=/home/user/freedom-e-sdk/work/build/openocd/prefix --disable-werror --host=x86_64-w64-mingw32

make

I get the following errors:

In file included from /home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:21:0:

/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.h:23:72: warning: ‘struct usb_dev_handle’ declared inside parameter list

int jtag_usb_open(const uint16_t vids, const uint16_t pids, struct usb_dev_handle **out);

^

/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.h:23:72: warning: its scope is only this definition or declaration, which is probably not what you want

/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:25:3: warning: ‘struct usb_device’ declared inside parameter list

const uint16_t vids, const uint16_t pids){

^

/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c: In function ‘jtag_usb_match’:

/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:27:10: error: dereferencing pointer to incomplete type ‘struct usb_device’

if (dev->descriptor.idVendor == vids &&
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c: At top level:
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:35:10: warning: ‘struct usb_dev_handle’ declared inside parameter list
struct usb_dev_handle **out){
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:34:5: error: conflicting types for ‘jtag_usb_open’
int jtag_usb_open(const uint16_t vids[], const uint16_t pids[],
^
In file included from /home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:21:0:
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.h:23:5: note: previous declaration of ‘jtag_usb_open’ was here
int jtag_usb_open(const uint16_t vids, const uint16_t pids, struct usb_dev_handle **out);
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c: In function ‘jtag_usb_open’:
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:36:2: warning: implicit declaration of function ‘usb_find_busses’ [-Wimplicit-function-declaration]
usb_find_busses();
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:37:2: warning: implicit declaration of function ‘usb_find_devices’ [-Wimplicit-function-declaration]
usb_find_devices();
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:39:27: warning: implicit declaration of function ‘usb_get_busses’ [-Wimplicit-function-declaration]
struct usb_bus *busses = usb_get_busses();
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:39:27: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:40:51: error: dereferencing pointer to incomplete type ‘struct usb_bus’
for (struct usb_bus *bus = busses; bus; bus = bus->next) {
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:41:3: error: ‘struct usb_device’ declared in ‘for’ loop initial declaration
for (struct usb_device *dev = bus->devices; dev; dev = dev->next) {
^
/home/user/freedom-e-sdk/openocd/src/jtag/drivers/usb_common.c:41:61: error: dereferencing pointer to incomplete type ‘struct usb_device’
for (struct usb_device *dev = bus->devices; dev; dev = dev->next) {
^
I am not sure what’s the problem with the file usb_common.c, since it works when I compile for ubuntu.

You did not report which version of openocd you are using. I just tested git master and compiles fine in Arch. If you are on an older version, it could be the reason of the error.

Nevertheless, it looks like you do not have libusb or it cannot be found or you have an incomplete installation.

What configure reports about libusb in the cross-compile environment?

yeah there was a problem related to libusb. now it’s fixed.

I recommend anyone who has this problem to use the scripts in the following git directory: https://github.com/artynet/openocd-ming … ld-scripts