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
Related
error log
paging.c: In function ‘setup_paging_structures’:
paging.c:7: warning: implicit declaration of function ‘printf’
rm -f bootimg
gcc -nostdlib -static boot.o paging.o x86_desc.o i8259.o kernel.o lib.o paging.o tests.o -Ttext=0x400000 -o bootimg
paging.o: In function `setup_paging_structures':
/workdirmain/work/mp3_group_31/student-distrib/paging.c:4: multiple definition of `setup_paging_structures'
paging.o:/workdirmain/work/mp3_group_31/student-distrib/paging.c:4: first defined here
paging.o: In function `initialize_paging':
/workdirmain/work/mp3_group_31/student-distrib/paging.c:13: multiple definition of `initialize_paging'
paging.o:/workdirmain/work/mp3_group_31/student-distrib/paging.c:13: first defined here
collect2: ld returned 1 exit status
make: *** [bootimg] Error 1
Here's what my paging.h file looks like:
#ifndef _PAGING_H
#define _PAGING_H
#include "types.h"
#define TOTAL_ENTRIES 1024
extern void setup_paging_structures();
extern void initialize_paging();
#endif
Paging.c below:
#include "paging.h" //include header files
void setup_paging_structures(){
int i;
for (i = 0; i < TOTAL_ENTRIES; i++){
printf("weird");
}
return;
}
void initialize_paging(){
setup_paging_structures();
return;
}
Note, I have not called the functions yet.
The command I'm using is "sudo make" (Makefile was given to me. I'm pretty sure I'm not supposed to modify it):
# Makefile for OS project
# To build, first `make dep`, them `make`. Everything should be automatic.
# Will compile all *.c and *.S files in the current directory.
# Flags to use when compiling, preprocessing, assembling, and linking
CFLAGS+=-Wall -fno-builtin -fno-stack-protector -nostdlib
ASFLAGS+=
LDFLAGS+=-nostdlib -static
CC=gcc
#If you have any .h files in another directory, add -I<dir> to this line
CPPFLAGS+=-nostdinc -g
# This generates the list of source files
SRC=$(wildcard *.S) $(wildcard *.c) $(wildcard */*.S) $(wildcard */*.c)
# This generates the list of .o files. The order matters, boot.o must be first
OBJS=boot.o
OBJS+=$(filter-out boot.o,$(patsubst %.S,%.o,$(filter %.S,$(SRC))))
OBJS+=$(patsubst %.c,%.o,$(filter %.c,$(SRC)))
bootimg: Makefile $(OBJS)
rm -f bootimg
$(CC) $(LDFLAGS) $(OBJS) -Ttext=0x400000 -o bootimg
sudo ./debug.sh
dep: Makefile.dep
Makefile.dep: $(SRC)
$(CC) -MM $(CPPFLAGS) $(SRC) > $#
.PHONY: clean
clean:
rm -f *.o */*.o Makefile.dep
ifneq ($(MAKECMDGOALS),dep)
ifneq ($(MAKECMDGOALS),clean)
include Makefile.dep
endif
endif
edit: I added updates to my post including the actual directories, the entire error log, and the contents of the Makefile I am using. This is also for a class that I'm currently taking, hence some of the things that were automatically given to me.
Hi i'm having issues while compiling my c program.
I'm using Makefile to compile it.
this is my make file :
# flags per la compilazione
#CFLAGS = -std=c89 -Wpedantic
CC = gcc
SO_HEIGHT= SO_HEIGHT=20
SO_WIDTH= SO_WIDTH=60
LIBS=libs/
OBJ = $(LIBS)ipc_utilities.o $(LIBS)utilities.o $(LIBS)dijkstra.o
OBJMAIN = main.o
OBJSOSOURCES=so_sources.o
OBJTAXI=taxi.o
all : utilities main so_sources taxi clean run
main: $(OBJMAIN) $(OBJ)
$(CC) $(OBJMAIN) $(OBJ)-o main
so_sources: $(OBJSOSOURCES) $(OBJ)
$(CC) $(OBJSOSOURCES) $(OBJ) -o so_sources
taxi: $(OBJTAXI) $(OBJ)
$(CC) $(OBJTAXI) $(OBJ)-o taxi
utilities:
$(CC) -c -D $(SO_HEIGHT) -D $(SO_WIDTH) -o $(LIBS)utilities.o $(LIBS)utilities.c
clean:
rm -f *.o
rm -f $(LIBS)*.o
clear
# il target run si usa talvolta per eseguire l'applicazione
run:
./main
this is the error i get :
gcc -c -D SO_HEIGHT=20 -D SO_WIDTH=60 -o libs/utilities.o libs/utilities.c
gcc -c -o libs/ipc_utilities.o libs/ipc_utilities.c
In file included from libs/ipc_utilities.h:4,
from libs/ipc_utilities.c:8:
libs/utilities.h:44:27: error: ‘SO_HEIGHT’ undeclared here (not in a function)
44 | struct strada cityMap[SO_HEIGHT][SO_WIDTH];
| ^~~~~~~~~
libs/utilities.h:44:38: error: ‘SO_WIDTH’ undeclared here (not in a function)
44 | struct strada cityMap[SO_HEIGHT][SO_WIDTH];
| ^~~~~~~~
make: *** [<builtin>: libs/ipc_utilities.o] Error 1
On ipc_utilities.h i include utilities.h :
#include <stdio.h>
#include <stdlib.h>
#include "utilities.h" // error
I'm familiar with makefile , anynone can help?
There are a number of ways to put the pieces together, but since you need both the define name and its value, I would do something like the following:
SO_HEIGHT := 20
SO_WIDTH := 20
CFLAGS := -std=c11 -Wall -Wextra -pedantic -Wshadow
CFLAGS += -DSO_HEIGHT=$(SO_HEIGHT) -DSO_WIDTH=$(SO_WIDTH)
...
$(CCLD) -o $(APPNAME) $(OBJECTS) $(CFLAGS) $(LDFLAGS) $(LIBS)
Now you have the define label and value as part of your CFLAGS variable (e.g. -DSO_HEIGHT=$(SO_HEIGHT)) you do not need to include anything further in your makefile rule.
Of Course, you could also simply do:
SO_HEIGHT := SO_HEIGHT=20
SO_WIDTH := SO_WIDTH=20
CFLAGS := -std=c11 -Wall -Wextra -pedantic -Wshadow
CFLAGS += -D$(SO_HEIGHT) -D$(SO_WIDTH)
It's really however you want to do it.
I try to write a makefile to create an executable .mexa64 file. I have to use the gcc compiler. My current working folder looks like this:
FFTW_build.c
FFTW_func.c
Makefile.c
obj (Folder, here are my object files *.o which are created)
Source code FFTW_build.c:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
FFTW_perform();
return;
}
Source code FFTW_func.c:
#include <math.h>
#include <stdio.h>
#include <complex.h>
#include <fftw3.h>
#include "mex.h"
void FFTW_perform() {
int i;
int Npoints=10;
fftw_complex *in, *out;
fftw_plan plan;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
plan = fftw_plan_dft_1d(Npoints, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
mexPrintf("\nCoefficcients of the expansion:\n\n");
for(i = 0; i < Npoints; i++)
{
in[i] = (i+1)+(3*i-1)*I;
mexPrintf("%d %11.7f %11.7f\n", i, creal(in[i]), cimag(in[i]));
}
mexPrintf("\n");
fftw_execute(plan);
mexPrintf("Output:\n\n");
for(i = 0; i < Npoints; i++)
{
mexPrintf("%d %11.7f %11.7f\n", i, creal(out[i]), cimag(out[i]));
}
}
Source code for Makefile.c:
################## Compiler ##################
CXX = gcc
####################################################
################## MEXSUFFIX ################
MEXSUFFIX = mexa64
####################################################
################## Home of my matlab version #####
MATLABHOME = /home/tuebel/matlab
####################################################
################## Object_File_Declaration_Folder ################
OBJS_MEX = FFTW_build.o
OBJS_FFTW_FUNC = FFTW_func.o
ODIR=obj
_OBJ = $(OBJS_MEX) $(OBJS_FFTW_FUNC)
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
####################################################
################## Header_Files ################
# Header for mex
DIR_MEX_HEADER = /home/tuebel/matlab/extern/include
_DEPS_MEX = mex.h
DEPS_MEX = $(patsubst %,$(DIR_MEX_HEADER)/%,$(_DEPS_MEX))
# Header for fftw3
DIR_FFTW_HEADER = /usr/local/include
_DEPS_FFTW = fftw3.h
DEPS_FFTW = $(patsubst %,$(DIR_FFTW_HEADER)/%,$(_DEPS_FFTW))
####################################################
################## Library_Files ################
# Libraries for mex
MEX_LIB = /home/tuebel/matlab/bin/glnxa64/libmex.so
# Libraries for FFTW
FFTW_LIB = /usr/local/lib/libfftw3.a
# Libraries for math_function
MATH_LIB = -lm
####################################################
################## Flags ################
# MEXFLAGS = -shared -Wl,--no-undefined -Wl,-rpath-link,$(MATLABHOME)/bin/glnxa64 -L$(MATLABHOME)/bin/glnxa64 -lmex -lmat -lmx -lm
MEXFLAGS = -shared -Wl,-rpath-link,$(MATLABHOME)/bin/glnxa64 -L$(MATLABHOME)/bin/glnxa64 -lmex -lmat -lmx -lm
COMPILERFLAGS = -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG
FFTW_FLAGS_INCLUDE = -I$(DIR_FFTW_HEADER)
MEX_FLAGS_INCLUDE = -I$(DIR_MEX_HEADER)
####################################################
#################### Final_Part ######################
TARGET = FFTW_MEX
all: $(TARGET)
echo ALL DONE
clean:
rm -f $(ODIR)/*.o
rm -f $(TARGET).mexa64
echo CLEAN DONE
$(ODIR)/%.o: %.c $(DEPS_MEX) $(DEPS_FFTW)
$(CXX) -c -o $# $< $(COMPILERFLAGS) $(MEX_FLAGS_INCLUDE) $(FFTW_FLAGS_INCLUDE)
# Final_Linking
$(TARGET) : $(OBJ) $(MATH_LIB) $(FFTW_LIB)
$(CXX) -o $#.$(MEXSUFFIX) $(MEX_FLAGS_INCLUDE) $(FFTW_FLAGS_INCLUDE) $^ $(MEXFLAGS)
####################################################
####################################################
####################################################
The idea is to make a FFTW using fftw3. The code works fine in the command window, but if I try to make it executable from matlab (.mexa64 file) it is not working. I get the following error message using make:
gcc -c -o obj/FFTW_build.o FFTW_build.c -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG -I/home/tuebel/matlab/extern/include -I/usr/local/include
gcc -c -o obj/FFTW_func.o FFTW_func.c -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG -I/home/tuebel/matlab/extern/include -I/usr/local/include
gcc -o FFTW_MEX.mexa64 -I/home/tuebel/matlab/extern/include -I/usr/local/include obj/FFTW_build.o obj/FFTW_func.o /usr/lib64/libm.so /usr/local/lib/libfftw3.a -shared -Wl,-rpath-link,/home/tuebel/matlab/bin/glnxa64 -L/home/tuebel/matlab/bin/glnxa64 -lmex -lmat -lmx -lm
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/local/lib/libfftw3.a(lt4-problem.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libfftw3.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:92: recipe for target 'FFTW_MEX' failed
make: *** [FFTW_MEX] Error 1
Can someone help me out? This is my first Makefile and I would be glad for any help... I am also glad for corrections to the Makefile...
Thanks a lot!
It is a bit unclear what you mean by an "executable" .mexa64 file.
MATLAB's mex compiler will let you compile C/C++ code with MATLAB libraries into a mex file (with 64 bit architecture for you here) that you can then "execute" via MATLAB's command line. This seems to be what you have gotten to work already.
However, if you want to have a stand alone "executable" outside of MATLAB, you need to work with MATLAB's mcr compiler (see the reference here). There are flags that you can set in the process to be build an object file which you can then link with later on with your makefile as you are trying to now.
So, don't mix mex compiled files which are runnable within MATLAB and mcr compiled code that is executable outside of it.
Apart from this, gcc is complaining that there is no main() function. I don't see one in your code here either, but you need a main() function for a standalone executable.
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.
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.)