Hi,

I am trying to compile an open source code on linux Ubuntu and getting the following error:
conflicting types for ‘strlen’

I am pasting the program in which it is giving me the error :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "port.h"

/*
 * strstr - find first occurrence of wanted in s
 */

char *                          /* found string, or NULL if none */
strstr(s, wanted)
CONST char *s;
CONST char *wanted;
{
        register CONST char *scan;
        register SIZET len;
        register char firstc;
        extern int strncmp();
        extern SIZET strlen(const char *);

        /*
         * The odd placement of the two tests is so "" is findable.
         * Also, we inline the first char for speed.
         * The ++ on scan has been moved down for optimization.
         */
        firstc = *wanted;
        len = strlen(wanted);
        for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
                if (*scan++ == '\0')
                        return NULL;
        return scan;
}

I cannot figure out why is this error coming and how to resolve it.
Any help is appreciated.

Thanks

Dani AI

Generated

Brief diagnosis and focused fixes for the two problems in this thread.

The "conflicting types for strlen" means the source file is introducing a prototype that differs from the one in <string.h>. The old code uses project macros (SIZET, CONST) and an explicit extern prototype; if those macros do not expand to exactly the same types that the system header uses (for example size_t/const), the compiler sees two different declarations and emits the conflict. The simplest, safest fix is to remove the local strlen prototype and rely on the declaration from <string.h>. As a more robust step, modernize the file to ANSI C: give strstr an ANSI-style prototype (char *strstr(const char *haystack, const char *needle)), eliminate redundant extern declarations for standard library functions (e.g. strncmp), and check port.h for what SIZET and CONST actually expand to.

The make failure (lint: Command not found, exit 127) is separate: the Makefile is invoking the historical lint program which is not installed by default on Ubuntu. Two pragmatic approaches:

  • Install a lint tool (Debian/Ubuntu have splint) and adapt the Makefile if the flags differ:

    sudo apt-get update
    sudo apt-get install splint
  • Or edit the Makefile to skip the lint step (locate the llib-lport.ln target or the lint -I... line and comment it out or replace it with a no-op like : or true) so the build proceeds.

Combine both lines of work: first fix the prototype mismatch (as pointed out) and standardize types in port.h, then address the Makefile's lint invocation (as suggested) so make can finish. After changes run make clean and rebuild; enable extra compiler warnings (-Wall -Wextra -std=c99) to catch remaining prototype/type issues.

Recommended Answers

All 3 Replies

Delete line 19 because the prototype on that line is probably not the same as the prototype found in string.h. Why prototype something twice ?

Thanks for your reply. That error got resolved but now I am having another error.

I am pasting the output after compilation:

lint -I../include  '-DCADROOT="~octtools"' -Cport -n dummy.c memccpy.c memchr.c memcmp.c memcpy.c memset.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c strerror.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strspn.c strstr.c strtok.c
make[1]: lint: Command not found
make[1]: *** [llib-lport.ln] Error 127

Why is this error coming....Thanks

Delete line 19 because the prototype on that line is probably not the same as the prototype found in string.h. Why prototype something twice ?

Where did you get this? You must be an archaeologist. The code truly belongs to the past millenium.

The error comes from make, which tries to call lint. Lint is morally obsolete tool (again from seventies), which purpose was to validate the program syntax in such details the old compilers didn't bother to check. You have two choices. Either edit a makefile to remove the lint invocation, or do another digging session to find and install lint.

commented: Haven't used lint for over 25 years :) +27
commented: LOL +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.