Alura, por favor, podem ajudar? Tentei compilar o programa de exemplo do Json escrito em linguagem C abaixo:
#include <stdio.h>
#include <cjson/cJSON.h>
int main() {
// create a cJSON object
cJSON *json = cJSON_CreateObject();
cJSON_AddStringToObject(json, "name", "John Doe");
cJSON_AddNumberToObject(json, "age", 30);
cJSON_AddStringToObject(json, "email", "john.doe@example.com");
// convert the cJSON object to a JSON string
char *json_str = cJSON_Print(json);
// write the JSON string to a file
FILE *fp = fopen("data.json", "w");
if (fp == NULL) {
printf("Error: Unable to open the file.\n");
return 1;
}
printf("%s\n", json_str);
fputs(json_str, fp);
fclose
// free the JSON string and cJSON object
cJSON_free(json_str);
cJSON_Delete(json);
return 0;
}
utilizando o seguinte makefile:
# your Makefile, replace four spaces with tab
CC=gcc
CFLAGS+=-Wall -Wextra -g
RM=rm -f
MY_SOURCES=$(wildcard *.c)
## above could be an MY_SOURCES= file1.c file2.c otherfile.c
MY_OBJECTS=$(patsubst %.c,%.o,$(MY_SOURCES))
#
LIBES=-lcjson
#
.PHONY:all clean
##
all:myprog
##
clean:
$(RM)myprog *.o *~
myprog:$(MY_OBJECTS)
₢
O gcc está me devolvendo: main.c:2:10: fatal error: cjson/cJSON.h: No such file or directory )