Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC compile error : declaration of ‘strlen’ must be available

My problem is that when I want to make a downloaded library I get some weird compile errors from GCC and the code that the compiler demands to correct seems just to be right.

The errors are all like this:

Catalogue.h:96: error: there are no arguments to ‘strlen’ that depend on a template parameter, so a declaration of ‘strlen’ must be available

Here is the code around line 96:

GaCatalogueEntry(const char* name, T* data)
{
    if( name )
    {
        _nameLength = (int)strlen( name ); // LINE 96

        // copy name
        _name = new char[ _nameLength + 1 ];
        strcpy( _name, name );       // LINE 100: similar error

        _data = data;

        return;
    }

    _name = NULL;
    _nameLength = 0;
    _data = NULL;
}

What can I do to fix these compile errors?

like image 419
Navid Avatar asked Oct 27 '09 08:10

Navid


4 Answers

You probably just need to include the header that contains the strcpy and strlen library functions.

#include <string.h>

or (preferably for C++)

#include <cstring>
like image 180
Charles Salvia Avatar answered Nov 04 '22 12:11

Charles Salvia


In C++ the strlen() function is part of the string library, and it almost looks like the header file was not included.

Is it included anywhere?

include <string.h>

If not, try adding it and see if that fixes the problem.

like image 32
Andre Miller Avatar answered Nov 04 '22 13:11

Andre Miller


The code is buggy. You are probably missing an #include <string.h>.

If you don't want to change the code, add -fpermissive to the compiler options. (See the GCC documentation.)

like image 3
Prof. Falken Avatar answered Nov 04 '22 12:11

Prof. Falken


a declaration of ‘strlen’ must be available

Include string.h or <cstring> (C++) for the declaration of strlen().

like image 1
Michael Foukarakis Avatar answered Nov 04 '22 11:11

Michael Foukarakis