Compiling on Sid with g++ 4.7

20 views
Skip to first unread message

Nate Bargmann

unread,
May 30, 2012, 5:52:40 PM5/30/12
to SO2SDR list
On Debian Sid (unstable) g++ was recently upgraded to version 4.7 and I
received the following error:

audioreader_portaudio.cpp: In member function ‘void AudioReaderPortAudio::stopReader()’:
audioreader_portaudio.cpp:143:22: error: ‘usleep’ was not declared in this scope
audioreader_portaudio.cpp:151:20: error: ‘sleep’ was not declared in this scope
audioreader_portaudio.cpp:164:20: error: ‘sleep’ was not declared in this scope
make[1]: *** [audioreader_portaudio.o] Error 1

I applied the following patch to audioreader_portaudio.cpp:

$ git diff
diff --git a/so2sdr/audioreader_portaudio.cpp
b/so2sdr/audioreader_portaudio.cpp
index 370020a..3aba4da 100644
--- a/so2sdr/audioreader_portaudio.cpp
+++ b/so2sdr/audioreader_portaudio.cpp
@@ -18,6 +18,11 @@
*/
#include <math.h>
#include "audioreader_portaudio.h"
+
+#ifdef Q_OS_LINUX
+#include <unistd.h>
+#endif
+
#ifdef Q_OS_WIN
#include <windows.h>
#include "pa_asio.h"


This will affect all recently released versions of SO2SDR, I would
think. I went looking for the reason and found it in the NEWS.gz file
installed by the Debian package (/usr/share/doc/g++-4.7/NEWS.gz) under
'Runtime Library (libstdc++):

- Avoid polluting the global namespace and do not include <unistd.h>.

So, the error makes perfect sense. Heh! This is now fixed in my Git
repository for my version 1.2.2git.

A bit more research shows that per the POSIX standard, usleep() is
considered obsolote. The C library offers nanosleep() in time.h but
there seem to be caveats regarding nanosleep() and threading. For now
usleep() is supported and probably will be for some time. Also,
winkey.cpp makes use of usleep() (seven times). As nanosleep() uses a
pair of structures for its passed values, and the structure typedef
contains a variable for whole seconds and nanoseconds, the call to
sleep() could be replaced as well. We would then be using a standard C
library call and not POSIX ones.

I did not have to specify unistd.h in winkey.cpp as it includes winkey.h
which includes qextserialport/qextserialport.h which then includes
unistd.h!

73, de Nate >>

--

"The optimist proclaims that we live in the best of all
possible worlds. The pessimist fears this is true."

Ham radio, Linux, bikes, and more: http://www.n0nb.us

R. Torsten Clay

unread,
May 31, 2012, 4:37:49 PM5/31/12
to so2...@googlegroups.com
Thanks- I will merge those changes when I get some time.

Another thing to look into is whether Qt has a sleep function that will work. Using that instead will make portability with Windows a little easier.

Tor

Nate Bargmann

unread,
May 31, 2012, 9:27:25 PM5/31/12
to so2...@googlegroups.com
* On 2012 31 May 15:37 -0500, R. Torsten Clay wrote:
> Thanks- I will merge those changes when I get some time.

You're welcome.

> Another thing to look into is whether Qt has a sleep function that will
> work. Using that instead will make portability with Windows a little
> easier.

A quick glance at the Qt 4.8 reference shows that the QThread class
offers the sleep(), msleep(), and usleep() methods for seconds,
milliseconds, and microseconds respectively. I think those would be
excellent choices for our purposes.

73, de Nate >>

P.S. I think the mail delivery issue I was having is solved. Besides
the feedback to Google, I also whitelisted googlegroups.com at the email
provider.

R. Torsten Clay

unread,
Jun 1, 2012, 11:16:43 AM6/1/12
to so2...@googlegroups.com
The problem with those is that in most cases I don't want to have to create a whole
QThread object just to get a sleep function.

Tor

Nate Bargmann

unread,
Jun 1, 2012, 1:18:24 PM6/1/12
to so2...@googlegroups.com
* On 2012 01 Jun 10:16 -0500, R. Torsten Clay wrote:
> The problem with those is that in most cases I don't want to have to create
> a whole
> QThread object just to get a sleep function.

That's a good enough reason. I'm still learning the codebase so I
presumed those thread objects were already in use.

The nanosleep manual page says it conforms to POSIX.1-2001 so using CPP
to choose which function is used will likely need to continue.

73, de Nate >>
Reply all
Reply to author
Forward
0 new messages