[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compiling cdb 0.75 on gentoo linux



On linux, if threads are usable (that is, if the C library is configured
to be fully reentrant), the global errno variable is implemented
differently -- on a per-thread basis.  This involves a preprocessor
define of 'errno', such that referencing 'errno' actually calls a
function returning a pointer to an integer, and dereferences the
returned pointer.

In the case of cdb, to avoid including errno.h, the library assumes that
'errno' follows standard semantics as a global integer, and explicitly
declares errno externally; e.g.:

  extern int errno;

In this case, since errno.h is not included, the define is inactive, yet
the C library does not support errno as a global symbol.  The cdb
functions use this external variable without it ever having been
defined.

To correct the issue, add

  #include <errno.h>

to the head of each file that uses errno:

-------------------------------------------------------
$ grep -l errno *.c
alloc.c
buffer_get.c
buffer_put.c
cdb.c
cdb_make.c
cdbmake.c
error.c
error_str.c
install.c
instcheck.c
strerr_sys.c
-------------------------------------------------------

ari


edelkind-debug@episec.com wrote:

> 'make' fails with the following error:
> 
> -------------------------------------------------------
> ./compile uint32_pack.c
> ./compile scan_ulong.c
> ./makelib byte.a byte_copy.o byte_cr.o str_len.o \
> fmt_ulong.o uint32_unpack.o byte_diff.o uint32_pack.o \
> scan_ulong.o
> ./load cdbget cdb.a buffer.a unix.a byte.a 
> cdb.a(cdb.o)(.text+0x10e): In function `cdb_read':
> : undefined reference to `errno'
> cdb.a(cdb.o)(.text+0x18b): In function `cdb_read':
> : undefined reference to `errno'
> buffer.a(strerr_sys.o)(.text+0x9): In function `strerr_sysinit':
> : undefined reference to `errno'
> buffer.a(buffer_put.o)(.text+0x47): In function `allwrite':
> : undefined reference to `errno'
> collect2: ld returned 1 exit status
> make: *** [cdbget] Error 1
> -------------------------------------------------------
> 
> The libraries compile fine; upon linking the binaries, the above
> "undefined reference to `errno'" errors appear.
> 
> Researching.
> 
> ari