error in GMutex.h, observed on r3055, 'usleep' was not declared in this scope, fix included

432 views
Skip to first unread message

Mike Roberts

unread,
Apr 3, 2013, 7:37:10 AM4/3/13
to g3d-...@googlegroups.com
Hi friends,

Background: I'm on r3061 of the SVN depot, and I'm on Mac OSX 10.8.3. I have a few different versions of GCC installed, but the default one that gets invoked when I type "gcc" or "g++" on the command line is the latest version of GCC that ships with the XCode Command Line Tools.



 dn5221dj:starter mike$ g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)



Quick side note: iCompile's strategy of using the latest version of GCC available on the system causes build errors for me when building G3D. I have GCC 4.8 installed on my system, but for all intents and purposes, it is disabled. GCC 4.2.1 is the version that gets invoked when I type gcc. See the build error above. Of course, I can sidestep this issue by specifying "g++" (with no path or anything) as the default compiler in my ~/.icompile file, but is the default behavior intended? Intuitively, I would expect the default compiler used by iCompile to be the compiler that gets invoked by typing "g++" on the command-line.



dn5221dj:G3D9 mike$ ./buildg3d update
Adding iCompile options: ['--verbosity', '1']
../bin/icompile --verbosity 1 --noprompt
_______________________________________________________________________

Building libfreeimaged.a
Computing dependencies
g++-mp-4.8: error: unrecognized command line option '-fasm-blocks'
1s



Main Bug: Ok, now onto the main bug. When I was on r3055, I encountered the following bug when I tried to compile the "starter" sample project. 

/Users/mike/Work/Subversion/g3d-code/G3D9/build/include/G3D/GMutex.h:51:25: error: 'usleep' was not declared in this scope

A straightforward fix is simply to #include <unistd.h> in GMutex.h when compiling on OSX. Interestingly, I couldn't reproduce this bug on r3061, even though GMutex.h still isn't including <unistd.h>. This suggests that <unistd.h> wasn't getting included at all in r3055, but is somehow getting indirectly included in r3061. As a matter of taste, I believe that GMutex.h should #include <unistd.h>, rather than relying on an indirect inclusion from some other header. After all, GMutex.h makes use of the usleep function which is declared in <unistd.h>.

There might be good reasons for not doing this though. I figured I'd mention my findings in case this was an oversight  :)

Cheers,
Mike

Morgan McGuire

unread,
Apr 3, 2013, 11:34:01 AM4/3/13
to g3d-...@googlegroups.com
building G3D. I have GCC 4.8 installed on my system, but for all intents and purposes, it is disabled. GCC 4.2.1 is the version that gets invoked when I type gcc. See the build error above. Of course, I can sidestep this issue by specifying "g++" (with no path or anything) as the default compiler in my ~/.icompile file, but is the default behavior intended? Intuitively, I would expect the default compiler used by iCompile to be the compiler that gets invoked by typing "g++" on the command-line.

The current behavior is the intended behavior--icompile is trying to save users from themselves (or at least, from their system administrators--the primary audience is people who don't control their machines).  Power users can override the default behavior as you did.  I'm not arguing that this is the optimal design choice, just stating that it is what was intended.

We're switching to clang soon, btw.

-m




dn5221dj:G3D9 mike$ ./buildg3d update
Adding iCompile options: ['--verbosity', '1']
../bin/icompile --verbosity 1 --noprompt
_______________________________________________________________________

Building libfreeimaged.a
Computing dependencies
g++-mp-4.8: error: unrecognized command line option '-fasm-blocks'
1s



Main Bug: Ok, now onto the main bug. When I was on r3055, I encountered the following bug when I tried to compile the "starter" sample project. 

/Users/mike/Work/Subversion/g3d-code/G3D9/build/include/G3D/GMutex.h:51:25: error: 'usleep' was not declared in this scope

A straightforward fix is simply to #include <unistd.h> in GMutex.h when compiling on OSX. Interestingly, I couldn't reproduce this bug on r3061, even though GMutex.h still isn't including <unistd.h>. This suggests that <unistd.h> wasn't getting included at all in r3055, but is somehow getting indirectly included in r3061. As a matter of taste, I believe that GMutex.h should #include <unistd.h>, rather than relying on an indirect inclusion from some other header. After all, GMutex.h makes use of the usleep function which is declared in <unistd.h>.

There might be good reasons for not doing this though. I figured I'd mention my findings in case this was an oversight  :)

Cheers,
Mike

--
You received this message because you are subscribed to the Google Groups "G3D Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to g3d-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Morgan McGuire

unread,
Apr 3, 2013, 11:35:17 AM4/3/13
to g3d-...@googlegroups.com
Fixed, thanks.

-m

Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan


--

Mike Roberts

unread,
Apr 3, 2013, 6:28:23 PM4/3/13
to g3d-...@googlegroups.com
Hey Morgan,

I glanced at your change r3062. It appears as though you edited the comments in GMutex.h without editing the includes. I might be interpreting the diff on the SourceForge website incorrectly though. Was that intended?  :)

Cheers,
Mike

Mike Roberts

unread,
Apr 3, 2013, 6:30:48 PM4/3/13
to g3d-...@googlegroups.com
Ah, that makes sense. Anyway, yes, it is very easy to override. Also, good to know about the upcoming switch to clang  :)

Cheers,
Mike

Morgan McGuire

unread,
Apr 3, 2013, 7:07:44 PM4/3/13
to g3d-...@googlegroups.com
That was a different change.  I haven't committed yours yet, I guess.

-m


Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan


Mike Roberts

unread,
Apr 3, 2013, 7:30:52 PM4/3/13
to g3d-...@googlegroups.com
No worries  :)
Reply all
Reply to author
Forward
0 new messages