I am currently creating (well at least I'm trying) to create a makefile for a software project.
Since I never used make before I quickly ran into problems.
The software project contains of many subfolders and subsubfolders containing source and header files.
Those files should be collected recursivly and after that beeing build and linked using cross arm toolchain.
The current makefile looks as following:
RM := rm -rf
# Every subdirectory with source files must be described here
DIR := \
D:/foxmake/
SUBDIRS := \
src/test \
src/test/usb_cdc_lolevel \
src/os \
src/os/FreeRTOS/Source \
src/os/FreeRTOS/Source/portable/MemMang \
src/os/FreeRTOS/Source/portable/GCC/ARM_CM4F \
src/os/FreeRTOS/Source/CMSIS_RTOS \
src/module/uart \
src/module/spi \
src/module/rcc \
src/module/ltc \
src/module/irq \
src/module/io \
src/module/eeprom \
src/module/dma \
src/module/cpu \
src/module/contactor \
src/module/config \
src/module/com \
src/module/can \
src/module/adc \
src/hal/STM32F4xx_HAL_Driver/Src \
src/general \
src/general/config \
src/engine/task \
src/engine/sysctrl \
src/engine/sof \
src/engine/soc \
src/engine/isoguard \
src/engine/diag \
src/engine/database \
src/engine/config \
src/application/task \
src/application/config \
CFLAGS := \
-mcpu=cortex-m4 \
-mthumb -mlittle-endian \
-mfloat-abi=softfp \
-mfpu=fpv4-sp-d16 \
-O0 \
-fmessage-length=0 \
-fsigned-char \
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fno-move-loop-invariants \
-Wall \
-g3 \
-std=gnu11 \
-DSTM32F429xx \
-DDEBUG \
-DUSE_FULL_ASSERT \
-DTRACE \
-DOS_USE_TRACE_ITM \
-DUSE_HAL_DRIVER \
-DHSE_VALUE=8000000
INCDIRS := \
-I"D:/foxmake/src/application" \
-I"D:/foxmake/src/application/config" \
-I"D:/foxmake/src/application/task" \
-I"D:/foxmake/src/module/adc" \
-I"D:/foxmake/src/module/can" \
-I"D:/foxmake/src/module/com" \
-I"D:/foxmake/src/module/config" \
-I"D:/foxmake/src/module/contactor" \
-I"D:/foxmake/src/module/cpuload" \
-I"D:/foxmake/src/module/io" \
-I"D:/foxmake/src/module/ltc" \
-I"D:/foxmake/src/module/spi" \
-I"D:/foxmake/src/module/uart" \
-I"D:/foxmake/src/engine/config" \
-I"D:/foxmake/src/engine/database" \
-I"D:/foxmake/src/engine/diag" \
-I"D:/foxmake/src/engine/isoguard" \
-I"D:/foxmake/src/engine/soc" \
-I"D:/foxmake/src/engine/sof" \
-I"D:/foxmake/src/engine/sysctrl" \
-I"D:/foxmake/src/engine/task" \
-I"D:/foxmake/src/general" \
-I"D:/foxmake/src/general/config" \
-I"D:/foxmake/src/general/includes" \
-I"D:/foxmake/src/hal/CMSIS/Device/ST/STM32F4xx/Include" \
-I"D:/foxmake/src/hal/CMSIS/Include" \
-I"D:/foxmake/src/hal/STM32F4xx_HAL_Driver/Inc" \
-I"D:/foxmake/src/os" \
-I"D:/foxmake/src/os/FreeRTOS" \
-I"D:/foxmake/src/os/FreeRTOS/Source" \
-I"D:/foxmake/src/os/FreeRTOS/Source/include" \
-I"D:/foxmake/src/os/FreeRTOS/Source/CMSIS_RTOS" \
-I"D:/foxmake/src/os/FreeRTOS/Source/portable/GCC/ARM_CM4F" \
-I"D:/foxmake/src/test" \
-I"D:/foxmake/src/module/cpu" \
-I"D:/foxmake/src/module/dma" \
-I"D:/foxmake/src/module/irq" \
-I"D:/foxmake/src/module/rcc" \
-I"D:/foxmake/src/test/usb_cdc_lolevel"
S_UPPER_SRCS := \
$(DIR)src/general/config/startup_stm32f429xx.S
S_UPPER_DEPS := \
./src/general/config/startup_stm32f429xx.d
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
# All of the sources participating in the build are defined here
C_SRCS := \
$(call rwildcard, , *.c)
#$(info C_SRCS='$(C_SRCS)')
OBJDIR := objdir
OBJS := \
$(patsubst %.c,%.o,$(C_SRCS))
#$(error OBJS='$(OBJS)')
# comment the above line once OBJS is ok.
C_DEPS := \
$(patsubst %.c,%.d,$(C_SRCS))
#$(info C_DEPS='$(C_DEPS)')
%.o: %.c ,$(C_SRCS)
echo 'Building file: $<'
echo 'Invoking: Cross ARM C Compiler'
arm-none-eabi-gcc $(CFLAGS) $(INCDIRS) -MMD -MP -MF"$(#:%.o=%.d)" -MT"$#" -c -o "$#" "$<"
echo 'Finished building: $<'
echo ' '
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
SECONDARY_FLASH := \
foxbms.hex \
SECONDARY_LIST := \
foxbms.lst \
SECONDARY_SIZE := \
foxbms.siz \
# All Target
all: foxbms.elf secondary-outputs
# Tool invocations
foxbms.elf: $(OBJS) $(USER_OBJS)
#echo 'Building target: $#'
#echo 'Invoking: Cross ARM C++ Linker'
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mlittle-endian -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -g3 -T "D:/foxmake/src/STM32F429ZIT6_FLASH.ld" -Xlinker --gc-sections -Wl,-Map,"foxbms.map" --specs=nano.specs -o "foxbms.elf" $(OBJS) $(USER_OBJS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
$(MAKE) --no-print-directory post-build
foxbms.hex: foxbms.elf
#echo 'Invoking: Cross ARM GNU Create Flash Image'
arm-none-eabi-objcopy -O ihex "foxbms.elf" "foxbms.hex"
#echo 'Finished building: $#'
#echo ' '
foxbms.lst: foxbms.elf
#echo 'Invoking: Cross ARM GNU Create Listing'
arm-none-eabi-objdump --source --all-headers --demangle --line-numbers --wide "foxbms.elf" > "foxbms.lst"
#echo 'Finished building: $#'
#echo ' '
foxbms.siz: foxbms.elf
#echo 'Invoking: Cross ARM GNU Print Size'
arm-none-eabi-size --format=berkeley $(OBJS) "foxbms.elf"
#echo 'Finished building: $#'
#echo ' '
# Other Targets
clean:
-$(RM) \
$(CC_DEPS) \
$(C++_DEPS) \
$(OBJS) \
$(C_UPPER_DEPS) \
$(CXX_DEPS) \
$(SECONDARY_FLASH) \
$(SECONDARY_LIST) \
$(SECONDARY_SIZE) \
$(ASM_DEPS) \
$(S_UPPER_DEPS) \
$(C_DEPS) \
$(CPP_DEPS) \
foxbms.elf
-#echo ' '
post-build:
-#echo 'Create binary'
-arm-none-eabi-objcopy -O binary "foxbms.elf" "foxbms.bin"
-#echo ' '
secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_LIST) $(SECONDARY_SIZE)
.PHONY: all clean dependents x
.SECONDARY: post-build
using eclipse to execute this makefile gives me this error:
make all
cc -mcpu=cortex-m4 -mthumb -mlittle-endian -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -g3 -std=gnu11 -DSTM32F429xx -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_ITM -DUSE_HAL_DRIVER -DHSE_VALUE=8000000 -c -o src/general/nvic.o src/general/nvic.c
<builtin>: recipe for target 'src/general/nvic.o' failed
process_begin: CreateProcess(NULL, cc -mcpu=cortex-m4 -mthumb -mlittle-endian -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -g3 -std=gnu11 -DSTM32F429xx -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_ITM -DUSE_HAL_DRIVER -DHSE_VALUE=8000000 -c -o src/general/nvic.o src/general/nvic.c, ...) failed.
make (e=2): System is unable to find the given file.
make: *** [src/general/nvic.o] Error 2
Anyone knows why my makefile fails?
What's wrong with the rule "%.o: %.c ,$(C_SRCS)"?
Related
I am trying to compile my code on my Ubuntu x64 laptop for the Raspberry Pi.
I am able to compile and run the code on Ubuntu laptop without any issue. However when I try to compile it for Raspberry Pi I get the following error:
$make
/home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc -g -Wall -Wextra -I /home/nmohan/github/NiRobot/inc -fPIC -shared -L/home/nmohan/github/NiRobot/Obj_arm -Wl,-rpath=/home/nmohan/github/NiRobot/Obj -o /home/nmohan/github/NiRobot/Obj_arm/libRSXA.so /home/nmohan/github/NiRobot/lib/RSXA.c -lNMT_stdlib -lNMT_log -ljson-c -lc -Ljson-c
/home/nmohan/github/NiRobot/lib/RSXA.c:11:25: fatal error: json-c/json.h: No such file or directory
compilation terminated.
Makefile:101: recipe for target '/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so' failed
make: *** [/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so] Error 1
#---------------------------------------#
# #
# Global Varibles #
# #
#---------------------------------------#
PROJ_DIR = /home/nmohan/github/NiRobot
BIN_DIR = $(PROJ_DIR)/bin
OBJ_DIR = $(PROJ_DIR)/Obj
OBJ_DIR_ARM = $(PROJ_DIR)/Obj_arm
INC_DIR = $(PROJ_DIR)/inc
LIB_DIR = $(PROJ_DIR)/lib
OUT_DIR = $(PROJ_DIR)/bld
OUT_DIR_ARM = $(PROJ_DIR)/bld_arm
CFLAGS = -g -Wall -Wextra -I $(INC_DIR)
SFLAGS = -fPIC -shared
RPATH = -L$(OBJ_DIR) -Wl,-rpath=$(OBJ_DIR)
RPATH_ARM = -L$(OBJ_DIR_ARM) -Wl,-rpath=$(OBJ_DIR)
GCC_DIR = /home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc
#---------------------------------------#
# #
# Targets #
# #
#---------------------------------------#
OBJS = NMT_stdlib.so \
NMT_log.so \
RSXA.so \
PCA9685.so \
MTDR.so \
CAM_MOTOR_CTRL.so \
HCxSR04.so
#---------------------------------------#
# #
# Dependancies #
# #
#---------------------------------------#
NMT_STDLIB_LIBS = -lc
NMT_LOG_LIBS = -lc \
-lNMT_stdlib \
RSXA_LIBS = -lNMT_stdlib \
-lNMT_log \
-ljson-c \
-lc
PCA9685_LIBS = -lNMT_stdlib \
-lNMT_log \
-lc \
-lwiringPi \
-lcrypt \
-lm \
-lrt \
-lRSXA
MTDR_LIBS = -lNMT_stdlib \
-lNMT_log \
-lwiringPi \
-lPCA9685 \
-lcrypt \
-lm \
-lrt \
-lRSXA
CAM_MOTOR_CTRL_LIBS = -lNMT_stdlib \
-lNMT_log \
-lwiringPi \
-lMTDR \
-lPCA9685 \
-lcrypt \
-lm \
-lrt \
-lRSXA
HCxSR04_LIBS = -lNMT_log \
-lNMT_stdlib \
-lRSXA \
-lwiringPi \
-lcrypt \
-lm \
-lrt
TARGET_OBJS := $(foreach OBJ,$(OBJS),$(OBJ_DIR)/lib$(OBJ))
TARGET_OBJS_ARM := $(foreach OBJ,$(OBJS),$(OBJ_DIR_ARM)/lib$(OBJ))
all: $(TARGET_OBJS) \
$(TARGET_OBJS_ARM)
.PHONY: all
$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
gcc $(CFLAGS) $(SFLAGS) $(RPATH) -o $# $< $($(*)_LIBS)
$(OBJ_DIR_ARM)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
$(GCC_DIR) $(CFLAGS) $(SFLAGS) $(RPATH_ARM) -o $# $< $($(*)_LIBS)
$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.cpp $(INC_DIR)/%.hpp
g++ $(CFLAGS) $(SFLAGS) $(RPATH) -o $# $< $($(*)_LIBS)
It depends on json-c/json.h. You need to include these files that were not found.
Installing libjson-c-dev package.
sudo apt install libjson-c-dev
I've had a similar problem. It's because of the json.h which is not part of the, in my case, gcc-arm-10-3-2017.07...-aarch64-none-linux-gnu.
I simply cloned json-c git and compiled it with the cross-compiler, too. Then you can reference to the output, or you can inlcude the whole git into your project and compile it all in one.
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'm using GNU Automake and libtool to compile my program. My Makefile.am looks like this:
lib_LTLIBRARIES = \
libObjectively.la
libObjectively_la_SOURCES = \
Array.c \
Class.c \
Condition.c \
Date.c \
DateFormatter.c \
Dictionary.c \
Lock.c \
Log.c \
Object.c \
String.c \
Thread.c
libObjectively_la_CFLAGS = \
-I ..
libObjectively_la_LDFLAGS = \
-pthread \
-shared
Everything compiles just fine. However, I would like to set CFLAGS for each source file using a pattern rule as well. In regular old Makefile syntax, this would look something like:
%.o: %.c
$(CC) $(CFLAGS) -D__Class=$(subst .o,,$#) -o $# $<
Is there a way to do this with Automake + libtool?
Turns out, there is no portable way to do this sort of thing.
I am writing a program in C that uses SDL2 on Cygwin. The problem I am having is that argc is always 1, even when the command line does contain other arguments.
This is a bit difficult to replicate as I can't post all the code for this program, but I can include the main source here to make sure my main function is correct.
My question is if there is any known reason why argc would always be 1 and not include other command line arguments (weather this be intentionally or a side effect from using SDL2 etc)?
This is the code i'm using:
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
#include <string.h>
#ifdef SIGNAL_AVAIL
#include <signal.h>
#endif
#include "process.h"
#include "nvconsole.h"
#include "stringutils.h"
#include "nova.h"
struct NovaContext_s *context; // Nova system context
#ifdef SIGNAL_AVAIL
// #### Signal Handler ####
void sig_handler(int signo)
{
if (signo == SIGINT)
{
NVConsole_print(NVInfo,"Terminated by user");
NVConsole_println(NVInfo,"");
Nova_cleanUp(context);
exit(0);
}
}
#endif
void init()
{
#ifdef SIGNAL_AVAIL
if (signal(SIGINT, sig_handler) == SIG_ERR)
{
NVConsole_println(NVError,"[main] Can't catch SIGINT");
exit(1);
}
if (signal(SIGQUIT, sig_handler) == SIG_ERR)
{
NVConsole_println(NVError,"[main] Can't catch SIGQUIT");
exit(1);
}
#endif
}
int main(int argc, char* argv[]) {
for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]);
init();
context = Nova_createContext();
Nova_init(context);
Nova_loop(context,0);
Nova_cleanUp(context);
return 0;
}
Although this code doesn't directly use SDL, it is being linked and is used by other parts of the included code. I get the below output from this:
$ ./bin/nova
0 F:\dev\nova\bin\nova.exe
$ ./bin/nova hello
0 F:\dev\nova\bin\nova.exe
I've included the makefile below:
ARCH = $(shell uname)
CXX=gcc -std=c99
ifeq ($(ARCH), Darwin)
SDLFLAGS = `/usr/local/bin/sdl2-config --cflags`
SDLLIBS = `/usr/local/bin/sdl2-config --libs`
else
SDLFLAGS = `sdl2-config --cflags`
SDLLIBS = `sdl2-config --libs`
endif
#OPT= -O2 -s -D_GNU_SOURCE
OPT= -O2 -D_GNU_SOURCE
INCLUDE=-I. -I.. -Isrc/nova -Isrc/nvscript -Isrc/common -Isrc/headers -Isrc/modules -Isrc/search
#WARN=-Werror
CWD=$(shell pwd)
#CXXFLAGS= $(OPT) $(INCLUDE) $(SDLFLAGS) $(WARN) -fPIC
CXXFLAGS= $(OPT) $(INCLUDE) $(SDLFLAGS) $(WARN)
LIBS= -lm $(SDLLIBS) -ldl
LD=$(CXX) $(OPT)
#####################################################
LIBNVSCRIPT_API_VERSION = 1.0.0
#####################################################
COMP = nova \
nvdata \
nvconsole \
nvdatastore \
nvconfig \
nvevent \
rule_clock \
rule_nvs
COMP_H = nova.h \
nvdata.h \
nvconsole.h \
nvdatastore.h \
nvconfig.h \
nvevent.h \
rule_clock.h \
rule_nvs.h
COMP_HEADERS := $(addprefix src/nova/, $(COMP_H) )
COMP_OBJS := $(addprefix objs/, $(COMP:=.o) )
COMP_LIB := libs/libnova.a
#####################################################
NVSCRIPT = nvscript \
nvscriptcore \
nvscriptresult \
nvscriptlist \
nvscriptstring \
nvscriptfile \
nvscriptnet \
nvscriptprocess \
nvscriptdebug \
nvscriptexec \
nvscriptmath
NVSCRIPT_H = nvscript.h \
nvscriptcore.h \
nvscriptresult.h \
nvscriptlist.h \
nvscriptstring.h \
nvscriptfile.h \
nvscriptnet.h \
nvscriptprocess.h \
nvscriptdebug.h \
nvscriptexec.h \
nvscriptmath.h
NVSCRIPT_HEADERS := $(addprefix src/nvscript/, $(NVSCRIPT_H) )
NVSCRIPT_OBJS := $(addprefix objs/, $(NVSCRIPT:=.o) )
NVSCRIPT_LIB := libs/libnvscript-$(LIBNVSCRIPT_API_VERSION).a
#####################################################
COMMON = stringutils \
fileutils \
wildcard \
intarray \
floatarray \
chararray \
stringarray \
uchararray \
boolarray \
voidarray \
base64 \
sha1 \
scramble \
lfp \
x86_intmem \
x86_console \
x86_file \
x86_timer \
x86_net \
x86_process \
x86_rtc \
x86_keys \
sdl_video \
sdl_input
COMMON_H = stringutils.h \
fileutils.h \
mallocdebug.h \
wildcard.h \
intarray.h \
floatarray.h \
chararray.h \
stringarray.h \
uchararray.h \
boolarray.h \
base64.h \
voidarray.h \
sha1.h \
scramble.h \
lfp.h \
x86_intmem.h \
x86_console.h \
x86_file.h \
x86_timer.h \
x86_net.h \
x86_process.h \
x86_rtc.h \
x86_keys.h \
sdl_video.h \
sdl_input.h
COMMON_HEADERS := $(addprefix src/common/, $(COMMON_H) )
COMMON_OBJS := $(addprefix objs/, $(COMMON:=.o) )
COMMON_LIB := libs/libmlcommon.a
#####################################################
SEARCH = search searchitem
SEARCH_H = search.h searchitem.h
SEARCH_HEADERS := $(addprefix src/search/, $(SEARCH_H) )
SEARCH_OBJS := $(addprefix objs/search/, $(SEARCH:=.o) )
SEARCH_LIB := libs/libsearch.a
#####################################################
MODULES = ui statusbar welcome context netmsg
MODULES_H = ui.h statusbar.h welcome.h context.h netmsg.h
MODULES_HEADERS := $(addprefix src/modules/, $(MODULES_H) )
MODULES_OBJS := $(addprefix objs/modules/, $(MODULES:=.o) )
MODULES_DSOS := $(addprefix modules/, $(MODULES:=.so) )
#####################################################
OUTPUT = main
OUTPUT_OBJS := $(addprefix objs/, $(OUTPUT:=.o) )
OUTPUT_BINARY = bin/nova
NVSOUTPUT = nvs
NVSOUTPUT_OBJS := $(addprefix objs/, $(NVSOUTPUT:=.o) )
NVSOUTPUT_BINARY = bin/nvs
NVSTESTOUTPUT = nvstest
NVSTESTOUTPUT_OBJS := $(addprefix objs/, $(NVSTESTOUTPUT:=.o) )
NVSTESTOUTPUT_BINARY = bin/nvstest
SEARCHOUTPUT = search
SEARCHOUTPUT_OBJS := $(addprefix objs/, $(SEARCHOUTPUT:=.o) )
SEARCHOUTPUT_BINARY = bin/search
#####################################################
default: $(COMP_LIB) $(NVSCRIPT_LIB) $(COMMON_LIB) $(SEARCH_LIB) $(OUTPUT_BINARY) $(NVSOUTPUT_BINARY) $(NVSTESTOUTPUT_BINARY) $(SEARCHOUTPUT_BINARY)
modules: $(MODULES_OBJS) $(MODULES_DSOS)
nova: $(COMP_LIB) $(NVSCRIPT_LIB) $(COMMON_LIB) $(OUTPUT_BINARY)
nvs: $(NVSCRIPT_LIB) $(COMMON_LIB) $(NVSOUTPUT_BINARY) $(NVSTESTOUTPUT_BINARY)
#################### Components #####################
objs/%.o: src/nova/%.c $(COMP_HEADERS)
#echo "Compiling $<"
#$(CXX) $(CXXFLAGS) -o $# -c $<
$(COMP_LIB): $(COMP_OBJS)
#echo "Building the nova library ($(COMP_LIB))"
#ar rcs $(COMP_LIB) $(COMP_OBJS)
##################### NVScript ######################
objs/%.o: src/nvscript/%.c $(NVSCRIPT_HEADERS)
#echo "Compiling $<"
#$(CXX) $(CXXFLAGS) -o $# -c $<
$(NVSCRIPT_LIB): $(NVSCRIPT_OBJS)
#echo "Building the nvscript library ($(NVSCRIPT_LIB))"
#ar rcs $(NVSCRIPT_LIB) $(NVSCRIPT_OBJS)
#################### Common #####################
objs/%.o: src/common/%.c $(COMMON_HEADERS)
#echo "Compiling $<"
#$(CXX) $(CXXFLAGS) -o $# -c $<
$(COMMON_LIB): $(COMMON_OBJS)
#echo "Building the mlcommon library ($(COMMON_LIB))"
#ar rcs $(COMMON_LIB) $(COMMON_OBJS)
################## MODULES #####################
# Compile plugin and then link to shared library
objs/modules/%.o: src/modules/%.c $(MODULES_HEADERS)
#echo "Compiling module \"$*\""
#$(CXX) $(CXXFLAGS) -o $# -c $<
modules/%.so: objs/modules/%.o $(MODULES_HEADERS)
#echo "Linking module \"$*\""
#$(CXX) -shared -o $# $(COMP_OBJS) $(NVSCRIPT_OBJS) $(COMMON_OBJS) $(LIBS) $<
#################### Search #####################
objs/search/%.o: src/search/%.c $(SEARCH_HEADERS)
#echo "Compiling $<"
#$(CXX) $(CXXFLAGS) -o $# -c $<
$(SEARCH_LIB): $(SEARCH_OBJS)
#echo "Building the search library ($(SEARCH_LIB))"
#ar rcs $(SEARCH_LIB) $(SEARCH_OBJS)
###################### Output #######################
objs/main.o: src/main/nova.c $(COMP_HEADERS) $(NVSCRIPT_HEADERS) $(COMMON_HEADERS)
#echo "Building binary ($<)"
#$(CXX) $(CXXFLAGS) -o $# -c $<
objs/nvs.o: src/main/nvs.c $(NVSCRIPT_HEADERS) $(COMMON_HEADERS)
#echo "Building binary ($<)"
#$(CXX) $(CXXFLAGS) -o $# -c $<
objs/nvstest.o: src/main/nvstest.c $(NVSCRIPT_HEADERS) $(COMMON_HEADERS)
#echo "Building binary ($<)"
#$(CXX) $(CXXFLAGS) -o $# -c $<
objs/search.o: src/main/search.c $(SEARCH_HEADERS) $(COMMON_HEADERS)
#echo "Building binary ($<)"
#$(CXX) $(CXXFLAGS) -o $# -c $<
$(OUTPUT_BINARY): $(OUTPUT_OBJS) $(COMP_LIB) $(NVSCRIPT_LIB) $(COMMON_LIB)
#echo "Linking $#"
#$(CXX) -o $# $(OUTPUT_OBJS) $(COMP_OBJS) $(NVSCRIPT_OBJS) $(COMMON_OBJS) $(LIBS)
$(NVSOUTPUT_BINARY): $(NVSOUTPUT_OBJS) $(NVSCRIPT_LIB) $(COMMON_LIB)
#echo "Linking $#"
#$(CXX) -o $# $(NVSOUTPUT_OBJS) $(NVSCRIPT_OBJS) $(COMMON_OBJS) $(LIBS)
$(NVSTESTOUTPUT_BINARY): $(NVSTESTOUTPUT_OBJS) $(NVSCRIPT_LIB) $(COMMON_LIB)
#echo "Linking $#"
#$(CXX) -o $# $(NVSTESTOUTPUT_OBJS) $(NVSCRIPT_OBJS) $(COMMON_OBJS) $(LIBS)
$(SEARCHOUTPUT_BINARY): $(SEARCHOUTPUT_OBJS) $(SEARCH_LIB) $(COMMON_LIB)
#echo "Linking $#"
#$(CXX) -o $# $(SEARCHOUTPUT_OBJS) $(SEARCH_OBJS) $(COMMON_OBJS) $(LIBS)
#####################################################
install:
./install.sh
uninstall:
./uninstall.sh
clean:
rm -f objs/*.o objs/modules/*.o objs/search/*.o */*.so */*.a modules/*.so libs/*.a $(OUTPUT_BINARY).exe $(OUTPUT_BINARY) $(NVSOUTPUT_BINARY).exe $(NVSOUTPUT_BINARY) $(NVSTESTOUTPUT_BINARY).exe $(NVSTESTOUTPUT_BINARY) $(SEARCHOUTPUT_BINARY) $(SEARCHOUTPUT_BINARY).exe
I've also written a small test:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]);
}
And it's not surprising that this does work and displays all arguments, as you would expect.
$ ./test hello
0 ./test
1 hello
It's also worth noting that the path for argv[0] seems to be different in both examples, the first (where it's not working) shows what looks like a windows path, while the second example (which does work) is showing a linux looking path. Does this indicate anything?
I think argc is required here (not argv)
for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]);
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