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
Related
I am unable to compile my code successfully due to undefined references.
I am using the STM32Cube IDE compiler which is based of atollic true studio.
The undefined references are due to headers not linking.
I have included the headers into my main program and have included them in the include path for the compiler.
#include "base64_codec_transport.h"
#include "line_buffer_transport.h"
#include "modem_ussd_transport.h"
#include "thingstream_transport.h"
#include "client_api.h"
#include "client_platform.h"
#include "client_set_callback.h"
#include "custom_modem_transport.h"
#include "debug_printf_core.h"
#include "log_client_transport.h"
#include "log_modem_transport.h"
#include "log_protocol_transport.h"
#include "log_transport.h"
#include "modem2_transport.h"
#include "modem_set_callback.h"
#include "modem_transport.h"
#include "predefined_topics.h"
#include "quectel_modem2_config.h"
#include "ring_buffer_transport.h"
#include "sdk_data.h"
#include "serial_transport.h"
#include "sim7600_modem2_config.h"
#include "transport_api.h"
#include "ublox_modem2_config.h"
The consol errors are below:
All these functions are defined in their respective headers as follows, to give one example.
#define line_buffer_transport_create Thingstream_createLineBufferTransport
which then points to
extern ThingstreamTransportResult Thingstream_line_buffer_deliver(ThingstreamTransport *self);
I have also rebuilt the index multiple times and still no success.
I don't know what else to do to solve this.
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’
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.