I am having issues compiling my code. It seems to an issue with the include headers
Here are my headers:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <asm/page.h>
#define __KERNEL__
#include <asm/unistd.h>
Here's what I am using to compile:
gcc -o file file.c -I/usr/src/linux-headers-4.12.0-kali2-common/include/asm-generic
I keep getting this error when I compile:
fatal error: uapi/asm-generic/signal.h: No such file or directory
#include <uapi/asm-generic/signal.h>
If I try adding asm/ or asm-generic/ to signal.h, I get:
redefinition of ‘struct timeval’
Related
I've created a c project and this is the beginning of the main.c file:
#include <curl/curl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "include/httpdef.h"
//...some code
The httpdef.h beginning is this:
#ifndef httpdef
#define httpdef
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
//definitions
#endif
At the very first line of both files I get the error from the gcc compiler:
macro name must be an identifier
What could be the problem?
EDIT: I realized now that actually the compiler doesn't give any error, it's my vim plugin (YouCOmpleteMe) that generates this error. If I compile everything works and the error doesn't appear
Here's my code:
#include <sys/types.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
int main(int argc, char** argv) {
sigignore(SIGTERM);
return 0;
}
Why do I get the following warning and how could I remove it?
implicit declaration of function ‘sigignore’
[-Wimplicit-function-declaration] sigignore(SIGTERM);
The program must be compiled like this: gcc -o foo.o foo.c.
Thanks
Man sigignore tells you to use #define _XOPEN_SOURCE 500 to enable sigignore. More on X/Open can be found here
The function you want to call has been marked as obsolete 15 years ago. The normal way to discourage people from using those functions (without actually breaking programs) is to have the implementation of the function left in the standard library, but remove the declaration from header files (or at least make it hard to enable).
Use sigaction or sigprocmask (depending on what you actually want to accomplish).
I get an error message error: ‘SIG_BLOCK’ undeclared for this code when compiling with -ansi.
sigprocmask(SIG_BLOCK, &my_sig, NULL);
Did I forget to be explicit about some header file? These are my includes
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
You need to tell the compiler you want SIG_BLOCK to be defined.
From man sigaction:
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
sigprocmask(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
So you might like to pass the option
-D_POSIX_SOURCE
or
-D_POSIX_C_SOURCE=1
to gcc for example
Alternativly you can put those "requests" as preprocessor directives right at the top of your sources:
#define _POSIX_SOURCE
... /* other includes */
#include <signal.h>
or
#define _POSIX_C_SOURCE 1
... /* other includes */
#include <signal.h>
Even after trying all orders of header file inclusion,
I still get the error for netinet/in.h
/usr/include/netinet/in.h:34: error: expected identifier before numeric constant
I have included the following header files
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <sys/select.h>
#include <fcntl.h>
#include <sys/types.h>
#include <errno.h>
#include <netinet/ip.h>
#include <netinet/in.h>
How do I get rid of this error?
I compile with gcc -g3 -Wall.
netinet/in.h doesn't have header guard so what's happening is some variable is already been defined in netinet/ip.h header file. try pushing netinet/in.h to beginning of the file.
Everything goes well with this statement:
fnmatch(pattern, href, FNM_EXTMATCH);
when I oder the header files as below:
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "link.h"
But the gcc says that FNM_EXTMATCH not defined when I order the head files instead as below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
#include "link.h"
So where is the conflict?
FNM_EXTMATCH is a GNU extension. If you wish to use it, put
#define _GNU_SOURCE
at the top of your file (before any #include statements). Note, however, that it will not be portable to non-GNU systems -- those without gcc and glibc.