Update Turnes out my lecturer will accept code written to the GNU99 standard, so, as User1 pointed out, I used _GNU_SOURCE
at the beginning of my program. (See man feature_test_macros
for more info.) Thanks for helping me understand!
On Ubuntu 13.10 with Clang 3.4, GCC 4.8.1, I am doing an assignment which requires me to use the C99 standard. (I also have GNUstep installed from SVN)
WRT GCC, I think I have 4 versions installed in these folders:
/usr/lib/gcc/x86_64-linux-gnu/4.7
/usr/lib/gcc/x86_64-linux-gnu/4.7.3
/usr/lib/gcc/x86_64-linux-gnu/4.8
/usr/lib/gcc/x86_64-linux-gnu/4.8.1
gcc --version
reports 4.8.1, clang --version
reports 3.4. ld -v
reports 2.23.52.20130913
I'm writing a signal handler and when I use siginfo_t in my function header, I get a compiler error: unknown type name 'siginfo_t'
I'm using sigaction() to install the handler.
While studying what needs to be done and how, I was able to compile a simple demo which also uses the same function header definition, and it works. However it's not limited to C99.
These are my includes (of which signal.h is one):
#define _POSIX_C_SOURCE 2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <math.h>
#include <ctype.h>
#include <libgen.h>
#include <signal.h>
This is my signal handler function (only for debugging purposes):
static void sigSIGCHLDhandler(int sigNum, siginfo_t *siginfo, void *context) {
printf("PID = %ld",(long) siginfo->si_pid);
}
I am compiling with clang
using -Wall
and now -std=c99
-std=gnu99
options.
I have tried locate signal.h
and I have it in /usr/include
. I tried adding #include <bits/siginfo.h>
and that allowed me to compile, but the binary wouldn't work correctly.
(I have a bunch of signal.h
and siginfo.h
files on my system.)
Another student suggested that there is something wrong with my set up. So I've reinstalled Clang. Here are some of my environment variables that I think might be relevant (please notify me of any missing or wrong)
LD_LIBRARY_PATH=/home/user/ros_catkin_ws/install_isolated/lib:/home/user/GNUstep/Library/Libraries:/usr/local/lib
CPATH=/home/user/ros_catkin_ws/install_isolated/include
PATH=/home/user/ros_catkin_ws/install_isolated/bin:/home/user/GNUstep/Tools:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/user/bin:/usr/local/java/jdk1.7.0_51/bin
CLASSPATH=/home/user/GNUstep/Library/Libraries/Java:/usr/local/lib/GNUstep/Libraries/Java
LIBRARY_COMBO=gnu-gnu-gnu
INFOPATH=/usr/local/share/info::/home/user/GNUstep/Library/Documentation/info:
GNUSTEP_IS_FLATTENED=yes
GNUSTEP_LOCAL_ROOT=/usr/local/Local
GNUSTEP_HOST=x86_64-unknown-linux-gnu
GUILE_LOAD_PATH=/home/user/GNUstep/Library/Libraries/Guile:/usr/local/lib/GNUstep/Libraries/Guile
GNUSTEP_MAKEFILES=/usr/local/share/GNUstep/Makefiles
GNUSTEP_NETWORK_ROOT=/usr/local/Network
GNUSTEP_FLATTENED=yes
GNUSTEP_HOST_OS=linux-gnu
GNUSTEP_HOST_VENDOR=unknown
GNUSTEP_HOST_CPU=x86_64
GNUSTEP_USER_ROOT=/home/user/GNUstep
GNUSTEP_SYSTEM_ROOT=/usr/local/System
GNUSTEP_PATHLIST=/usr/local/System:/usr/local/Network:/usr/local/Local:/home/user/GNUstep
GNUSTEP_SYSTEM_ROOT=/usr/local/System
GNUSTEP_PATHLIST=/usr/local/System:/usr/local/Network:/usr/local/Local:/home/nap/GNUstep
I've spent hours searching for a fix but can't find anything, and I'm out of ideas. What is broken?
If you look the man page of sigaction(2), you will find the following:
siginfo_t: _POSIX_C_SOURCE >= 199309L
Try adding the compiler option: -D_POSIX_C_SOURCE=199309L
It tells the required posix version to your c-lib (glibc).
EDIT:
See more about those from POSIX wiki page.
featuers.h
tells more about how glibc use the define:
_POSIX_C_SOURCE
If ==1, like _POSIX_SOURCE;
if >=2 add IEEE Std 1003.2;
if >=199309L, add IEEE Std 1003.1b-1993;
if >=199506L, add IEEE Std 1003.1c-1995;
if >=200112L, all of IEEE 1003.1-2004
Similar information also in man page: feature_test_macros(7).
So: _POSIX_C_SOURCE=2 does not bring latest POSIX features for available, because 1003.2 (posix 2) is not the latest one. For getting more features available you need to define later version.
Don't get confused: POSIX.2 is not newer than POSIX.1c.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With