stddef.h: error: duplicate 'unsigned' - c

I'm compiling grep on the 64-bit GCC compiler for Windows 7 x64 SUA/Interix.
It chokes on the marked line in stddef.h:
#ifndef _SIZE_T_DEFINED
#if defined (lp64) || defined(_WIN64)
#ifdef lp64
typedef unsigned long size_t; // <------ error
#else /* lp64 */
typedef unsigned __int64 size_t;
#endif /* lp64 */
#else /* (defined(lp64) || defined(_WIN64)) */
typedef unsigned int size_t;
#endif /* (defined(lp64) || defined(_WIN64)) */
#define _SIZE_T_DEFINED
#define _SIZE_T
#endif /* _SIZE_T_DEFINED */
The output for make is:
make all-recursive
Making all in intl
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale\" -DLIBDIR=\"/usr/local/lib\" -DIN_LIBINTL -DHAVE_CONFIG_H -I.. -I. -I../../intl -D_ALL_SOURCE -D_REENTRANT -I/usr/local/include -I/usr/local/include -D_ALL_SOURCE -D_REENTRANT ../../intl/intl-compat.c
In file included from ../../intl/gettextP.h:23:0,
from ../../intl/intl-compat.c:25:
/usr/include/stddef.h:50:23: error: duplicate 'unsigned'
*** Error code 1
Stop in /tmp/grep-2.5.4-src/build/intl.
*** Error code 1
Stop in /tmp/grep-2.5.4-src/build (line 329 of Makefile).
*** Error code 1
Stop in /tmp/grep-2.5.4-src/build (line 244 of Makefile).
I don't understand what the cause is... it's already confusing that long is being used as though it's 64-bit in GCC, but the error is even more confusing! Ideas?

Somewhere in your code, somone probably did:
#define size_t unsigned long
Or something along those lines, without having defined _SIZE_T_DEFINED when they did it. Then their code #includes stddef.h via the path listed in your error message. That makes your error line look like:
typedef unsigned long unsigned long;
To the compiler, which is not going to work!

Related

Compilation headers for 64-bit ARM64 Raspberry Pi for Yate?

When I try to compile Nuand's Yate software on 64-bit (ARM64) Ubuntu 21.04 on a Raspberry Pi 4, I get architecture support headers errors:
~/software/bts/yate$ make
make -C ./engine all
make[1]: Entering directory '/home/parallels/software/bts/yate/engine'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/parallels/software/bts/yate/engine'
make -C ./modules all
make[1]: Entering directory '/home/parallels/software/bts/yate/modules'
make -C ../libs/miniwebrtc
make[2]: Entering directory '/home/parallels/software/bts/yate/libs/miniwebrtc'
g++ -Wall -I. -I./audio/common/processing -I./audio/common/vad -I./audio/processing/aec -I./audio/processing/aecm -I./audio/processing/agc -I./audio/processing/ns -I./audio/processing/utility -I./system_wrappers -O2 -Wno-overloaded-virtual -fno-exceptions -fPIC -DHAVE_GCC_FORMAT_CHECK -DHAVE_BLOCK_RETURN -DWEBRTC_NS_FLOAT=true -c -o audio/common/resampler/resampler.o audio/common/resampler/resampler.cc
In file included from ./audio/common/processing/signal_processing_library.h:22,
from audio/common/resampler/resampler.cc:19:
./typedefs.h:104:2: error: #error Please add support for your architecture in typedefs.h
104 | #error Please add support for your architecture in typedefs.h
| ^~~~~
make[2]: *** [Makefile:263: audio/common/resampler/resampler.o] Error 1
make[2]: Leaving directory '/home/parallels/software/bts/yate/libs/miniwebrtc'
make[1]: *** [Makefile:448: ../libs/miniwebrtc/libminiwebrtc.a] Error 2
make[1]: Leaving directory '/home/parallels/software/bts/yate/modules'
make: *** [Makefile:186: modules] Error 2
When I check the typedefs.h header, I see arm64 support is not added yet:
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contains platform-specific typedefs and defines.
#ifndef WEBRTC_TYPEDEFS_H_
#define WEBRTC_TYPEDEFS_H_
// Reserved words definitions
// TODO(andrew): Look at removing these.
#define WEBRTC_EXTERN extern
#define G_CONST const
#define WEBRTC_INLINE extern __inline
// Define WebRTC preprocessor identifiers based on the current build platform.
// TODO(andrew): Clean these up. We can probably remove everything in this
// block.
// - TARGET_MAC_INTEL and TARGET_MAC aren't used anywhere.
// - In the few places where TARGET_PC is used, it should be replaced by
// something more specific.
// - Do we really support PowerPC? Probably not. Remove WEBRTC_MAC_INTEL
// from build/common.gypi as well.
#if defined(WIN32)
// Windows & Windows Mobile.
#if !defined(WEBRTC_TARGET_PC)
#define WEBRTC_TARGET_PC
#endif
#elif defined(__APPLE__)
// Mac OS X.
#if defined(__LITTLE_ENDIAN__ )
#if !defined(WEBRTC_TARGET_MAC_INTEL)
#define WEBRTC_TARGET_MAC_INTEL
#endif
#else
#if !defined(WEBRTC_TARGET_MAC)
#define WEBRTC_TARGET_MAC
#endif
#endif
#else
// Linux etc.
#if !defined(WEBRTC_TARGET_PC)
#define WEBRTC_TARGET_PC
#endif
#endif
// Derived from Chromium's build/build_config.h
// Processor architecture detection. For more info on what's defined, see:
// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
// http://www.agner.org/optimize/calling_conventions.pdf
// or with gcc, run: "echo | gcc -E -dM -"
// TODO(andrew): replace WEBRTC_LITTLE_ENDIAN with WEBRTC_ARCH_LITTLE_ENDIAN?
#if defined(_M_X64) || defined(__x86_64__)
#define WEBRTC_ARCH_X86_FAMILY
#define WEBRTC_ARCH_X86_64
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(_M_IX86) || defined(__i386__)
#define WEBRTC_ARCH_X86_FAMILY
#define WEBRTC_ARCH_X86
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__ARMEL__)
// TODO(andrew): We'd prefer to control platform defines here, but this is
// currently provided by the Android makefiles. Commented to avoid duplicate
// definition warnings.
//#define WEBRTC_ARCH_ARM
// TODO(andrew): Chromium uses the following two defines. Should we switch?
//#define WEBRTC_ARCH_ARM_FAMILY
//#define WEBRTC_ARCH_ARMEL
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__mips__)
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_BIG_ENDIAN
#elif defined(__powerpc64__)
#define WEBRTC_ARCH_PPC64 1
#define WEBRTC_ARCH_64_BITS
#ifdef __LITTLE_ENDIAN__
#define WEBRTC_ARCH_LITTLE_ENDIAN
#define WEBRTC_LITTLE_ENDIAN
#else
#define WEBRTC_ARCH_BIG_ENDIAN
#define WEBRTC_BIG_ENDIAN
#endif
#elif defined(__powerpc__)
#define WEBRTC_ARCH_PPC 1
#define WEBRTC_ARCH_32_BITS
#ifdef __LITTLE_ENDIAN__
#define WEBRTC_ARCH_LITTLE_ENDIAN
#define WEBRTC_LITTLE_ENDIAN
#else
#define WEBRTC_ARCH_BIG_ENDIAN
#define WEBRTC_BIG_ENDIAN
#endif
#else
#error Please add support for your architecture in typedefs.h
#endif
#if defined(__SSE2__) || defined(_MSC_VER)
#define WEBRTC_USE_SSE2
#endif
#if defined(WEBRTC_TARGET_PC)
#if !defined(_MSC_VER)
#include <stdint.h>
#else
// Define C99 equivalent types.
// Since MSVC doesn't include these headers, we have to write our own
// version to provide a compatibility layer between MSVC and the WebRTC
// headers.
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#endif
#if defined(WIN32)
typedef __int64 WebRtc_Word64;
typedef unsigned __int64 WebRtc_UWord64;
#else
typedef int64_t WebRtc_Word64;
typedef uint64_t WebRtc_UWord64;
#endif
typedef int32_t WebRtc_Word32;
typedef uint32_t WebRtc_UWord32;
typedef int16_t WebRtc_Word16;
typedef uint16_t WebRtc_UWord16;
typedef char WebRtc_Word8;
typedef uint8_t WebRtc_UWord8;
// Define endian for the platform
#define WEBRTC_LITTLE_ENDIAN
#elif defined(WEBRTC_TARGET_MAC_INTEL)
#include <stdint.h>
typedef int64_t WebRtc_Word64;
typedef uint64_t WebRtc_UWord64;
typedef int32_t WebRtc_Word32;
typedef uint32_t WebRtc_UWord32;
typedef int16_t WebRtc_Word16;
typedef char WebRtc_Word8;
typedef uint16_t WebRtc_UWord16;
typedef uint8_t WebRtc_UWord8;
// Define endian for the platform
#define WEBRTC_LITTLE_ENDIAN
#else
#error "No platform defined for WebRTC type definitions (typedefs.h)"
#endif
#endif // WEBRTC_TYPEDEFS_H_
So I reported this error to manufacturer Nuand, but they were not responding quickly on how to resolve these issues. So if I would add support for the raspberry pi manually, What's the correct way to add support for ARM64 without resulting into errors after compilation?
I tried:
#elif defined(__aarch64__)
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
But it didn't result into a working Yate binary:
make[1]: Leaving directory '/home/yate/yate-rc-2/yate/conf.d'
make: *** [Makefile:259: install-api] Error 1

custom collectd plugin will not compile

I am trying to write a custom plugin in C for collectd and cannot get it to compile with collectd. I've tried this tutorial and could get the plugin to work with the collectd build system.
I've also tried this with just a copy of the load plugin, and tried to manually compile the c-file in order to just link the compiled library (kind of a hackish way around). But I'm still getting errors.
When I run
gcc -I. -g -O -c load_copy.c -lcommon
I get this error
daemon/common.h:308:2: error: #error "Don't know how to convert between host
and network representation of doubles."
#error
\
^
daemon/common.h:336:23: warning: ‘struct passwd’ declared inside parameter list
struct passwd **pwbufp);
^
daemon/common.h:336:23: warning: its scope is only this definition or declaration, which is probably not what you want
load_copy.c: In function ‘load_read’:
load_copy.c:184:2: error: #error "No applicable input method."
#error "No applicable input method."
like there is still a compilation error. Has anyone successfully written a C plugin for collectd? Any tips?
This is from common.h
#ifdef HAVE_LIBKSTAT
int get_kstat(kstat_t **ksp_ptr, char *module, int instance, char *name);
long long get_kstat_value(kstat_t *ksp, char *name);
#endif
#ifndef HAVE_HTONLL
unsigned long long ntohll(unsigned long long n);
unsigned long long htonll(unsigned long long n);
#endif
#if FP_LAYOUT_NEED_NOTHING
#define ntohd(d) (d)
#define htond(d) (d)
#elif FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP
double ntohd(double d);
double htond(double d);
#else
#error \
"Don't know how to convert between host and network representation of
doubles."
#endif

Getting embedded PACKED_STRUCT definition to compile under g++

I'm working on a smart meter project, ARM, keil compiler. I want to compile some of the more complex logic under g++ to run regression tests. I'm having a problem with some include files defining the interface to WMBus stack we purchased.
PACKED_STRUCT( typedef struct S_WMBUS_ADDR_T
{
/*! Manufacturer ID */
uint8_t pc_manufr[WMBUS_ADDR_MANUFR_LEN];
/*! Ident number */
uint8_t pc_ident[WMBUS_ADDR_IDENT_LEN];
/*! Version */
uint8_t c_version;
/*! Type */
uint8_t c_type;
}, s_wmbus_addr_t);
PACKED_STRUCT is defined in a compiler sensitive include file:
#elif defined (__GNUC__)
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __attribute__ ((__packed__)) __name__
...
#elif defined(__arm__)
#ifdef __ARMCC_VERSION
#define PACKED_STRUCT(__declaration__, __name__) \
__packed __declaration__ __name__
And I always get the following error messages:
error: types may not be defined in parameter types
error: typedef declaration invalid in parameter declaration
I can so no way around this other than by editing the include file to remove the PACKED_STRUCT. Obviously I won't edit the files directly, I'll copy them, edit them, and use the -I directive to make it find my modified files under G++
The error message seems to be saying you cannot declare a type as an argument to a macro?
Note even if I redeclare:
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __name__
I am using the -std=c++11 flag to g++ but removing this flag solves nothing, but makes a system include fail
Is there any way I can define PACKED_STRUCT to make the unmodified code compile under g++?
#LP You are right, though I'm not sure why right now. This code compiles:
I must have a wrong include file slipping through somehow.
typedef unsigned char uint8_t;
#define WMBUS_ADDR_MANUFR_LEN 4
#define WMBUS_ADDR_IDENT_LEN 4
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __attribute__ ((__packed__)) __name__
PACKED_STRUCT( typedef struct S_WMBUS_ADDR_T
{
/*! Manufacturer ID */
uint8_t pc_manufr[WMBUS_ADDR_MANUFR_LEN];
/*! Ident number */
uint8_t pc_ident[WMBUS_ADDR_IDENT_LEN];
/*! Version */
uint8_t c_version;
/*! Type */
uint8_t c_type;
}, s_wmbus_addr_t);
s_wmbus_addr_t hello;

Compilation error in C: Inconsistent type declaration/Illegal redeclaration for identifier

I am getting the following error while compiling my source code:
Compiling lib/netapi/joindomain.c
cc: "include/smb_ldap.h", line 33: error 1584: Inconsistent type declaration: "ber_tag_t".
cc: "include/smb_ldap.h", line 34: error 1713: Illegal redeclaration for identifier "ber_int_t".
The following command failed:
)
*** Error exit code 1
The corresponding code which flags the error is:
if HAVE_LBER_H
#include <lber.h>
#if defined(HPUX) && !defined(_LBER_TYPES_H)
#ifndef ber_tag_t
typedef unsigned long ber_tag_t;
typedef int ber_int_t;
#endif
#endif
I request help in understanding the root cause of this error.
Thanks in advance.
Here are my machine and compiler details for reference:
$ uname -a
HP-UX cifsvade B.11.31 U 9000/800 3751280844 unlimited-user license
$ which cc
/usr/bin/cc
$ ls -lrt /usr/bin/cc
lrwxr-xr-x 1 root sys 17 Oct 8 17:45 /usr/bin/cc -> /opt/ansic/bin/cc
$
lber.h defines ber_tag_t and ber_tag_t as follow:
typedef impl_tag_t ber_tag_t;
typedef impl_int_t ber_int_t;
In your code you try to redefine them, this is the case.
A condition
#ifndef ber_tag_t
is always true unless you defined ber_tag_t somewhere like
#define ber_tag_t smth
As oleg_g hints towards you are mixing preprocessor commands (#define) and c++ typedef
The preprocessor directives (#define etc.) are processed before the parser processes the resulting code. When you typedef ber_tag_t the preprocessor commands will never know of this and instead you need to #define a variable to indicate the type is defined.:
#if HAVE_LBER_H
#include <lber.h>
#if defined(HPUX) && !defined(_LBER_TYPES_H)
#ifndef DEFINED_BER_TAG_T
#define DEFINED_BER_TAG_T
typedef unsigned long ber_tag_t;
typedef int ber_int_t;
#endif
#endif
To clarify; preprocessor directives see only of other preprocessor variables as your code has not yet been interpreted at this point.
EDIT:
I should also mention it may be beneficial to lay out your code in a way to avoid the need of this if possible. For example using a separate common header in which the inclusion and type are protected by include guards for example.

"error: expected specifier-qualifier-list before XXX"?

I'm trying to "implement" a cross-platform mutex following the instructions here:
And here is my code:
#ifndef __SIMPLEAV_CORE_UTIL_SAMUTEX_H_DEFINED__
#define __SIMPLEAV_CORE_UTIL_SAMUTEX_H_DEFINED__
/*
* A simple cross-platform (currently only on linux and win) mutex.
*
* usage:
* SAMutex mutex;
* SAMutex_init(&mutex);
* SAMutex_lock(&mutex);
* SAMutex_unlock(&mutex);
* SAMutex_destroy(&mutex);
*
* all functions return 0 on success, -1 on error.
*/
#if defined(LINUX)
#include <pthread.h>
//typedef pthread_mutex_t SAMutex;
#define SAMutex pthread_mutex_t
#elif defined(WINDOWS)
#include <windows.h>
#include <process.h>
//typedef HANDLE SAMutex;
#define SAMutex HANDLE
#endif
int SAMutex_init(SAMutex *);
int SAMutex_lock(SAMutex *);
int SAMutex_unlock(SAMutex *);
int SAMutex_destroy(SAMutex *);
#endif
but what I got after running gcc was:
~/git/SimpleAV/build $ make
[ 20%] Building C object CMakeFiles/player2.dir/player2.c.o
In file included from /home/wecing/git/SimpleAV/include/SimpleAV/core/core.h:4,
from /home/wecing/git/SimpleAV/include/SimpleAV/SDL/api.h:5,
from /home/wecing/git/SimpleAV/player2.c:4:
/home/wecing/git/SimpleAV/include/SimpleAV/core/util/SAMutex.h:28: error: expected ‘)’ before ‘*’ token
/home/wecing/git/SimpleAV/include/SimpleAV/core/util/SAMutex.h:29: error: expected ‘)’ before ‘*’ token
/home/wecing/git/SimpleAV/include/SimpleAV/core/util/SAMutex.h:30: error: expected ‘)’ before ‘*’ token
/home/wecing/git/SimpleAV/include/SimpleAV/core/util/SAMutex.h:31: error: expected ‘)’ before ‘*’ token
In file included from /home/wecing/git/SimpleAV/include/SimpleAV/SDL/api.h:5,
from /home/wecing/git/SimpleAV/player2.c:4:
/home/wecing/git/SimpleAV/include/SimpleAV/core/core.h:28: error: expected specifier-qualifier-list before ‘SAMutex’
make[2]: *** [CMakeFiles/player2.dir/player2.c.o] Error 1
make[1]: *** [CMakeFiles/player2.dir/all] Error 2
make: *** [all] Error 2
by the way, on linux, pthread_mutex_t is defined as:
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
#if __WORDSIZE == 64
unsigned int __nusers;
#endif
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
#if __WORDSIZE == 64
int __spins;
__pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV 1
#else
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
#endif
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
What did I do wrong?
have you defined LINUX or WINDOWS define in your Makefile?
try
gcc -dM -E - < /dev/null
this prints all the predefined macros.
and here the windows macros.
It looks that gcc doesn't see the macro definition in the #ifdef. I think __linux__ is the correct macro to test. Or even better test for the macros from POSIX and not for Linux alone.
Edit: Probably the best is test for _XOPEN_SOURCE. POSIX imposes that this is defined before any header is included.

Resources