I am working on a project using a ST Microcontroller (STM32f101C8T6) with GNU 5.4.1 on Windows.
The software contains both C and C++ source files (Majority in C). So I am using both C and C++ compilers along with a linker script. But unfortuately, I get the flash overflow errors and undefined reference errors:
"C:\Program Files (x86)/GNU Tools ARM Embedded\5.4 2016q3\bin"/arm-none-eabi-g++ -o ./obj/rel/MICRO_AO/MICRO_AO.elf -mcpu=cortex-m3 -mthumb -Wl,-L./Make/ld -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-T -Xlinker ./Make/ld/STM32F101_64K_10K_FLASH.ld -Wl,-Map -Xlinker ./obj/rel/MICRO_AO/MICRO_AO.map ./obj/rel/MICRO_AO/./MICRO_BASE/main.cpp.o ./obj/rel/MICRO_AO/./MICRO_AO/AoModule.cpp.o ./obj/rel/MICRO_AO/./MICRO_BASE/Module.cpp.o ./obj/rel/MICRO_AO/./MICRO_AO/output.c.o ./obj/rel/MICRO_AO/./MICRO_AO/ioports.c.o ./obj/rel/MICRO_AO/./MICRO_AO/parameter.c.o ./obj/rel/MICRO_AO/./MICRO_AO/frontendDummy.c.o ./obj/rel/MICRO_AO/./MICRO_AO/frontendMax5134.c.o ./obj/rel/MICRO_AO/./Globals/src/stm32f10x_vector.c.o ./obj/rel/MICRO_AO/./Globals/src/max5134.c.o ./obj/rel/LibStm32f10x/LibStm32f10x.a ./obj/rel/LibGlobals/LibGlobals.a ./obj/rel/LibStm32f10x/LibStm32f10x.a ./obj/rel/LibGlobals/LibGlobals.a
c:/program files (x86)/gnu tools arm embedded/5.4 2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: ./obj/rel/MICRO_AO/MICRO_AO.elf section `.text' will not fit in region `FLASH'
c:/program files (x86)/gnu tools arm embedded/5.4 2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: section .calibdata loaded at [0800fc00,0800ffff] overlaps section .text loaded at [08002230,08014517]
c:/program files (x86)/gnu tools arm embedded/5.4 2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: section .ARM.extab.text.__cxa_pure_virtual loaded at [08014518,08014523] overlaps section .data loaded at [08014518,080151f7]
c:/program files (x86)/gnu tools arm embedded/5.4 2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 11492 bytes
C:\MICRO_AO\Micro_SLIO/MICRO_AO/AoModule.cpp:330: undefined reference to `AnalogProcess()'
C:\MICRO_AO\Micro_SLIO/MICRO_AO/AoModule.cpp:331: undefined reference to `Diag_Process()'
By looking for soultions in the internet, I assume the errors are due to the linker flags I tried changing. None of it seemed to work. I am not exactly sure where the error lies and what should be done.
Below is the compiler and linker settings from the Makefile:
### Global complier and linker settings
INCLUDES_APP := -I$(GLOBALS_DIR)/inc -I$(LIBGLOBALS_DIR)/inc - I$(LIBSTM32F10X_DIR)/inc
AFLAGS :=
CFLAGS := -Wall -Wextra -Wmissing-field-initializers -Wstrict- prototypes -mcpu=cortex-m3 -mthumb -fsigned-char -g -ffunction-sections -fpic -mlittle-endian -D_FLASH_PROG
CXXFLAGS := -Wall -Wextra -Wmissing-field-initializers -mcpu=cortex-m3 -mthumb -fsigned-char -g -ffunction-sections -fno-rtti -fpic -fno-exceptions -mlittle-endian -D_FLASH_PROG
LINKER_FILE := $(LD_DIR)/STM32F101_64K_10K_FLASH.ld
LFLAGS := -mcpu=cortex-m3 -mthumb -Wl,-L$(LD_DIR) -Wl,-static -Wl,--gc-sections -nostartfiles
ifeq ($(BUILD_TYPE),$(BUILD_TYPE_DEBUG))
CFLAGS := $(CFLAGS) -O0 -g -DDEBUG
CXXFLAGS := $(CXXFLAGS) -O0 -g -DDEBUG
else
CFLAGS := $(CFLAGS) -O2 -g
CXXFLAGS := $(CXXFLAGS) -Os -g
endif
### TOOLCHAIN
COMMAND_DIR := "$(PROGRAMFILES)/GNU Tools ARM Embedded\5.4 2016q3\bin"
COMMAND_PREFIX := arm-none-eabi-
CMD_PREFIX := arm-none-eabi-
CC := $(COMMAND_DIR)/$(CMD_PREFIX)gcc
CPPC := $(COMMAND_DIR)/$(CMD_PREFIX)g++
ASM := $(COMMAND_DIR)/$(COMMAND_PREFIX)as
LINK := $(COMMAND_DIR)/$(COMMAND_PREFIX)g++
ELFBIN := $(COMMAND_DIR)/$(COMMAND_PREFIX)objcopy
AR := $(COMMAND_DIR)/$(COMMAND_PREFIX)ar
SIZE := $(COMMAND_DIR)/$(COMMAND_PREFIX)size
CP := cp
MKDIR := mkdir
RM := rm
MV := mv
SREC_CAT := $(TOOLS_DIR)/srec_cat
Related
I am trying to do this tutorial: https://linuxgazette.net/139/peterson.html so I can learn to write postgres functions.
It says to use this makefile, which fails:
MODULES = example
PGXS := $(shell pg_config --pgxs)
include $(PGXS)
Errors:
(base) weather#weather:~/pg_func_learn$ make
/tmp/build/80754af9/postgresql-split_1552510884761/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/home/weather/anaconda3/include -fdebug-prefix-map=/tmp/build/80754af9/postgresql-split_1552510884761/work=/usr/local/src/conda/postgresql-split-11.2 -fdebug-prefix-map=/home/weather/anaconda3=/usr/local/src/conda-prefix -fPIC -I. -I./ -I/home/weather/anaconda3/include/server -I/home/weather/anaconda3/include/internal -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -D_GNU_SOURCE -I/home/weather/anaconda3/include -c -o example.o example.c
make: /tmp/build/80754af9/postgresql-split_1552510884761/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc: Command not found
<builtin>: recipe for target 'example.o' failed
make: *** [example.o] Error 127
I have tried several things, including updating conda and anaconda, as per the answers to similar questions. Nothing has worked yet.
How do I compile postgres function given this situation?
This error has occurred caused by absent GCC compiler((/tmp/build/80754af9/postgresql-split_1552510884761/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc) in your machine. Therefore, you need to rewrite a make rule.
Update the gcc compiler version 6 or later.
Rewrite the Makefile by adding "CC := /usr/bin/gcc" below the line of "include $(PGXS)".
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
CC := /usr/bin/gcc
3. Finally, compile your extension. (USE_PGXS=1 make)
I'm working on a Makefile to make me able to native and cross-compile. choosing wether to compile for host linux or ti MSP432 should be done from command line:
$ make build PLATFORM=MSP432
$ make build PLATFORM=HOST
here's my Makefile that I tried to do it in:
include sources.mk
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CC = gcc
endif
TARGET = c1m1
LDFLAGS = -Wl,-Map=$(TARGET).map -T $(LINKER_FILE)
CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -Wall -Werror -g -O0
-std=c99
CPPFLAGs =
.PHONY: build
build: $(TARGET).out
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET).out $(TARGET).map
%.o : %.c
$(CC) -c $< $(CFLAGS) -o $#
OBJS = $(SOURCES:.c=.o)
$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $#
is this the right way to do that?
there's also another weird error happening when I compile using:
$ make main.o PLATFORM=MSP432
I get this error:
arm-none-eabi-gcc -c main.c -mcpu=cortex-m4 -mthumb --
specs=nosys.specs -Wall -Werror -g -O0 -std=c99 -o main.o
main.c:23:22: fatal error: platform.h: No such file or directory
#include "platform.h"
^
compilation terminated.
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
and when I compile using this:
$ make main.o PLATFORM=HOST
I get this error, they are 2 different errors and I can't understand the reason behind this.
gcc -c main.c -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99 -o
main.o
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’
instead
gcc: error: missing argument to ‘-mcpu=’
gcc: error: missing argument to ‘--specs=’
gcc: error: unrecognized command line option ‘-m’
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
I posted those apparently different questions in 1 question, because I think they are affecting eachother.
this is also another headerfile that is called platform.h that has some conditionals to include some directives, which after the answer I think might be needed for compile time switches
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
#if defined (MSP432)
#include "msp432p401r.h"
#define PRINTF(...)
#elif defined (HOST)
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#error "Platform provided is not supported in this Build System"
#endif
#endif /* __PLATFORM_H__ */
First, I will answer the case when PLATFORM and HOST are the same:
$ make main.o PLATFORM=HOST
I get this error, they are 2 different errors and I can't understand the reason behind this.
gcc -c main.c -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99 -o
main.o
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’
instead
gcc: error: missing argument to ‘-mcpu=’
gcc: error: missing argument to ‘--specs=’
gcc: error: unrecognized command line option ‘-m’
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
This is due to your makefile: CPU, ARCH and SPECS are only set when
PLATFORM is MSP432
So the line CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -Wall -Werror -g -O0 -std=c99
is evalued as CFLAGS = -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99
When gcc is invoked with CFLAGS as argument, which is incorrect.
To correct this, you can make theses little changes in your makefile:
include sources.mk
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
LDFLAGS_ARCH = -T $(LINKER_FILE)
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS)
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CC = gcc
endif
TARGET = c1m1
LDFLAGS = -Wl,-Map=$(TARGET).map $(LDFLAGS_ARCH)
CFLAGS = $(CFLAGS_ARCH) -Wall -Werror -g -O0
-std=c99
CPPFLAGs =
Now, for the main.c:23:22: fatal error: platform.h: No such file or directory
You have to find where this file is locatted and eventually add it as a gcc option.
For instance, if the file platform.h is in /some/directory, you can add this
option to gcc to help it to find it:
-I/some/directory
So in makefile, you can have this line:
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -I/some/directory
EDIT
In comments, you add this problem for your question:
that solved it the errors are consistent now, and here it is
In file included from main.c:23:0: ./include/common/platform.h:30:2: error:
#error "Platform provided is not supported in this Build System" #error "... *** [main.o] Error 1
Regarding the platform.h file, macro MSP432 or HOST must be defined in order to run.
To define such macro, the -D option must be passed to gcc.
So the idea is to add some line to the makefile to define MSP432 or HOST when necessary:
...
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
LDFLAGS_ARCH = -T $(LINKER_FILE)
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -DMSP432
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CFLAGS_ARCH = -DHOST
CC = gcc
endif
...
I am having a existing application which compiles and executes in GCC.
I am cross compiling the same application, I am able to cross compile and generate the shared libraries. But when I try to use the shared libraries for linking to a application it is giving the following errors
arm-poky-linux-gnueabi-gcc MSO_Version.o MSO_Connect.o MSO_errors.o -o bin/MSO_Version_shared -Wall -g -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk -I../include -I../wsq -I/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/include/ -L/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/lib -L../lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib -L/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/lib -lMSO -lMSOComm -lusb
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: skipping incompatible /opt/poky/1.8/sysroots/i686-pokysdk-linux/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /lib/libc.so.6
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /usr/lib/libc_nonshared.a
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /lib/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status
make[1]: *** [MSO_Version_shared] Error 1
make[1]: Leaving directory `/home/linux/ESYS-IMP-LINUXAPP-SUF-24092012-V0.01/Internal Release/ESYS-IMP-LinuxApp-SUF-LIB-SRS-V0.01/samples'
make: *** [samples] Error 2
If I compile with static libraries executables are getting generated. Below is my makefile
export CROSS_COMPILE
CC = $(CROSS_COMPILE)gcc
ifeq ($(DEBUG),yes)
CFLAGS = -Wall -g -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk
else
CFLAGS = -Wall -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk
endif
LIB_USB = -lusb
LIB_SDL = -lSDL -lSDL_ttf
LIBPATH += -L/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/lib
LIBPATH += -L../lib
LIBPATH += -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib
LIBPATH += -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib
LIBPATH += -L/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/lib
LIB_STATIC_SAGEM = ../lib/libMSO.a ../lib/libMSOComm.a
LIB_SAGEM = -lMSO -lMSOComm
SRCINCLUDE += -I../include -I../wsq
SRCINCLUDE += -I/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/include/
EXEC_PATH = bin
EXEC_STATIC = MSO_Version #MSO_TestBio MSO_TestThread
EXEC_SHARED = MSO_Version_shared #MSO_TestBio_shared
MSO_Version_SRC = MSO_Version.c MSO_Connect.c MSO_errors.c
MSO_Version_OBJ = $(MSO_Version_SRC:.c=.o)
.PHONY: all
all: $(EXEC_STATIC) $(EXEC_SHARED)
%.o: %.c
$(CC) -c $(CFLAGS) $(SRCINCLUDE) $< -o $#
.PHONY: MSO_Version MSO_Version_shared
MSO_Version: $(MSO_Version_OBJ)
$(CC) $(MSO_Version_OBJ) -o $(EXEC_PATH)/MSO_Version $(CFLAGS) $(SRCINCLUDE) $(LIB_STATIC_SAGEM) $(LIB_USB)
MSO_Version_shared: $(MSO_Version_OBJ)
$(CC) $(MSO_Version_OBJ) -o $(EXEC_PATH)/MSO_Version_shared $(CFLAGS) $(SRCINCLUDE) $(LIBPATH) $(LIB_SAGEM) $(LIB_USB)
You can see I am generating two executables one with the static library and other with shared library.
I am using poky 1.8 and kernel is 2.6.38. Using NXP IMX6ULEVK board.
Can anyone tell me where I am going wrong
You specify architecture as armv7-a:
-march=armv7-a
but link towards i686 libraries:
-L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib
My goal is to use a single Makefile for compiling a C app across various platforms.
I've been busily relearning C while working on a project, so as a result have not yet had the time to delve into make; instead I have a single, long gcc command in some .bat / .sh files. Needless to say that each time I change one such file, I have to make those same changes in the others. Hence, make. Conditions that need to be handled:
Builds for multiple OS & architecture, i.e. for now (at least) 32 & 64-bit for Windows & Linux, thus I need access to that info in the Makefile, and executables should go into distinct folders under /build: i.e. /win32, /win64, /lin32, /lin64 (et cetera, in future).
Required DLLs should be copied in alongside the built executable.
Separate compile & link phases (thanks #EtanReisner)
Question: Can someone show me how one would go about constructing a Makefile using the info below? And explain how each part works / why it is needed for my particular case? I have an understanding of the prerequisites approach by which Makefiles are built. Thanks in advance.
Here is my project directory tree:
+---bin
+---include
| +---enet
| +---GL
| +---libxml
| \---ncursesw
+---lib
+---src
+---fonts
\---shaders
And mingw gcc for Windows 32-bit compile:
gcc -Iinclude ./src/main.c ./src/MainCtrl.c ./src/MainView.c ./src/PerspectiveView.c ./src/LogView.c ./src/LobbyView.c ./src/TerminalView.c ./src/World.c ./src/Chunk.c ./src/CellPattern.c ./src/CellPlan.c ./src/GridPoint.c ./src/Entity.c ./src/InfluenceRadial.c ./src/AoIList.c ./src/AoI.c ./src/ChunkRenderable.c ./src/PrimitiveRenderable.c ./src/Geometry.c ./src/glew/glew.c ./src/stb/stb_image_aug.c ../curt/list_generic.c ../curt/map_generic.c ../curt/intMap.c ../curt/floatMap.c ../hedgehog/hedgehog.c ./src/Inputs.c ./src/InputResponse.c ./src/Network.c ../Disjunction/c/disjunction.c ./src/my/math/Range.c ./src/my/math/Point.c -Llib -lglfw3-32 -lopengl32 -lgdi32 -lenet-32 -lws2_32 -lwinmm -llibxml2-32 -L. -ldll32/libncursesw6 -std=c11 -m32 -w -Wall -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes -Wlogical-op -Wcast-align -Wconversion -Wpedantic -Wfloat-equal -fopenmp -O0 -o ./build/win32/wa
And the gcc for Linux 64-bit compile:
gcc -Iinclude -I/usr/include/libxml2 ./src/main.c ./src/MainCtrl.c ./src/MainView.c ./src/PerspectiveView.c ./src/LogView.c ./src/LobbyView.c ./src/TerminalView.c ./src/World.c ./src/Chunk.c ./src/CellPattern.c ./src/CellPlan.c ./src/GridPoint.c ./src/Entity.c ./src/InfluenceRadial.c ./src/AoIList.c ./src/AoI.c ./src/ChunkRenderable.c ./src/PrimitiveRenderable.c ./src/Geometry.c ./src/glew/glew.c ./src/stb/stb_image_aug.c ../curt/list_generic.c ../curt/map_generic.c ../curt/intMap.c ../curt/floatMap.c ../hedgehog/hedgehog.c ./src/Inputs.c ./src/InputResponse.c ./src/Network.c ../disjunction/c/disjunction.c ./src/my/math/Range.c ./src/my/math/Point.c -Llib -L/usr/lib -l:libglfw.so.3 -lncurses -lGL -lxml2 -lenet -lm -std=c11 -m64 -w -Wall -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes -Wlogical-op -Wcast-align -Wconversion -Wpedantic -Wfloat-equal -fopenmp -g -o ./wa-64.elf
(worth diffing these.)
Trial and error led tothe following... work in progress, but the basics are there. Features:
No need to manually list source / object files (all relevant sources expected to be in src)
Separate compile & link phases using shared logic for .c/.o file lists
OS & architecture autodetection (WIP), with manual override for arch (
e.g. make BITS=32)
Clean that works for both Win & *nixes
Copies in .DLLs on compile (WIP to supply a list of DLLs to copy in)
Thanks to Yanick Rochon, Samuel and Trevor Robinson for their answers, and to those who wrote the GNU Makefile examples.
CC = gcc
#Directories
HDRDIR = include
SRCDIR = ./src
OBJDIR = ./obj
BINDIR = ./bin
LIBDIR = lib
#File lists
HDRS := $(wildcard $(HDRDIR)/*.h)
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
#Autodetect OS / architecture
OS =
BITS = 32
#ifeq ($(shell echo "check_quotes"),"check_quotes")
ifeq ($(OS),Windows_NT)
OS := win
EXT := .exe
rm := del /q
cp := copy /y
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
CFLAGS += -D AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
CFLAGS += -D IA32
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS := lin
EXT := .elf
rm := rm -f
cp := cp
CCFLAGS += -D LINUX
BITS = $(shell getconf LONG_BIT)
endif
ifeq ($(UNAME_S),Darwin)
OS := osx
EXT :=
rm := rm -f
cp := cp
CCFLAGS += -D OSX
BITS = $(shell getconf LONG_BIT)
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
CCFLAGS += -D AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
CCFLAGS += -D IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
CCFLAGS += -D ARM
endif
endif
#Define flags for compile & link
CFLAGS = -I$(HDRDIR) -std=c11 -m64 -fopenmp -Wall -Werror -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wlogical-op -Wcast-align -Wconversion -Wpedantic -Wfloat-equal -w -O0 -DGLEW_STATIC
LFLAGS = -L$(LIBDIR)
#Do we want verbose linker messages?
LVERBOSE := false
LLIBS =
ifeq ($(OS),win)
LLIBS += -lglfw3-$(BITS) -lglew32s -lglew32 -lopengl32 -lgdi32 -lwinmm
endif
ifeq ($(OS),lin)
LLIBS += -lglew32s -lglew32 -lGL -lm
endif
ifeq ($(LVERBOSE),true)
LFLAGS += -Wl,--verbose
endif
TARGET = program$(EXT)
#Rules
$(BINDIR)/$(TARGET): $(OBJS)
#$(CC) -o ./$# $(OBJS) $(LFLAGS) $(LLIBS)
#echo Linking complete.
#$(cp) $(LIBDIR)\glfw3.dll $(BINDIR)
#echo DLLs accompanying executable.
$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
#$(CC) $(CFLAGS) -c $< -o ./$#
#echo Compiled $<.
.PHONEY: clean
clean:
ifeq ($(OS),win)
#$(rm) $(subst /,\\,$(OBJS))
#$(rm) $(subst /,\\,$(BINDIR)/*.*)
else
#$(rm) $(OBJS)
#$(rm) $(BINDIR)/*
endif
#echo Cleanup complete.
#$(subst /,\\, $(SOMETHING)) replaces all (make-native) forward slashes with backslashes, for Windows.
Hello I need to compute logarithms on my stm32. I use arm-none-eabi-gcc. When I add -L/opt/tools/Sourcery_G++_Lite/arm-none-eabi/lib/ in my Makefile microcontroller stop to work. Unfortunately I can't debug my program because there is no debag pins on my device and I load program to flash via bootloader. I not use any math functioins from libraries - i just add library path to Makefile.
Here is my full makefile:
OUTPUTDIR = $(BUILDDIR)/../../output
DEPDIR = $(BUILDDIR)/.dep
PWD = $(shell pwd)
COMMONFLAGS = -mcpu=cortex-m3 -mthumb -ggdb3
CFLAGS += $(COMMONFLAGS) -Os $(INCLUDES) -I.
CFLAGS += -std=c99 -Wall -Wextra -static -fdata-sections -ffunction-sections -fno-hosted -fno-builtin
CFLAGS += -nostdlib -nodefaultlibs
CFLAGS += -mapcs-frame -msoft-float
CFLAGS += -MD -MP -MF $(DEPDIR)/$(#F).d
LDFLAGS = $(COMMONFLAGS) -static
LDFLAGS += -fno-exceptions -ffunction-sections -fdata-sections
LDFLAGS += -static -Xlinker --gc-sections
#LDFLAGS += -L/opt/tools/dima/Sourcery_G++_Lite/arm-none-eabi/lib/
ASFLAGS = $(COMMONFLAGS)
CFLAGS += -DUSE_STDPERIPH_DRIVER
CROSS = /opt/tools/Sourcery_G++_Lite/bin/arm-none-eabi
GCC = $(CROSS)-gcc
AS = $(CROSS)-as
SIZE = $(CROSS)-size
OBJCOPY = $(CROSS)-objcopy
OBJDUMP = $(CROSS)-objdump
NM = $(CROSS)-nm
COBJ = $(addprefix $(BUILDDIR)/, $(CSRC:.c=.c.o))
ASMOBJ = $(addprefix $(BUILDDIR)/, $(ASMSRC:.s=.s.o))
OBJ = $(COBJ) $(ASMOBJ)
V = $(if $(VERBOSE), , #)
all: prebuild $(BUILDDIR)/$(TARGET).elf $(LDSCRIPT)
#$(SIZE) $(BUILDDIR)/$(TARGET).elf
#$(OBJCOPY) -O binary $(BUILDDIR)/$(TARGET).elf $(BUILDDIR)/$(TARGET).bin
#$(OBJCOPY) -O ihex $(BUILDDIR)/$(TARGET).elf $(BUILDDIR)/$(TARGET).hex
#$(OBJDUMP) -h -S -z $(BUILDDIR)/$(TARGET).elf > $(BUILDDIR)/$(TARGET).lss
#$(NM) -n $(BUILDDIR)/$(TARGET).elf > $(BUILDDIR)/$(TARGET).sym
#mkdir -p $(OUTPUTDIR)
#cp $(BUILDDIR)/$(TARGET).bin $(OUTPUTDIR)
#echo =======================================================================
$(BUILDDIR)/$(TARGET).elf: $(OBJ)
#echo Linking $#
$(GCC) $(LDFLAGS) -T $(PWD)/$(LDSCRIPT) -o $# $(OBJ) -lm
$(COBJ): $(BUILDDIR)/%.c.o : %.c
#echo Compiling $<
#-mkdir -p $(#D)
$(GCC) $(CFLAGS) -c $< -o $#
$(ASMOBJ): $(BUILDDIR)/%.s.o : %.s
#echo Assembling $<
#-mkdir -p $(#D)
$(V)$(AS) $(ASFLAGS) -c ./$< -o $#
-include $(shell mkdir -p $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*)
.PHONY: clean output
clean:
rm -rf $(BUILDDIR)
What i do wrong? Thanks.
Whith this library dir you will simply link against the wrong set of files in multilib, and end up linking with ARM code while your MCU can only execute THUMB code. The correct set of files should be in the thumb2 subdirectory for Cortex M3 µC.
Note that Sourcery G++ lite will auto-magically add the correct library dir when using arm-none-eabi-gcc to link, which your Makefile seems to do already.
You really shouldn't link libm.a manually and you really shouldn't hardcode library path manually... This all gets done automatically (and correctly) if you use arm-none-eabi-gcc (or -g++) to link and give proper flags (-mcpu and -mthumb). So just drop all these paths and "-lm" and it must work. You could try one of my example project for ARM microcontrollers - the settings in the makefiles (and linker scripts) make all of this work just fine - with no user intervention. http://www.freddiechopin.info/en/download/category/6-examples
Also - I think part of the problem may be in these flags you use: -fno-hosted -fno-builtin -nostdlib -nodefaultlibs - the last one especially prevents this automatic linking of libm.a.