Ultimaker / cura-build-environment

CMake project to build dependencies for Cura
GNU Affero General Public License v3.0
24 stars 55 forks source link

error: 'strdup' was not declared in this scope #72

Closed henryprobosantoso closed 5 years ago

henryprobosantoso commented 5 years ago

i was tryng to build cura by following this link https://github.com/Ultimaker/Cura/wiki/Running-Cura-from-Source-on-Windows and now i stuck at this point when i run mingw32-make to build protobuf-3.0.0-mingw for cura engine.

image

i am using windows 10, visual basic 2015, everything was exactly same like the link. Please help to solve that, thank you.

Ghostkeeper commented 5 years ago

Looks like you need to set CXX_STANDARD to 11 in CMake.

I wonder if that needs to be done by default from our CMake file or whether it always needs to be set by the user. Or maybe you unset it somewhere by accident?

henryprobosantoso commented 5 years ago

thank you for your reply, the problem was solve by adding two files strdup.c and strdup.h

with content strdup.c

/*
 * C Source File
 *
 * Author: Davide Di Carlo
 * Date:   February 12, 2017 
 * email:  daddinuz@gmal.com
 */

#include <stdlib.h>
#include <string.h>
#include "strdup.h"

/*********************************
 * Public functions definitions
 */
char *strdup(const char *s) {
    return strndup(s, strlen(s));
}

char *strndup(const char *s, size_t n) {
    if (NULL == s) {
        return NULL;
    }
    char *buffer = calloc(n + 1, sizeof(char));
    if (NULL != buffer) {
        strncpy(buffer, s, n);
    }
    return buffer;
}

with content strdup.h

/*
 * C Header File
 *
 * Author: Davide Di Carlo
 * Date:   February 12, 2017 
 * email:  daddinuz@gmal.com
 */

#include <stddef.h>

#ifndef __STRDUP_H__
#define __STRDUP_H__

#define STRDUP_VERSION "0.1.0"

#ifdef __cplusplus
extern "C" {
#endif

extern char *strdup(const char *s);
extern char *strndup(const char *s, size_t n);

#ifdef __cplusplus
}
#endif

#endif /* __STRDUP_H__ */

and now i am successfully build and install protobuf, but i don't know about adding thats 2 files because i got that ways from forum, would it be a problem later ? thanks.

Ghostkeeper commented 5 years ago

I think you'll be fine later.

The reason I was suggesting to add the C++11 compilation flag was because some compilers compile strict by default unless you have the C++ version there. Since strdup is not in the standard C but in the std, it wouldn't get included.

But if your solution works, that's fine too. If it completed the Protobuf compiler stage, the next stage is completely separately compiled anyway so you won't see any effects later in the build process.