I am trying to compile a simple C function to handle two stacks of ints and sorting them with specific rules.
I had no problem compiling earlier but I can't anymore. and receive this error message :
make: *** No rule to make target `objs/main.c', needed by `push_swap'. Stop.
Below is my code;
NAME = push_swap
SRC_DIR = srcs
SRC = main.c \
instructions/swap.c \
instructions/rotate.c \
instructions/push.c \
instructions/reverse.c \
utils/check_duplicate.c \
utils/chunk_clear.c \
utils/chunk.c \
utils/ft_error.c \
utils/ft_split.c \
utils/highest.c \
utils/init_stack.c \
utils/is_sorted.c \
utils/lowest.c \
utils/num.c \
utils/tab.c \
sort/five.c \
sort/small.c \
sort/sorter.c \
OBJ_DIR = objs
OBJ = $(addprefix $(OBJ_DIR)/, $(SRC:.c =.o))
HEADER_FOLDER = inc
CC = gcc
CFLAGS = -Werror -Wextra -Wall -I$(HEADER_FOLDER) -g
RM = rm -rf
all: $(NAME)
$(OBJ_DIR):
#mkdir -p $(OBJ_DIR)
#mkdir -p $(OBJ_DIR)/operations
#mkdir -p $(OBJ_DIR)/sorters
#mkdir -p $(OBJ_DIR)/utils
$(NAME): $(OBJ_DIR) $(OBJ)
#cd libft && make && cd ../
#echo "making push_swap ... \033[32mok\033[0m"
#$(CC) $(CFLAGS) -o $(NAME) $(OBJ) $(HEADER)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
#echo "Compiling ... $# \033[32mok\033[0m"
#$(CC) $(CFLAGS) -c $< -o $#
clean:
#cd libft && make clean && cd ../
#echo "Removing object files ... \033[32mok\033[0m"
#$(RM) $(OBJ) $(OBJ_DIR)
fclean:
#cd libft && make fclean && cd ../
#echo "Removing files and program ... \033[32mok\033[0m"
#$(RM) $(NAME) $(OBJ) $(OBJ_DIR)
re: fclean all
.PHONY: all re fclean clean
The problem is that $(SRC:.c =.o) doesn't work because of that space (there are no SRC names ending with ".c " (including the last space).
It should be $(SRC:.c=.o).
Related
I want to include in a random test.c file my own library to test if it works but I can't do it.
Even a simple make all doesn't work, but I'm supposed to have done everything right. I have the impression that my makefile doesn't even compile my .c files in .o
here is my make file:
SRCS = ft_atoi.c ft_isascii.c ft_memchr.c ft_putchar_fd.c ft_strchr.c ft_strlen.c ft_strtrim.c \
ft_bzero.c ft_isdigit.c ft_memcmp.c ft_putendl_fd.c ft_strdup.c ft_strmapi.c ft_substr.c \
ft_calloc.c ft_isprint.cft_memcpy.c ft_putnbr_fd.c ft_strjoin.c ft_strncmp.c ft_tolower.c \
ft_isalnum.c ft_itoa.c ft_memmove.c ft_putstr_fd.c ft_strlcat.c ft_strnstr.c ft_toupper.c \
ft_isalpha.c ft_memccpy.c ft_memset.c ft_split.c ft_strlcpy.c ft_strrchr.c \
\
CC = gcc
CFLAGS = -Wall -Wextra -Werror
HEADER = libft.h
OBJS = $(SRCS:.c=.o)
RM = rm -f
NAME = libft.a
.c.o:
$(CC) $(CFLAGS) -c $< -o ${<:.c=.o}
$(NAME): $(OBJS) $(HEADER)
ar rcs $(NAME) $(OBJS)
all: $(NAME)
clean:
$(RM) $(OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean all
.PHONY: all clean fclean re
I have a little problem on this Makefile, my makefile recompile each time, when I call make command. What is the problem?
CC = gcc -Wall -Werror -Wextra
INC=includes
INC_LIB=libft/includes
SRC_PATH = srcs
OBJ_PATH = srcs
NAME = vital
NAME_CLIENT = client
NAME_SERVER = server
INCLUDES = ./includes/server.h ./includes/client.h
INCLUDES_GCH = ./includes/server.h.gch ./includes/client.h.gch
LIB_PATH = libft
SRC_M_SERVER_PATH = server
SRC_M_CLIENT_PATH = client
################################################
### SOURCES
###############################################
SRC_M_CLIENT = client.c main_client.c manage_put_client.c manage_get_client.c create_client.c usage_builtin.c make_client.c remaster_prompt.c my_send_and_recv.c
SRC_M_SERVER = server.c main_server.c manage_builtin.c ft_put.c create_server.c server_make.c ft_cd.c ft_mkdir.c ft_ls.c ft_pwd.c ft_quit.c ft_get.c network.c get_server_make.c
SRC_M_C = $(addprefix ./$(SRC_M_CLIENT_PATH)/, $(SRC_M_CLIENT))
SRC_M_S = $(addprefix ./$(SRC_M_SERVER_PATH)/, $(SRC_M_SERVER))
###############################################
### OBJECT
##############################################
OBJ_M_CLIENT = $(patsubst %.c, %.o, $(SRC_M_CLIENT))
OBJ_M_SERVER = $(patsubst %.c, %.o, $(SRC_M_SERVER))
OBJ_M_C = $(addprefix ./$(OBJ_PATH)/, $(OBJ_M_CLIENT))
OBJ_M_S = $(addprefix ./$(OBJ_PATH)/, $(OBJ_M_SERVER))
OBJ_ALL = $(OBJ_M_C) $(OBJ_M_S)
####################################################
#################### RULES ########################
.PHONY: all libft clean fclean re
all: $(NAME)
$(NAME): lib $(OBJ_M_C) $(OBJ_M_S)
$(CC) $(OBJ_M_C) $(OBJ_M_U) -L ./libft -lft -o $(NAME_CLIENT)
$(CC) $(OBJ_M_S) $(OBJ_M_U) -L ./libft -lft -o $(NAME_SERVER)
$(OBJ_M_C): $(OBJ_PATH)%.o : $(SRC_PATH)/$(SRC_M_CLIENT_PATH)%.c
$(CC) $(CFLAGS) -I$(INC) -I $(INC_LIB) -c $< -o $#
$(OBJ_M_S) : $(OBJ_PATH)%.o : $(SRC_PATH)/$(SRC_M_SERVER_PATH)%.c
$(CC) $(CFLAGS) -I$(INC) -I $(INC_LIB) -c $< -o $#
lib:
#cd $(LIB_PATH) && make
cleanlib:
#cd $(LIB_PATH) && make clean
#echo "$(COL_WHITE)[ CLEAN LIBFT ]\n"
fcleanlib: cleanlib
#cd $(LIB_PATH) && make fclean
#echo "$(COL_WHITE)[ FCLEAN LIBFT ]\n"
clean: cleanlib
rm -rf $(OBJ_ALL) $(OBJ_M_M) $(INCLUDES_GCH)
fclean: fcleanlib clean
rm -rf $(NAME_CLIENT) $(NAME_SERVER)
re : fclean $(NAME)
When I use make command, it run $(NAME) and launch gcc.
I have this result:
make[1]: Nothing to be done for `all'. (ma lib)
gcc -Wall -Werror -Wextra ./srcs/client.o ./srcs/main_client.o ./srcs/manage_put_client.o ./srcs/manage_get_client.o ./srcs/create_client.o ./srcs/usage_builtin.o ./srcs/make_client.o ./srcs/remaster_prompt.o ./srcs/my_send_and_recv.o -L ./libft -lft -o client
gcc -Wall -Werror -Wextra ./srcs/server.o ./srcs/main_server.o ./srcs/manage_builtin.o ./srcs/ft_put.o ./srcs/create_server.o ./srcs/server_make.o ./srcs/ft_cd.o ./srcs/ft_mkdir.o ./srcs/ft_ls.o ./srcs/ft_pwd.o ./srcs/ft_quit.o ./srcs/ft_get.o ./srcs/network.o ./srcs/get_server_make.o -L ./libft -lft -o server
Any suggestion?
You have not 'made clear' all the details; however, the following Makefile should get you moving in the right direction.
Note: replace all<tab> with a tab
Note: use := so the macros are only evaluated once
CC := /usr/bin/gcc -Wall -Werror -Wextra
RM := /bin/rm -rf
MAKE := /usr/bin/make
INC := includes
INC_LIB := libft/includes
SRC_PATH := srcs
OBJ_PATH := srcs
NAME_CLIENT := client
NAME_SERVER := server
SERVER_INCLUDES := includes/server.h
CLIENT_INCLUDES := includes/client.h
LIB_PATH := libft
SRC_M_SERVER_PATH := server
SRC_M_CLIENT_PATH := client
################################################
### SOURCES
###############################################
SRC_M_CLIENT := client.c \
main_client.c \
manage_put_client.c \
manage_get_client.c \
create_client.c \
usage_builtin.c \
make_client.c \
remaster_prompt.c \
my_send_and_recv.c
SRC_M_SERVER := server.c \
main_server.c \
manage_builtin.c \
ft_put.c \
create_server.c \
server_make.c \
ft_cd.c \
ft_mkdir.c \
ft_ls.c \
ft_pwd.c \
ft_quit.c \
ft_get.c \
network.c \
get_server_make.c
SRC_M_C := $(addprefix ./$(SRC_M_CLIENT_PATH)/, $(SRC_M_CLIENT))
SRC_M_S := $(addprefix ./$(SRC_M_SERVER_PATH)/, $(SRC_M_SERVER))
###############################################
### OBJECT
##############################################
OBJ_M_CLIENT := $(patsubst %.c, %.o, $(SRC_M_CLIENT))
OBJ_M_SERVER := $(patsubst %.c, %.o, $(SRC_M_SERVER))
OBJ_M_C := $(addprefix ./$(OBJ_PATH)/, $(OBJ_M_CLIENT))
OBJ_M_S := $(addprefix ./$(OBJ_PATH)/, $(OBJ_M_SERVER))
####################################################
#################### RULES ########################
.PHONY: all clean libclean
all: $(NAME_CLIENT) $(NAME_SERVER)
# link client
$(NAME_CLIENT) : $(OBJ_M_C)
<tab>$(CC) $^ -o $# -L$(LIB_PATH) -lft
# link server
$(NAME_SERVER) : $(OBJ_M_S)
<tab>$(CC) $^ -o $# -L$(LIB_PATH) -lft
# compile sources
%.o : %.c $(INC_CLIENT) $(INC_SERVER) $(INC)
<tab>$(CC) $(CFLAGS) -c $< -o $# -I$(INC_CLIENT) $(INC_SERVER) -I$(INC)
# is there another Makefile in the $(LIB_PATH) directory?
cleanlib: clean
<tab>(#cd $(LIB_PATH) && $(MAKE) clean)
<tab>#echo "$(COL_WHITE)[ CLEAN LIBFT ]\n"
clean:
<tab>$(RM) $(OBJ_M_C) $(OBJ_M_S)
Change this line:
.PHONY: all libft clean fclean re
to
.PHONY: clean fclean re
.PHONY disables file association checks
I've got a strange issue when I try to compile my code on my laptop.
It gives me this error: undefined reference to 'main' because apparently it cannot see my source files and then the objects either.
However, the same makefile and code work perfectly on my office machine.
here's the makefile. any hints?
thanks a lot for helping me in advance
ROOT = $(addprefix $(PWD), /)
BUILDS_DIR = $(addprefix $(ROOT), builds/)
SRCS_DIR = $(addprefix $(ROOT), src/)
INCS_DIR = $(addprefix $(ROOT), src/)
OBJS_DIR = $(addprefix $(SRCS_DIR), objects/)
LIBS_DIR = ./
SRCS = $(wildcard $(SRCS_DIR)*.c)
OBJS = $(SRCS:$(SRCS_DIR)%.c=$(OBJS_DIR)%.o)
TARGET = INTERP
EXES = $(addprefix $(BUILDS_DIR), $(TARGET))
CC = gcc
CFLAGS = -Wall -O3 -MD -DTRILIBRARY
INCLUDES = -I$(INCS_DIR)
CL = gcc
LFLAGS =
LIBS = -L$(LIBS_DIR) -lm
RM = rm -f
.PHONY: all $(TARGET) distclean clean
default: clean $(TARGET)
$(TARGET): $(OBJS)
#echo -e "\n\n\t\t*** Compiled $(TARGET) successfully! ***\n" ;
$(CL) $(LFLAGS) -o $(BUILDS_DIR)$# \
$(OBJS) \
$(LIBS)
#echo -e "\n\n\t\t*** Linking $(TARGET) completed! ***\n"
$(OBJS): $(OBJS_DIR)%.o : $(SRCS_DIR)%.c
$(CC) $(CFLAGS) $(INCLUDES) \
-c $<\
-o $#
distclean: clean
$(RM) $(EXES)
#echo -e "\n\n\t\t*** Purge $(TARGET) completed! ***\n"
clean:
$(RM) $(OBJS_DIR)*.o \
$(SRCS_DIR)*~
#echo -e "\n\n\t\t*** Cleanup $(TARGET) completed! ***\n"
depend: $(SRCS)
makedepend $(INCLUDES) $^
I'm getting a strange error when building this project. It compiles everything successfully, but on the end, make tells me:
make: *** No rule to make target `cc', needed by `game'. Stop.
Here's the makefile:
TARGET = game
SDL_INC_DIR = /usr/include/SDL
SDL_LIB_DIR = /usr/lib/SDL
CFLAGS = -D __SDL__ -O2 -g -Wall -I$(SDL_INC_DIR)
LDFLAGS = -L$(SDL_LIB_DIR) -lSDL
OBJECTS = game/ai/boost.o \
game/ai/bullet.o \
game/ai/death.o \
game/ai/explode.o \
game/ai/pickup.o \
game/ai/quad.o \
game/ai/sheba.o \
game/ai/static_model.o \
game/ai/static_sprite.o \
game/ai/teleporter.o \
game/ai/torch.o \
game/data.o \
game/entities.o \
game/game.o \
game/maps.o \
game/models.o \
game/screens.o \
game/sprites.o \
platform/main.o
$(TARGET): $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
clean:
rm -f *.o game/*.o game/ai/*.o
You need to put $(CC) and the rest on the next line, after a tab:
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
It was able to compile the target successfully anyway using the default rule.
$(CC) is not defined. Add $(CC)=gcc also put it on a new line otherwise it will take them as dependencies
I have a makefile that I am using to generate artifacts using a third party IDL compiler (rtiddsgen). This takes in idl files and spits out C/Ada files relating to them. The C files are then compiled and put into a library (idl_dds_types.a)
I have the IDL files listed in the IDL_TYPES variable. Each IDL_TYPES file will generate (through rtiddsgen) files of the following form (For example with alerts.idl):
alerts.c
alerts.h
alerts_idl.ads
alerts_idl.adb
So, what I want to happen is when alerts.idl's timestamp is newer than the alerts.c (or the obj.Linux-i686/alerts.o) file, then the alerts.c file is regenerated. This doesn't seem to be happening. Any ideas what I need to do to make this happen? I've tested by "touch"-ing the idl file and then re-running make.
Here is the makefile:
DDS_OUT_DIR = $(MY_HOME)/DDS/DDS_Types/src
IDL_DIR=$(MY_HOME)/DDS/DDS_Types/IDL
IDL_TYPES=common.idl alerts.idl summary.idl
GENERATED_SOURCES = $(IDL_TYPES:%.idl=%.c)
GENERATED_HEADERS = $(IDL_TYPES:%.idl=%.h)
LIBNAME = idl_dds_types
OBJS_DIR = obj.$(CPUTYPE)
GENERATED_OBJS = $(GENERATED_SOURCES:%.c=$(OBJS_DIR)/%.o)
LIBDIR = $(DDS_OUT_DIR)/../../lib.$(CPUTYPE)
BINDIR = $(DDS_OUT_DIR)/../../../../bin.$(CPUTYPE)
CC = $(C_COMPILER)
CXX = $(CPP_COMPILER)
OS = $(shell uname)
DDSCOMMON = $(DDS_OUT_DIR)/../../Common/src
CFLAGS = -m32 -g -DRTI_UNIX -DRTI_32BIT
CXXFLAGS = -m32 -g
LDFLAGS = -m32 -static-libgcc
SYSLIBS = -ldl -lnsl -lpthread -lm -lc
DEFINES_ARCH_SPECIFIC = -DRTI_UNIX
DEFINES = $(DEFINES_ARCH_SPECIFIC) $(cxx_DEFINES_ARCH_SPECIFIC)
INCLUDES = -I. -I$(NDDSHOME)/include -I$(NDDSHOME)/include/ndds
INCLUDES += -I$(DDSCOMMON)
LIBS = -L$(NDDSLIBDIR) -L$(LIBDIR) -lrt \
-lnddscppz -lnddscz -lnddscorez $(SYSLIBS) $(OS_SPECIFIC_LIBS)
COMMONLIBSRC = $(DDSCOMMON)/dds_common.cxx
COMMONLIBOBJS = $(DDSCOMMON)/obj.$(CPUTYPE)/%.o
$(shell mkdir -p $(OBJS_DIR) $(DDSCOMMON)/obj.$(CPUTYPE) $(DDS_CPP_DIR))
default: $(GENERATED_OBJS) $(LIBDIR)/lib$(LIBNAME).a
$(OBJS_DIR)/%.o : %.idl $(DDSCOMMON)/dds_common.h
$(C_COMPILER) -o $(OBJS_DIR)/$(*F).o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F).c; \
$(C_COMPILER) -o $(OBJS_DIR)/$(*F)Support.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Support.c; \
$(C_COMPILER) -o $(OBJS_DIR)/$(*F)Plugin.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Plugin.c; \
$(LIBDIR)/lib$(LIBNAME).a: $(GENERATED_OBJS) $(CPP_OBJS)
#echo "Adding these to lib: " $(OBJS_DIR)/*.o; \
mkdir -p $(LIBDIR)
rm -f $(LIBDIR)/lib$(LIBNAME).a
$(AR) -cr $(LIBDIR)/lib$(LIBNAME).a $(OBJS_DIR)/*.o
ranlib $(LIBDIR)/lib$(LIBNAME).a
%.idl:
#echo "Generating C and Ada from $# ..."; \
$(NDDSHOME)/scripts/rtiddsgen ${IDL_DIR}/$# -d $(DDS_OUT_DIR) -I ${IDL_DIR} -replace -language Ada; # -example i86Linux2.6gcc4.1.2;
clean:
rm -rf $(LIBDIR)/lib$(LIBNAME).a; \
rm -rf $(DDS_OUT_DIR)/*.h; \
rm -rf $(DDS_OUT_DIR)/*.c; \
rm -rf $(DDS_OUT_DIR)/*.gpr; \
rm -rf $(DDS_OUT_DIR)/samples; \
rm -rf $(DDS_OUT_DIR)/*.xml; \
rm -rf $(DDS_OUT_DIR)/makefile_*; \
rm -rf $(DDS_OUT_DIR)/bin; \
rm -rf $(DDS_OUT_DIR)/summary_idl*; \
rm -rf $(DDS_OUT_DIR)/common_idl*; \
rm -rf $(DDS_OUT_DIR)/alerts_idl*; \
rm -rf $(DDS_OUT_DIR)/$(OBJS_DIR);
A rule like your %.idl: rule tells make how to generate .idl files, not how to generate things from .idl files. You want to change this to %.c: %.idl -- how to generate .c files from .idl files.
That will do most of what you want -- the only problem is if you ever want to be able to generate .ads/.adb files WITHOUT generating .c files or rebuilding the library.