Compilation avec -ansi : SA_RESTART undeclared
Salut à toutes et à tous.
J'ai terminé et remis tantôt un projet pour mon cours de UNIX. Il s'agissait d'utiliser les IPC : semaphores, mémoires partagées, sockets...
Dans l'ensemble, ça s'est pas mal passé, mais quelques questions subsistent. Elles concernent l'option -ansi de notre ami gcc.
Pour info, je bosse sous Ubuntu 10.04 64 bits, et voici ce qu'affiche gcc -v :
Code:
1 2 3 4 5 6 7 8 9 10
| antoine@Aspyct:~$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) |
Ce que je vous décris plus bas ne se passe que si l'option -ansi est utilisée pour compiler.
Bien, le décors est placé, voici mes questions :
1. contraint et forcé par <sys/ipc.h>, j'ai du mettre l'option -D_XOPEN_SOURCE. À quoi sert-elle exactement ?
2. SA_RESTART semble bien poser des soucis. Voyez par vous même:
Code:
1 2 3 4 5 6 7
| #include <signal.h>
int
main()
{ int flags = SA_RESTART;
return 0;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11
| antoine@Aspyct:~$ gcc sa_restart.c
antoine@Aspyct:~$ gcc -ansi sa_restart.c
sa_restart.c: In function main:
sa_restart.c:5: error: SA_RESTART undeclared (first use in this function)
sa_restart.c:5: error: (Each undeclared identifier is reported only once
sa_restart.c:5: error: for each function it appears in.)
antoine@Aspyct:~$ gcc -ansi -D_XOPEN_SOURCE sa_restart.c
sa_restart.c: In function main:
sa_restart.c:5: error: SA_RESTART undeclared (first use in this function)
sa_restart.c:5: error: (Each undeclared identifier is reported only once
sa_restart.c:5: error: for each function it appears in.) |
D'après ce que j'ai pu lire sur le net, il s'agirait d'une sorte de conflit du standard avec les headers actuels (info à vérifier). Qu'en est-il exactement ? sigaction fait-il partie du passé ? Et comment résoudre cette erreur de compilation ?