I encountered very strange issue. I am using readlink in one of my functions:
#include <unistd.h>
#include "../logger/logger.h"
#include "../string/string.h"
bool path_retrieve_executable_filepath(char exe_filepath[PATH_MAX_SIZE]) {
string_copy(exe_filepath, PATH_MAX_SIZE, "");
ssize_t len = readlink("/proc/self/exe", exe_filepath, PATH_MAX_SIZE - 1);
if (len == -1) {
log_error("Unable to retrieve executable directory");
return false;
}
exe_filepath[len] = '\0';
return true;
}
I have defined and set _POSIX1_SOURCE to 2 in my Makefile:
CC = gcc
DEFINES = -DVK_NO_PROTOTYPES -D_POSIX1_SOURCE=2 -DDEBUG
# compiling flags here
# CFLAGS = -std=c11 -flto -O3 -march=native
CFLAGS = -std=c11 -Wall -g3
LINKER = gcc -o
# linking flags here
LFLAGS = -flto -O3 -march=native -lm -lSDL2
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(DEFINES) $(INCLUDE_DIRS) -c $< -o $@
@echo "Compiled "$<" successfully!"
The gcc is giving me implicit-function-declaration warning although a) the readlink function should be defined b) the function is working correctly once run. The details of the warning:
src/file/path.c:10:19: warning: implicit declaration of function ‘readlink’; did you mean ‘realloc’? [-Wimplicit-function-declaration]
ssize_t len = readlink("/proc/self/exe", exe_filepath, PATH_MAX_SIZE - 1);
^~~~~~~~
realloc
Any ideas on how to get rid of the warning? Am I doing anything incorrectly?