I have a program that compiles on both MacOS and Linux. In my makefile, I define a variable:
# MAC
ifeq ($(UNAME), Darwin)
OS = APPLE
#LINUX
else
OS = LINUX
endif
INCLUDES = -Iincludes -Ilibft -I$(MLX_DIR) -D$(OS)
Leading to the following compilation:
gcc -Wall -Wextra -Werror -O3 -Iincludes -Ilibft -I./minilibx_mms -DAPPLE -c srcs/parser/parser.c -o objs/parser/parser.o
gcc -Wall -Wextra -Werror -O3 -Iincludes -Ilibft -I./minilibx_mms -DAPPLE -c srcs/terminate/gameover_sys.c -o objs/terminate/gameover_sys.o
As you can see, I am passing APPLE
as a macro so when I call this function:
if (cub->mlx)
{
#ifdef LINUX
mlx_destroy_display(cub->mlx);
#endif
free(cub->mlx);
}
Everything between the #ifdef
and #endif
should be removed before compilation, right? But alas, I am getting this error from the compiler:
Call to undeclared function 'mlx_destroy_display'; ISO C99 and later do not support implicit function declarations clang(-Wimplicit-function-declaration)
The function only exists in the Linux implementation of the library. Where is my understanding of preprocessor directives incorrect? To my understanding the whole #ifdef LINUX
part should be removed when the LINUX
macro is not present.