[Techtalk] install from source problem

Meredydd meredydd at everybuddy.com
Wed Mar 24 14:08:23 EST 2004


By the way, for future reference if you ever want to fix this:

strdup() is, in the include files you have, defined as a macro. This 
means that it is in fact expanded (actually, it's pretty much a 
search-and-replace) *before* the compiler gets to it. That file, for 
some reason, attempts to re-prototype the function, which isn't an 
error for a normal function (which it presumably is on the system used 
by the developers of that package), but if it's a macro, instead of:

char * strdup(char * s);

You get:

char * <insert-the-implementation-of-strdup-here>

...which is, unsurprisingly, not what the compiler was expecting. The 
fragments it's choking on are in fact part of the expanded "body" 
macro, which is why the compiler sees them on that line, despite them 
not being anywhere in the .c file. The header file you quoted seems to 
define strdup() as an ordinary function, which would *not* cause this 
problem, but I note that it is a conditional compile (it's inside 
#ifdefs), and I don't think that it does actually get compiled at all.

Meredydd

On Tuesday 23 March 2004 22:32, Alice Moomlyn wrote:
> I was reading through the linuxchix course archives
> when I discovered that my machine does not have
> 'locate' installed.
>
> .......................................
>
> alice at linux:~> locate
> bash: locate: command not found
> alice at linux:~> man locate
> No manual entry for locate
>
> ........................................
>
> So I looked on the net and found what looked to be the
> sources at:
>
> http://www.gnu.org/directory/GNU/findutils.html
>
> I downloaded these sources, and tried to 'make' them,
> but got:
>
> ..................................................
>
>
> nextelem.c:35: parse error before "__extension__"
> nextelem.c:35: `__len' undeclared here (not in a
> function)
> nextelem.c:35: initializer element is not constant
> nextelem.c:35: parse error before "if"
> nextelem.c:35: conflicting types for `__retval'
> nextelem.c:35: previous declaration of `__retval'
> nextelem.c:35: warning: data definition has no type or
> storage class
> nextelem.c:35: parse error before '}' token
> make: *** [nextelem.o] Error 1
>
>
> .................................................
>
>
> So I peak inside nextelem.c and I find:
>
>
> ................................................
>
> #ifdef HAVE_CONFIG_H
> #include <config.h>
> #endif
>
> #include <stdio.h>
> #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
> #include <string.h>
> #else
> #include <strings.h>
> #ifndef strchr
> #define strchr index
> #endif
> #endif
>
> char *strdup (); <============== offending line
> void free ();
>
> .............................................
>
> What does it mean?
> No '__extension__' or '__len' or '__retval' on line
> 35!
>
> But I did find this in string.h:
>
> ....................................................
>
> #if defined __USE_SVID || defined __USE_BSD || defined
> __USE_XOPEN_EXTENDED
> /* Duplicate S, returning an identical malloc'd
> string.  */
> extern char *strdup (__const char *__s) __THROW
> __attribute_malloc__;
> #endif
>
>
> #if defined __USE_GNU && defined __GNUC__
> /* Duplicate S, returning an identical alloca'd
> string.  */
> # define strdupa(s)
>                        \
>   (__extension__
>                        \
>     ({
>                        \
>       __const char *__old = (s);
>                        \
>       size_t __len = strlen (__old) + 1;
>                        \
>       char *__new = (char *) __builtin_alloca (__len);
>                        \
>       (char *) memcpy (__new, __old, __len);
>                        \
>     }))
>
> /* Return an alloca'd copy of at most N bytes of
> string.  */
> # define strndupa(s, n)
>                        \
>   (__extension__
>                        \
>     ({
>                        \
>       __const char *__old = (s);
>                        \
>       size_t __len = strnlen (__old, (n));
>                        \
>       char *__new = (char *) __builtin_alloca (__len +
> 1);                    \
>       __new[__len] = '\0';
>                        \
>       (char *) memcpy (__new, __old, __len);
>                        \
>     }))
> #endif
>
>
> ............................................
>
> No clue what any of it means though 8^<
>
> ............................................
>
> This is what the man-pages say:
>
>
> NAME
>        strdup, strndup, strdupa, strndupa - duplicate
> a string
>
> SYNOPSIS
>        #include <string.h>
>
>        char *strdup(const char *s);
>
>        #define _GNU_SOURCE
>        #include <string.h>
>
>        char *strndup(const char *s, size_t n);
>        char *strdupa(const char *s);
>        char *strndupa(const char *s, size_t n);
>
>
> DESCRIPTION
>        The  strdup()  function  returns a pointer to a
> new string
>        which is a duplicate of the string s.  Memory
> for the  new
>        string  is  obtained with malloc(3), and can be
> freed with
>        free(3).
>
>        The strndup() function is similar, but only
> copies at most
>        n characters. If s is longer than n, only n
> characters are
>        copied, and a terminating NUL is added.
>
>        strdupa and strndupa are similar,  but  use
> alloca(3)  to
>        allocate  the  buffer.  They are only available
> when using
>        the GNU GCC suite, and suffer from  the  same
> limitations
>        described in alloca(3).
>
>
> RETURN VALUE
>        The  strdup() function returns a pointer to the
> duplicated
>        string, or NULL if insufficient memory was
> available.
>
> ....................................................
>
> /me is still clueless.
>
>
>
> =====
> "the only way to learn how to be clever is to say stupid things" -
> anon
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance Tax Center - File online. File on time.
> http://taxes.yahoo.com/filing.html
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/techtalk


More information about the Techtalk mailing list