mingw32

Leif Asbrink leif at sm5bsz.com
Sat Jan 26 13:25:45 UTC 2013


Hello Peter,

This may not be the appropriate forum for libusb-1.0 discussions,
but since the library is essential for rtlsdr users I take the
liberty to post my findings here.

I already solved the problems when your posting appeared.
I will try the proper configure commands. That would make
things easier of course.

I am not a programmer. There is a lot of terminology that
I do not understand. I am limited to a small sub-set
of regular C and I am too old to learn big volumes of
new things. My interest is radio and signal processing.
The RTL dongle is a marvellous thing (with the e4k tuner)
and I want to make people aware of how it can be used.
Having to worry about drive routines is frustrating but
necessary for performance reasons.

I have been using simple hand-written Makefiles to 
compile and create the libraries. I will try the commands
that you have supplied to see what happens, but first
I will make a new version of Linrad available that will
use rtlsdr properly under Windows.

First of all, the Debian versions of mingw32 are broken. There
are two alternative (mutually excluding) mackages.
The package gcc-mingw32 runs the first step and produces
an assembly file that contains errors causing the second 
step to fail. (do not remember what routine)

The package mingw32 does compile but the linker can not
find the entry for vprintf. There are several .a files
containing a reference to it, if should be located
in libmingwex but it is not there.

The mingw package (5.1.6) for Windows works however so I can
compile on an XP platform. 

I have tested http://git.libusb.org/libusb.git (today, Jan 26)

As it turns out I have to make a couple of changes to allow
compilation. Those are:

--------------------------- core.c -----------------------------
/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
// #define _W32_FT_OFFSET (116444736000000000)
// Jan 26 2013 Leif _sbrink SM5BSZ
// mingw32 does not accept this. Integer constant too large.
// define in 100 millisecond units.
// The routine is rewritten in a simple-minded fashion
#define _W32_FT_OFFSET (11644473600.0)


int usbi_gettimeofday(struct timeval *tp, void *tzp)
 {
 unsigned __int64 *ns100; /*time since 1 Jan 1601 in 100ns units */
 FILETIME ft;
 ns100=(__int64*)&ft;

  if(tp)
    {
      GetSystemTimeAsFileTime (&ft);
      tp->tv_usec=(long)((ns100[0] / 10) % 1000000 );
      ns100[0]/=10000000;
      ns100[0]-=_W32_FT_OFFSET;
      tp->tv_sec= (long)ns100[0];
    }
  /* Always return 0 as per Open Group Base Specifications Issue 6.
     Do not set errno on error.  */
  return 0;
}
// end of modified code Jan 26 2013
--------------------------------------------------------------------
-----------------------   threads_windows.c   ----------------------
// Jan 26 2013 Leif _sbrink SM5BSZ Line changed to coply with mingw 
// static int __inline usbi_cond_intwait(usbi_cond_t *cond,
static __inline int usbi_cond_intwait(usbi_cond_t *cond,
--------------------------------------------------------------------

The resulting library does not work however. It returns -12
to librtl during the initial setup.

I have also compiled libusb-1.0.9 which needed the same
modifications. The library runs, but behaves as all precompiled
versions available on the Internet. Crashes on a frequency change.

Having the library running from my own source code
allowed tracing the crash that occurs when the frequency
is changed while the callback is running. The culpit
is the call usbi_warn(NULL,.... that is issued when
something belonging to another thread is detected.
I have commented out all such calls and now libusb-1.0.9
runs fine on my Windows machine:-)

I have verified that usbi_warn is ok if a context is supplied.

Regards

Leif




On Sat, 26 Jan 2013 05:44:56 +0100
Peter Stuge <peter at stuge.se> wrote:

> Leif Asbrink wrote:
> > Attempts to link librtlsdr and libusb-1.0 with my project
> 
> Please note that libusbx is not libusb. I'm the maintainer of libusb
> at libusb.org and libusbx is a fork with some good additions but more
> notably an overwhelming amount of questionable practises and changes,
> by basically one developer who refuses to work with me. (He banned me
> from the libusbx mailing list when I wrote that some of his code
> which is both in libusb and libusbx had a bug.)
> 
> While I do pay attention to what happens in libusbx I don't know
> exactly what the state is of that code. I haven't tested libusbx-1.0.14
> in a while, and in particular not on Windows, where libusbx has crazy
> changes compared to the original libusb-1.0 from libusb.org. (That's
> the platform the main developer works on.)
> 
> I know of others who have had strange issues with libusbx-1.0.14,
> while the latest libusb.git source code from libusb.org instead
> worked as expected.
> 
> Please grab the latest code from http://git.libusb.org/libusb.git
> and see if it works any better.
> 
> 
> > BUT if I try to change frequency or gain Windows crashes. Also
> > if I try to exit. It seems one must not call anything
> > else in libusb-1.0 after having started read.
> 
> That would be a bug in the implementation. The API design very much
> allows mixing sync and async transfers, and it works fine in
> libusb-1.0.
> 
> 
> > I have used mingw32, the standard install under Ubuntu.
> 
> Ok.
> 
> 
> > I was unable to use the configure script
> 
> This is a HUGE alarm bell for me. Especially if you are just starting
> out with learning cross-compiling it is critical that you make things
> work exactly the way they are supposed to, or you are just setting
> yourself up for endless unneccessary trouble.
> 
> If you tried to use configure and it did not work then why don't you
> show what went wrong?
> 
> Please show the configure command that you ran, along with the
> complete output that it produced. I assume that there were some
> errors in the end, make sure to include those of course, and ideally
> also attach the complete config.log file. Feel free to send that in
> an email directly to me if the mailing list thinks that the
> attachments are too large. Make sure to send the log file as plain
> text, ie. either inline in the email, or attached with text/plain
> MIME type.
> 
> 
> > but made a simple script to compile with
> > /usr/bin/i586-mingw32msvc-gcc
> > and then create the library and install like this:
> > 
> > /usr/bin/i586-mingw32msvc-ar rc librtlsdr.a librtlsdr.o tuner_tuner_fc0013.o tuner_fc2580.o tuner_r820t.o
> > /usr/bin/i586-mingw32msvc-ranlib librtlsdr.a
> > cp librtlsdr.a /usr/i586-mingw32msvc/lib
> 
> It's a bad idea to store librtlsdr in the toolchain lib dir. The
> correct approach is to use a so-called prefix directory, which as
> it happens is taken caren of automatically by the configure script.
> 
> 
> > What can I do to fix the problem?
> 
> I'm happy to help you sort things out with libusb-1.0, but you'll
> have to work with the code from libusb.org.
> 
> configuring and building libusb with that ubuntu cross-compiler
> should work without any issues..
> 
> git clone git://git.libusb.org/libusb.git && \
>   cd libusb && \
>   ./autogen.sh --host=i586-mingw32msvc --prefix=$(pwd)/../winlibs && \
>   make install && \
>   cd .. && \
> git clone git://git.osmocom.org/rtl-sdr && \
>   cd rtl-sdr && \
>   autoreconf -fi && \
>   PKG_CONFIG_LIBDIR=$(pwd)/../winlibs/lib/pkgconfig \
>     ./configure --host=i586-mingw32msvc --prefix=$(pwd)/../winlibs && \
>   make install && \
>   cd .. && \
> ls -l winlibs/bin winlibs/lib
> 
> ..builds libusb and rtl-sdr using the cross-compiler and installs the
> built files into the winlibs/ directory wherever you copypaste the
> above commands.
> 
> But, I don't know if the rtl-sdr configure.ac works so well for
> cross-compiling for Windows. The last time I tried to cross-compile
> rtl-sdr for Windows I used cmake, and I had to work around several
> issues to make that work.
> 
> If you want to focus on the USB communication then you can of course
> continue bypassing the build system for rtl-sdr, but if it has
> actually been fixed since I tried to cross-compile then you should
> really use it.
> 
> The libusb that gets built above includes very verbose debug logging,
> and will output lots of lines of useful information when you run a
> program which uses it. When there are no more bugs to deal with you
> will rebuild libusb without that debug logging:
> 
> cd libusb && \
>   ./configure --host=i586-mingw32msvc --prefix=../winlibs \
>     --disable-debug-log && \
>   make install && \
>   cd ..
> 
> I hope you already see the pattern for how configure works.
> 
> 
> If something doesn't work, please send complete information to get a
> useful response.
> 
> 
> //Peter
> 




More information about the osmocom-sdr mailing list