have troubles with Make files - c

I have some problems with double! Through terminal there is some query, that I should give some number (For example how much delay in per hour). If I give through terminal a number such as 1.1 h then it prints about -1173000! It should print only 1.1.
I think, maybe there is some problem with the Makefile from FreeRTOS. (because it doesn't compile through FreeRTOS to STM32F407 processor!)
I believe something on this line should be fixed!
CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
Here is the complete code of Makefile:
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
#
OPT = 0
# Object files directory
# Warning: this will be removed by make clean!
#
OBJDIR = obj
# Target file name (without extension)
#TARGET = $(OBJDIR)/main
TARGET = $(OBJDIR)/STM32F4_Test
# Define all C source files (dependencies are generated automatically)
#
SOURCES += src/uart.c
SOURCES += src/ustime.c
SOURCES += src/main.c
SOURCES += src/startup_stm32f4xx.S
SOURCES += src/system_stm32f4xx.c
SOURCES += src/syscalls.c
SOURCES += src/modbus.c
SOURCES += src/test.c
SOURCES += src/get.c
SOURCES += src/heap_2.c
SOURCES += FreeRTOS/Source/tasks.c
SOURCES += FreeRTOS/Source/queue.c
SOURCES += FreeRTOS/Source/list.c
SOURCES += FreeRTOS/Source/croutine.c
SOURCES += FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/misc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_adc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_can.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_crc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_aes.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_des.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_tdes.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dac.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dbgmcu.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dcmi.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_flash.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fsmc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash_md5.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash_sha1.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_iwdg.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rng.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_sdio.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_tim.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_wwdg.c
OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES))))
# Place -D, -U or -I options here for C and C++ sources
CPPFLAGS += -Isrc
CPPFLAGS += -IFreeRTOS/Source/include
CPPFLAGS += -Ilibs/CMSIS/Include
CPPFLAGS += -Ilibs/Device/STM32F4xx/Include
CPPFLAGS += -Ilibs/STM32F4xx_StdPeriph_Driver/inc
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -O$(OPT)
CFLAGS += -std=gnu99
CFLAGS += -gdwarf-2
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
#CFLAGS += -Wextra
#CFLAGS += -Wpointer-arith
#CFLAGS += -Wstrict-prototypes
#CFLAGS += -Winline
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wundef
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(*F).lst
# Optimize use of the single-precision FPU
#
# CFLAGS += -fsingle-precision-constant
# This will not work without recompiling libs
#
# CFLAGS += -fshort-double
#---------------- Compiler Options C++ ----------------
#
CXXFLAGS = $(CFLAGS)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler
# -adhlns: create listing
#
ASFLAGS = -Wa,-adhlns=$(OBJDIR)/$(*F).lst
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS += -lm
LDFLAGS += -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Tsrc/stm32_flash.ld
#============================================================================
# Define programs and commands
TOOLCHAIN = d:/Programme/CodeSourcery/Sourcery_2011_09_ARM_EABI/bin/arm-none-eabi
CC = $(TOOLCHAIN)-gcc
OBJCOPY = $(TOOLCHAIN)-objcopy
OBJDUMP = $(TOOLCHAIN)-objdump
SIZE = $(TOOLCHAIN)-size
NM = $(TOOLCHAIN)-nm
OPENOCD = D:\Tools\openocd-0.7.0\bin\openocd-0.7.0.exe
DOXYGEN = doxygen
STLINK = tools/ST-LINK_CLI.exe
MKDIR = d:\tools\unxutils\bin\mkdir.exe
ifeq (AMD64, $(PROCESSOR_ARCHITEW6432))
SUBWCREV = tools/SubWCRev64.exe
else
SUBWCREV = tools/SubWCRev.exe
endif
# Compiler flags to generate dependency files
GENDEPFLAGS = -MMD -MP -MF $(OBJDIR)/$(*F).d
# Combine all necessary flags and optional flags
# Add target processor to flags.
#
#CPU = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
#CPU = -mcpu=cortex-m4 -mthumb
#
// kannst du mal nach dem problem suchen? Und dich ueber floating point probleme informieren?
// auf der ARM cpu oder spezielle dieser F407 cpu
CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
#CPU = -mcpu=cortex-m4 -mthumb
CFLAGS += $(CPU)
CXXFLAGS += $(CPU)
ASFLAGS += $(CPU)
LDFLAGS += $(CPU)
# Default target.
all: setup gccversion build showsize
setup:
$(MKDIR) -p $(OBJDIR)
$(MKDIR) -p $(OBJDIR)\src
$(MKDIR) -p $(OBJDIR)\FreeRTOS\Source
$(MKDIR) -p $(OBJDIR)\FreeRTOS\Source\portable\GCC\ARM_CM4F
$(MKDIR) -p $(OBJDIR)\libs\STM32F4xx_StdPeriph_Driver\src
build: elf hex lss sym bin
elf: $(TARGET).elf
hex: $(TARGET).hex
bin: $(TARGET).bin
lss: $(TARGET).lss
sym: $(TARGET).sym
doxygen:
#echo
#echo Creating Doxygen documentation
#$(DOXYGEN)
# Display compiler version information
gccversion:
#$(CC) --version
# Show the final program size
showsize: elf
#echo
#$(SIZE) $(TARGET).elf
# debug level
OOCD_CL=-d2
#OOCD_CL=-d3
# interface and board/target settings (using the OOCD target-library here)
## OOCD_CL+=-c "fast enable"
OOCD_CL+=-f interface/signalyzer.cfg -f openocd/stm32f4x.cfg
OOCD_CL+=-f openocd/config.cfg
OOCD_CL+=-c init -c targets
# commands to prepare flash-write
OOCD_CL+=-c "halt"
# flash-write and -verify
OOCD_CL+=-c "flash write_image erase $(TARGET).elf" -c "verify_image $(TARGET).elf"
# reset target
OOCD_CL+=-c "reset run"
# terminate OOCD after programming
# OOCD_CL+=-c shutdown
# Flash the device
flash: hex
# $(OPENOCD) -f "interface/signalyzer.cfg" -f "openocd/stm32f4x.cfg" -f "openocd/config.cfg" -c "flash_image $(TARGET).elf; shutdown"
$(OPENOCD) $(OOCD_CL)
# $(STLINK) -c SWD -P $(TARGET).hex -Run
# Target: clean project
clean:
#echo Cleaning project:
rm -rf $(OBJDIR)
rm -rf docs/html
# Create extended listing file from ELF output file
%.lss: %.elf
#echo
#echo Creating Extended Listing: $#
$(OBJDUMP) -h -S -z $< > $#
# Create a symbol table from ELF output file
%.sym: %.elf
#echo
#echo Creating Symbol Table: $#
$(NM) -n $< > $#
# Link: create ELF output file from object files
.SECONDARY: $(TARGET).elf
.PRECIOUS: $(OBJECTS)
$(TARGET).elf: $(OBJECTS)
#echo
#echo Linking: $#
$(CC) $^ $(LDFLAGS) --output $#
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
#echo
#echo Creating hex file: $#
$(OBJCOPY) -O ihex $< $#
# Create bin file :
%.bin: %.elf
#echo
#echo Creating bin file: $#
$(OBJCOPY) -O binary $< $#
# Compile: create object files from C source files
$(OBJDIR)/%.o : %.c
#echo
#echo Compiling C: $<
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(GENDEPFLAGS) $< -o $#
# Compile: create object files from C++ source files
$(OBJDIR)/%.o : %.cpp
#echo
#echo Compiling CPP: $<
$(CC) -c $(CPPFLAGS) $(CXXFLAGS) $(GENDEPFLAGS) $< -o $#
# Assemble: create object files from assembler source files
$(OBJDIR)/%.o : %.s
#echo
#echo Assembling: $<
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $#
# Include the dependency files
-include $(wildcard $(OBJDIR)/*.d)
# Listing of phony targets
.PHONY: all build flash clean \
doxygen elf lss sym \
showsize gccversion \
build elf hex bin lss sym clean clean_list setup program

I don't believe the Sourcery CodeBench 2011.09 ARM EABI compiler supports that configuration. In particular, your FPU setting appears to use single-precision, and I'm pretty sure all the libraries included with that toolchain expect a double-precision FPU.
It's not that the compiler can't produce the code you ask for. The problem is that the toolchain doesn't include compatible libraries.
It's possible that I'm mistaken and the FreeRTOS folks have already built and bundled the missing pieces, but suspect not.

Related

"make all" twice in a row doesn't return "make: Nothing to be done for 'all'."

I've noticed a lot of questions about people having the message "make: Nothing to be done for 'all'.", however my problem is the opposite.
Here is my makefile:
#################
## VARIABLES ##
#################
# Environment
OS := $(shell uname)
# Output
NAME := libft.a
DYNAMIC_NAME := ${NAME:a=so}
# Compiler
CC := gcc
ifneq ($(OS), Linux)
FLAGS += -Wall -Wextra -Werror
endif
DYN_FLAG := -shared
HEADERS := -I ./includes/
O_FLAG := -O2
# Directories
ADDITIONAL_FUNCTIONS = $(addprefix ./additional_functions/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix ./bonus_functions/, $(BONUS))
LIBC_FUNCTIONS = $(addprefix ./libc_functions/, $(LIBC))
PERSONAL_FUNCTIONS = $(addprefix ./personal_functions/, $(PERSONAL))
DYN_OBJDIR = dyn_build/
OBJDIR := build/
# Sources
ADDITIONAL += ft_itoa.c
ADDITIONAL += ft_memalloc.c ft_memdel.c
ADDITIONAL += ft_putchar.c ft_putchar_fd.c
ADDITIONAL += ft_putendl.c ft_putendl_fd.c
ADDITIONAL += ft_putnbr.c ft_putnbr_fd.c
ADDITIONAL += ft_putstr.c ft_putstr_fd.c
ADDITIONAL += ft_strclr.c ft_strdel.c
ADDITIONAL += ft_strnew.c ft_strjoin.c
ADDITIONAL += ft_strequ.c ft_strnequ.c
ADDITIONAL += ft_striter.c ft_striteri.c
ADDITIONAL += ft_strmap.c ft_strmapi.c
ADDITIONAL += ft_strsplit.c ft_strsub.c ft_strtrim.c
BONUS += ft_lstadd.c ft_lstnew.c
BONUS += ft_lstdel.c ft_lstdelone.c
BONUS += ft_lstiter.c ft_lstmap.c
LIBC += ft_atoi.c
LIBC += ft_isalnum.c ft_isalpha.c ft_isascii.c
LIBC += ft_isdigit.c ft_isprint.c
LIBC += ft_memcpy.c ft_memccpy.c ft_memchr.c ft_memcmp.c
LIBC += ft_bzero.c ft_memmove.c ft_memset.c
LIBC += ft_strcat.c ft_strlcat.c ft_strncat.c
LIBC += ft_strchr.c ft_strrchr.c
LIBC += ft_strcmp.c ft_strncmp.c
LIBC += ft_strcpy.c ft_strncpy.c ft_strdup.c
LIBC += ft_strlen.c
LIBC += ft_strstr.c ft_strnstr.c
LIBC += ft_tolower.c ft_toupper.c
PERSONAL += ft_intlen.c
PERSONAL += ft_invert.c ft_islower.c ft_isupper.c
PERSONAL += ft_lstgetnode.c ft_lstsize.c
PERSONAL += ft_kill.c ft_putuchar.c ft_putuchar_fd.c
PERSONAL += ft_strrev.c ft_strrevcpy.c
PERSONAL += get_next_line.c
DYN_OBJECTS = $(patsubst %.c,$(DYN_OBJDIR)%.o,$(SRCS))
OBJECTS = $(patsubst %.c,$(OBJDIR)%.o,$(SRCS))
SRCS += $(ADDITIONAL_FUNCTIONS)
SRCS += $(BONUS_FUNCTIONS)
SRCS += $(LIBC_FUNCTIONS)
SRCS += $(PERSONAL_FUNCTIONS)
#################
## RULES ##
#################
all: $(NAME)
$(NAME): $(OBJECTS)
#ar rcs $# $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(SRCS)))
ranlib $#
#echo "Static library created."
$(OBJECTS): | $(OBJDIR)
$(OBJDIR):
#mkdir -p $#
$(OBJDIR)%.o: %.c
$(CC) $(FLAGS) $(O_FLAG) -c $< $(HEADERS) -o $(OBJDIR)$(notdir $#)
$(DYN_OBJECTS): | $(DYN_OBJDIR)
$(DYN_OBJDIR):
#mkdir -p $#
$(DYN_OBJDIR)%.o: %.c
$(CC) $(FLAGS) $(O_FLAG) -c $< $(HEADERS) -fpic -o $(DYN_OBJDIR)$(notdir $#)
clean:
#/bin/rm -rfv $(OBJDIR)
#/bin/rm -rfv $(DYN_OBJDIR)
fclean: clean
#/bin/rm -fv $(NAME)
#/bin/rm -fv $(DYNAMIC_NAME)
re: fclean all
so: $(DYN_OBJECTS)
#$(CC) $(DYN_FLAG) -o $(DYNAMIC_NAME) $(patsubst %.c,$(DYN_OBJDIR)%.o,$(notdir $(SRCS)))
#echo "Dynamic library created."
.PHONY: all build clean dynbuild fclean re so
The makefile works perfectly fine. It takes every .c in the different directories, creates an object directory, build/ if the library is static and dyn_build/ if it is dynamic, put the object files inside said directory and compile the library from them.
My issue is that if I run make twice in a row, nothing should be done the second time as the object files and the library are still there and up to date. But, somehow doing make twice in a row results in the second make repeating the operation.
What is causing this and is there a way to fix it?
Your problem can be reduced to this:
ADDITIONAL += ft_strsplit.c
BONUS += ft_lstadd.c
ADDITIONAL_FUNCTIONS = $(addprefix ./add/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix ./bonus/, $(BONUS))
SRCS += $(ADDITIONAL_FUNCTIONS)
SRCS += $(BONUS_FUNCTIONS)
OBJECTS = $(patsubst %.c,./build/%.o,$(SRCS))
# OBJECTS contains ./build/./add/ft_strsplit.o and ./build/./bonus/ft_lstadd.o
all: $(OBJECTS)
$(OBJDIR)%.o: %.c
$(CC) ...
So Make runs the last rule with e.g. build/./add/ft_strsplit.o as the target, and add/ft_strsplit.c as the prerequisite. The question is how to write the recipe so as to build build/ft_strsplit.o.
As #user657267 has pointed out, it is a mistake to have a (non-PHONY) rule that does not build a file whose name is the target of the rule. So let's first ask Make for the files we actually want:
ADDITIONAL += ft_strsplit.c
BONUS += ft_lstadd.c
SRCS += $(ADDITIONAL)
SRCS += $(BONUS)
OBJECTS = $(patsubst %.c,./build/%.o,$(SRCS))
# OBJECTS contains ./build/ft_strsplit.o and ./build/ft_lstadd.o
So far so good, but now how can Make find the sources? When we ask Make to build ./build/ft_strsplit.o, how can it know where ft_strsplit.c is?
We use vpath:
vpath %.c add bonus
Now the makefile works correctly. And to write that vpath line automatically, we can just pull the directory names out of the assignments:
# Directories
ADDITIONAL_DIR := ./additional_functions
BONUS_DIR := ./bonus_functions
...
ADDITIONAL_FUNCTIONS = $(addprefix $(ADDITIONAL_DIR)/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix $(BONUS_DIR)/, $(BONUS))
...
vpath %.c $(ADDITIONAL_DIR)
vpath %.c $(BONUS_DIR)
...

make: *** [.o] Error 1

I get this error:
make all
Building file: ../src/lol.c
Invoking: GCC C Compiler
gcc -lm lol.c -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/lol.d" -MT"src/lol.d" -o "src/lol.o" "../src/lol.c"
gcc: error: lol.c: No such file or directory
make: *** [src/lol.o] Error 1
MAKEFILE
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: lol
# Tool invocations
lol: $(OBJS) $(USER_OBJS)
#echo 'Building target: $#'
#echo 'Invoking: GCC C Linker'
gcc -o "lol" $(OBJS) $(USER_OBJS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) lol
-#echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
SUBDIR.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../src/lol.c
OBJS += \
./src/lol.o
C_DEPS += \
./src/lol.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
#echo 'Building file: $<'
#echo 'Invoking: GCC C Compiler'
gcc -lm lol.c -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -o "$#" "$<"
#echo 'Finished building: $<'
#echo ' '
when I try to compile the code below. I use eclipse on ubuntu 14.04lts. I know you'll probably need more details bout the error but I don't know what and how, please just ask if you need further information.
#include <stdio.h>
#include <math.h>
/* to be compiled with "gcc -lm 05_09.c" */
double calculateCharges(float hours);
int main(void)
{
float car_a_hours, car_b_hours, car_c_hours, tothours;
float car_a_charge, car_b_charge, car_c_charge, totcharge;
printf("\n\n");
printf("enter car #1 parking hours: ");
scanf("%f", &car_a_hours);
printf("enter car #2 parking hours: ");
scanf("%f", &car_b_hours);
printf("enter car #3 parking hours: ");
scanf("%f", &car_c_hours);
tothours = car_a_hours + car_b_hours + car_c_hours;
car_a_charge = calculateCharges(car_a_hours);
car_b_charge = calculateCharges(car_b_hours);
car_c_charge = calculateCharges(car_c_hours);
totcharge = car_a_charge + car_b_charge + car_c_charge;
printf("\n\n");
printf("Car\tHours\tCharge\n");
printf("%d\t%5.1f\t%6.2f\n", 1, car_a_hours, car_a_charge);
printf("%d\t%5.1f\t%6.2f\n", 2, car_b_hours, car_b_charge);
printf("%d\t%5.1f\t%6.2f\n", 3, car_c_hours, car_c_charge);
printf("TOTAL\t%5.1f\t%6.2f\n", tothours, totcharge);
printf("\n\n");
return 0;
}
double calculateCharges(float hours)
{
if ((hours - 3.0) <= 0)
return 2.0;
else if ((hours == 24.0))
return 10;
else
return (ceil(hours) - 3) * 0.5 + 2;
}
It was a Gcc Math.h Linking Problem in Eclipse
If you use Eclipse/gcc and have functions that need the math.h library, you may find out that the linker can't find functions like sqrt or pow and signal it like this:
undefined reference to `pow' Matrix.c /TzUtils/Sources line 152 C/C++ Problem
undefined reference to `pow' Matrix.c /TzUtils/Sources line 204 C/C++ Problem
and it was my original error, before tried to add wrongly the flag -lm.
This thing happens because the library which contains math.h is not linked by default. To link it you will need to add the extra flag -Im.
In Eclipse this can be done by:
Right click on your project in Project Explorer and select Properties.
Go to C\C++ Build -> Settings -> Tool Settings -> Gcc Linker -> Libraries and click on green plus button to add a new library. When the dialog pops up, write m, and Eclipse will automatically add the -Im flag.
After this I don't get any error. Thanks everyone for the help.
Credits answer: dystopiancode.blogspot.it

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

Problems with linking CUDA for running fastHOG algorithm

I am trying to set up the fastHOG codebase in my linux server, but unable to finish it as i am getting heap of link errors. I am giving here a sample portion of the link errors
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x910): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x944): undefined reference to 'cudaGetErrorString'
/home/n8385106/bin/contrib/qut/qutanomaly/matlab/person- detector/fasthog/obj/release/HOG/HOGHistogram.cu.o: In function 'InitHistograms(int, int, int, int, int, float)':
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xac0): undefined reference to 'cudaCreateChannelDesc'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xafe): undefined reference to 'cudaMallocArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xb46): undefined reference to 'cudaMemcpyToArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc3d): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc63): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc89): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xcae): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xccd): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd01): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd15): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd29): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd3d): undefined reference to 'cudaGetErrorString'
It seems the linker didn't realize any of the linker libraries provided in the make file. It did not say anything like "was unable to find this library" but it avoided all the information provided about the libraries to be linked such as
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) - L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
I was able to create all the object files but problem is comming during the linking process, I am a newbie to CUDA, Can anyone please help me to sort this out?
My OS is 64 bit linux
Edited : My MakeFile
# Add source files here
EXECUTABLE := fastHOG
# C/C++ source files (compiled with gcc / c++)
CCFILES := \
fastHOG.cpp \
# HOG UTILS
CCUTILS := \
ImageWindow.cpp \
# CC HOG
CCHOG := \
HOGImage.cpp \
HOGEngine.cpp \
HOGNMS.cpp \
# CUDA HOG
CUFILES := \
HOGEngineDevice.cu \
HOGConvolution.cu \
HOGHistogram.cu \
HOGPadding.cu \
HOGScale.cu \
HOGSVMSlider.cu \
HOGUtils.cu \
################################################################################
# Rules and targets
include common.mk
Contents of the common.mk file
################################################################################
#
# Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
#
################################################################################
#
# Common build script
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin
#Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := sm_10 sm_11 sm_12 sm_13
CUDA_INSTALL_PATH ?= fasthoglib/cuda/cuda
ifdef cuda-install
CUDA_INSTALL_PATH := $(cuda-install)
endif
# detect OS
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
# 'linux' is output for Linux system, 'darwin' for OS X
DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
SRCDIRUTILS ?= Utils
SRCDIRHOG ?= HOG
ROOTDIR ?= /home/n8385106/src/saivt-vxl/contrib/qut/qutanomaly/matlab/pedestrian-detector/fasthoglib/cuda/sdk
ROOTBINDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/bin
BINDIR ?= $(ROOTBINDIR)
ROOTOBJDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/obj
LIBDIR := $(ROOTDIR)/C/lib
COMMONDIR := $(ROOTDIR)/C/common
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++
CC := gcc
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/cuda/include -I$(COMMONDIR)/inc
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# Warning flags
CXXWARN_FLAGS := \
-W -Wall \
-Wimplicit \
-Wswitch \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wmultichar \
-Wtrigraphs \
-Wpointer-arith \
-Wcast-align \
-Wreturn-type \
-Wno-unused-function \
$(SPACE)
CWARN_FLAGS := $(CXXWARN_FLAGS) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Wmain \
# Compiler-specific flags
NVCCFLAGS :=
CXXFLAGS := $(CXXWARN_FLAGS)
CFLAGS := $(CWARN_FLAGS)
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O3
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# append optional arch/SM version flags (such as -arch sm_11)
#NVCCFLAGS += $(SMVERSIONFLAGS)
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# detect if 32 bit or 64 bit system
HP_64 = $(shell uname -m | grep 64)
# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
ifeq ($(USEGLLIB),1)
ifneq ($(DARWIN),)
OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
CUBIN_ARCH_FLAG := -m64
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
OPENGLLIB += -lglut
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl$(LIBSUFFIX)
endif
USECUDPP := 1;
ifeq ($(USECUDPP), 1)
ifeq "$(strip $(HP_64))" ""
CUDPPLIB := -lcudpp
else
CUDPPLIB := -lcudpp64
endif
CUDPPLIB := $(CUDPPLIB)$(LIBSUFFIX)
ifeq ($(emu), 1)
CUDPPLIB := $(CUDPPLIB)_emu
endif
endif
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
LIB += -lcutil$(LIBSUFFIX)
# Device emulation configuration
ifeq ($(emu), 1)
NVCCFLAGS += -deviceemu
CUDACCFLAGS +=
BINSUBDIR := emu$(BINSUBDIR)
# consistency, makes developing easier
CXXFLAGS += -D__DEVICE_EMULATION__
CFLAGS += -D__DEVICE_EMULATION__
endif
TARGETDIR := $(BINDIR)/$(BINSUBDIR)
TARGET := $(TARGETDIR)/$(EXECUTABLE)
#fltk
LIB += -lfltk2 -lXft -lfltk2_images -lXext -lXinerama -lXi
#boost thread for interface
LIB += -lboost_thread
#read images in HOGImage from file
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
endif
# check if verbose
ifeq ($(verbose), 1)
VERBOSE :=
else
VERBOSE := #
endif
################################################################################
# Check for input flags and set compiler flags appropriately
################################################################################
ifeq ($(fastmath), 1)
NVCCFLAGS += -use_fast_math
endif
ifeq ($(keep), 1)
NVCCFLAGS += -keep
NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
endif
ifdef maxregisters
NVCCFLAGS += -maxrregcount $(maxregisters)
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# workaround for mac os x cuda 1.1 compiler issues
ifneq ($(DARWIN),)
NVCCFLAGS += --host-compilation C
endif
# Add common flags
NVCCFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
CFLAGS += $(COMMONFLAGS)
ifeq ($(nvcc_warn_verbose),1)
NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
NVCCFLAGS += --compiler-options -fno-strict-aliasing
endif
################################################################################
# Set up object files
################################################################################
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJDIRUTILS := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRUTILS)
OBJS += $(patsubst %.cpp,$(OBJDIRUTILS)/%.cpp.o,$(notdir $(CCUTILS)))
OBJDIRHOG := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRHOG)
OBJS += $(patsubst %.cu,$(OBJDIRHOG)/%.cu.o,$(notdir $(CUFILES)))
OBJS += $(patsubst %.cpp,$(OBJDIRHOG)/%.cpp.o,$(notdir $(CCHOG)))
################################################################################
# Set up cubin files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIRUTILS)/%.cpp.o : $(SRCDIRUTILS)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cpp.o : $(SRCDIRHOG)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cu.o : $(SRCDIRHOG)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
#
# The following definition is a template that gets instantiated for each SM
# version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
# 1. It adds to OBJS a .cu_sm_XX.o for each .cu file it finds in CUFILES_sm_XX.
# 2. It generates a rule for building .cu_sm_XX.o files from the corresponding
# .cu file.
#
# The intended use for this is to allow Makefiles that use common.mk to compile
# files to different Compute Capability targets (aka SM arch version). To do
# so, in the Makefile, list files for each SM arch separately, like so:
#
# CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
# CUFILES_sm_12 := anothercudakernel_sm12.cu
#
define SMVERSION_template
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) -arch $(1)
endef
# This line invokes the above template for each arch version stored in
# SM_VERSIONS. The call function invokes the template, and the eval
# function interprets it as make commands.
$(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
$(TARGET): makedirectories $(OBJS) $(CUBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(OBJDIRUTILS)
$(VERBOSE)mkdir -p $(OBJDIRHOG)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :-lboost_thread
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
clobber : clean
$(VERBOSE)rm -rf $(ROOTOBJDIR)
The common.mk has been broken (presumably by a modification you made to it) here:
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
This is undoubtedly not what you want, it is destroying all of the carefully crafted library dependencies assigned above it. I guess you intended something like
LIB += /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a

Cygwin - Makefile-error: recipe for target `main.o' failed

I am currently failing to write a good makefile and don't know the reason why.. -.-
This is my main.c:
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("MEEEEEP");
return (0);
}
This is my makefile:
# make SYSTEM= OS= ENVIRONMENT=
# Binaries to use
ifeq ($(ENVIRONMENT),MINGW)
CXX = i686-pc-mingw32-g++
else
CXX = g++
endif
REMOVE = rm -vf
RC = windres
EXE = .exe
#############################################################
# Info
ifeq ($(CXX),g++)
INFO_CXX = g++ -dumpversion; g++ -dumpmachine
endif
#############################################################
# Flags
DEBUG = -DDEBUG -g
OPTIMIZATION = -O2 #-Winline -finline-functions
CFLAGS = -Wall -Wextra -W -static $(DEBUG) $(OPTIMIZATION) -D$(SYSTEM) -D$(OS) -D$(ENVIRONMENT) $(PRGFLAGS)
ifeq ($(SYSTEM),I686)
CFLAGS += -m32
ifeq ($(OS),WIN32)
CFLAGS += -D_WIN32
endif
ifeq ($(ENVIRONMENT),MINGW)
CFLAGS += -fexceptions
endif
endif
LFLAGS =
#############################################################
# Files
CFILES = main.c
OBJS = ${CFILES:.c=.o}
#############################################################
# Include
INCLUDES = -I.
#############################################################
# Library
LIBRARIES =
#############################################################
# Targets
.PHONY: all
all:
#echo == Standard build: make SYSTEM=I686 OS=WIN32 ENVIRONMENT=MINGW
#echo
#echo
make SYSTEM=I686 OS=WIN32 ENVIRONMENT=MINGW gyro
#############################################################
# Implicit rules and filename extensions...
.SUFFIXES: .h .o .c
.c.o: %.h
#echo Compiling $< for $(SYSTEM) $(OS) $(ENVIRONMENT) ...
#echo MEEP
$(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $#
#echo MEEP2
#############################################################
# Target rules
gyro: $(OBJS)
#echo Building software for $(SYSTEM) ...
#echo
$(CXX) $(CFLAGS) $(LFLAGS) -o $#$(EXE) $(OBJS) $(LIBRARIES)
#############################################################
# Clean
.PHONY: clean
clean:
$(REMOVE) $(OBJS)
#############################################################
# Info
.PHONY: info
info:
#echo
#echo Information about C++ Compiler/Linker:
#echo
$(INFO_CXX)
When i type in make gyro,
i receive the output:
Compiling main.c for Windows_NT ...
MEEP
g++ -Wall -Wextra -W -static -DDEBUG -g -O2 -D -DWindows_NT -D -I. -c main.c -o main.o
makeNew.mak:83: recipe for target `main.o' failed
make: *** [main.o] Error 1
But Line number 83 is behind .c.o: %.h. And i don’t understand why.
Does anyone have a solution for me?
You see the two empty -D entries in the g++ command line? They're causing the problem. You must have values in the -D items e.g. -DWIN32
if you're insistent on using something like -D$(SYSTEM) -D$(ENVIRONMENT) then you can use something like:
SYSTEM ?= generic
ENVIRONMENT ?= generic
in the makefile which gives them default values.
Your output looks to be missing the all important output:
<command-line>:0:1: error: macro names must be identifiers
<command-line>:0:1: error: macro names must be identifiers
just to clarify, what actually got sent to g++ was -D -DWindows_NT, i.e. define a preprocessor macro called -DWindows_NT; which is of course not a valid identifier (similarly for -D -I.)

Resources