Cygwin C program not accepting command line arguments - c

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]);

Related

how can I solve my compiling problem with makefile

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).

Why my Makefile recompile each time?

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

More advanced makefile

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)"?

I cannot link fortran code to my own C code on my laptop

I know this issue has been discussed several times here, but I cannot find help from the previous threads.
Here's the deal. I use a code written in fortran and I link it to my code in C by my makefile. The fortran makefile is ready to handle the compatibility, in fact, I got the command
CDEFS: -DAdd_
On my work machine everything seems fine. I do the link and run my own code.
However, I just tried to use the same code on my laptop and I got the classical linker error like:
undefined reference to 'dtrsm_' or
undefined reference to 'dcopy_'
refering to the fortran program. Nevertheless, the compilers are the same gcc and f95 for both machines and I didn't touch anything from the makefile.
How come I got this error?
thanks for help me.
EDIT1: sure, this is my makefile and MUMPS is the fortran code that uses a own makefile.
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 = ./
MUMPS_DIR = $(MUMPS_ROOT)
MUMPS_INCS_DIR = $(addprefix $(MUMPS_DIR), /include)
MUMPS_LIB_DIR = $(addprefix $(MUMPS_DIR), /lib)
MUMPS_MPI_DIR = $(addprefix $(MUMPS_DIR), /libseq)
SRCS = $(wildcard $(SRCS_DIR)*.c)
OBJS = $(SRCS:$(SRCS_DIR)%.c=$(OBJS_DIR)%.o)
MUMPS = MUMPS
TARGET = APOGEE
EXES = $(addprefix $(BUILDS_DIR), $(TARGET))
CC = gcc
CFLAGS = -O3 -MD -DTRILIBRARY
INCLUDES = -I$(INCS_DIR) -I$(MUMPS_INCS_DIR)
# CL = gcc
FL = f95
LFLAGS = -O
LIBS = -L$(LIBS_DIR) -lm -lblas -lpthread
LIBS += -L$(MUMPS_LIB_DIR) -ldmumps -lmumps_common -lpord -L$(MUMPS_MPI_DIR) -lmpiseq
RM = rm -f
.PHONY: all $(MUMPS) $(TARGET) distclean clean
default: $(MUMPS) $(TARGET)
$(TARGET): $(OBJS)
#echo -e "\n\n\t\t*** Compiled $(TARGET) successfully! ***\n" ;
$(FL) $(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 $#
$(MUMPS):
(cd $(MUMPS_DIR) ; $(MAKE) ; cd $(ROOT)) ;
#echo -e "\n\n\t\t*** Compiled $(MUMPS) successfully! ***\n" ;
distclean: clean
$(RM) $(EXES)
(cd $(MUMPS_DIR) ; $(MAKE) clean ; cd $(ROOT)) ;
#echo -e "\n\n\t\t*** Purge $(MUMPS) and $(TARGET) completed! ***\n"
clean:
$(RM) $(OBJS_DIR)*.o \
$(SRCS_DIR)*~
#echo -e "\n\n\t\t*** Cleanup $(TARGET) completed! ***\n"
depend: $(SRCS)
makedepend $(INCLUDES) $^
EDIT2: chunks of the MUMPS makefile is here
include Makefile.inc
mumps_lib: requiredobj
(cd src ; $(MAKE) $(ARITH))
requiredobj: Makefile.inc $(LIBSEQNEEDED) $(libdir)/libpord$(PLAT)$(LIBEXT)
# dummy MPI library (sequential version)
libseqneeded:
(cd libseq; $(MAKE))
# Build the libpord.a library and copy it into $(topdir)/lib
$(libdir)/libpord$(PLAT)$(LIBEXT):
if [ "$(LPORDDIR)" != "" ] ; then \
cd $(LPORDDIR); \
$(MAKE) CC="$(CC)" CFLAGS="$(OPTC)" AR="$(AR)" RANLIB="$(RANLIB)" OUTC=$(OUTC) LIBEXT=$(LIBEXT); \
fi;
if [ "$(LPORDDIR)" != "" ] ; then \
cp $(LPORDDIR)/libpord$(LIBEXT) $#; \
fi;
and in Makefile.inc we got:
PLAT =
LIBEXT = .a
OUTC = -o
OUTF = -o
RM = /bin/rm -f
CC = cc
FC = f95
FL = f95
AR = ar vr
RANLIB = ranlib
INCSEQ = -I$(topdir)/libseq
LIBSEQ = -L$(topdir)/libseq -lmpiseq
LIBBLAS = -lblas
LIBOTHERS = -lpthread
CDEFS = -DAdd_
OPTF = -O
OPTC = -O -I.
OPTL = -O
INCS = $(INCSEQ)
LIBS = $(LIBSEQ)
LIBSEQNEEDED = libseqneeded

Getting "No rule to make target" on a successful build

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

Resources