views:

755

answers:

4

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?

+2  A: 

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.)

Amigable Clark Kant
+4  A: 

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>
Charles Salvia
much better ! (and you have to use std::strlen() instead of just strlen).
Ben
+3  A: 

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.

Andre Miller
Yes, the problem was the missing header file. but I think error messages are not as leading as languages such as java.
Navid
In this case, the cause of the error was obfuscated somewhat by the fact that the code was part of a template. The compiler found an unidentified symbol in the template, which wouldn't even have caused an error until the template was actually instantiated if the unidentified symbol was dependent on the template parameter T, (e.g. if the symbol was something like T::dosomething())
Charles Salvia
A: 

a declaration of ‘strlen’ must be available

Include string.h for the declaration of strlen().

Michael Foukarakis