Undefined reference to `compress2' and other functions in the HDF5 library - makefile

I am trying to make a code called iPIC3D and it has some prerequisite libraries such as HDF5, H5hut etc. I did everything as instructed. One has to install all the prerequisites and then run the "make" command. But while running the make command, I get a series of errors such as
/usr/local/hdf5/1.8.11-par/lib/libhdf5.a(H5Zdeflate.o): In function `H5Z_filter_deflate':
H5Zdeflate.c:(.text+0xf1): undefined reference to `compress2'
H5Zdeflate.c:(.text+0x1af): undefined reference to `inflateInit_'
H5Zdeflate.c:(.text+0x1c9): undefined reference to `inflate'
H5Zdeflate.c:(.text+0x27a): undefined reference to `inflateEnd'
H5Zdeflate.c:(.text+0x2dc): undefined reference to `inflateEnd'
H5Zdeflate.c:(.text+0x3de): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
Here is a copy of my makefile for reference
PIC_HOME = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
## SECTION THAT DEPENDS ON THE SYSTEM
# -- Modify this variables according
# -- to your system options.
# -- Possible flags:
# -DPARALLEL_IO Use parallel HDF5
# -DUSEH5HUT Use H5hut (must include also -DPARALLEL_IO)
# -DBATSRUS Coupling with BATS-R-US
CXX = mpicxx
HDF5_HOME = /usr/local/hdf5/1.8.11-par
H5HUT_HOME = /usr/local/H5hut/1.8.11
IPIC_FLAGS = "-DUSEH5HUT -DPARALLEL_IO"
## END OF SECTION
OPTIM = -O3
HDF5_LIB = $(HDF5_HOME)/lib/libhdf5_hl.a $(HDF5_HOME)/lib/libhdf5.a
H5HUT_LIB = $(H5HUT_HOME)/lib/libH5hut.a
H5HUTIO_LIB = $(IPIC_HOME)/H5hut-io/libH5hut-io.a
INC_DIR = ./include
INC_H5HUT = $(H5HUT_HOME)/include
INC_H5HUTIO = $(IPIC_HOME)/H5hut-io/include
INC_HDF5 = $(HDF5_HOME)/include
.SUFFIXES:
.SUFFIXES: .cpp .o .h
SRC = \
$(IPIC_HOME)/grids/Grid3DCU.cpp \
$(IPIC_HOME)/fields/BCStructure.cpp \
$(IPIC_HOME)/fields/EMfields3D.cpp \
$(IPIC_HOME)/inputoutput/phdf5.cpp \
$(IPIC_HOME)/inputoutput/Restart3D.cpp \
$(IPIC_HOME)/inputoutput/ParallelIO.cpp \
$(IPIC_HOME)/inputoutput/Collective.cpp \
$(IPIC_HOME)/performances/Timing.cpp \
$(IPIC_HOME)/PSKOutput3D/PSKhdf5adaptor.cpp \
$(IPIC_HOME)/bc/BcParticles.cpp \
$(IPIC_HOME)/bc/BcFields3D.cpp \
$(IPIC_HOME)/mathlib/EllipticF.cpp \
$(IPIC_HOME)/solvers/CG.cpp \
$(IPIC_HOME)/solvers/GMRES.cpp \
$(IPIC_HOME)/ConfigFile/src/ConfigFile.cpp \
$(IPIC_HOME)/main/iPic3Dlib.cpp \
$(IPIC_HOME)/particles/Particles3Dcomm.cpp \
$(IPIC_HOME)/particles/Particles3D.cpp \
$(IPIC_HOME)/communication/ComNodes3D.cpp \
$(IPIC_HOME)/communication/ComParser3D.cpp \
$(IPIC_HOME)/communication/ComInterpNodes3D.cpp \
$(IPIC_HOME)/communication/ComParticles3D.cpp \
ALLOBJ = $(subst .cpp,.o,$(SRC))
IPIC3D_EXE = $(IPIC_HOME)/iPic3D
IPIC3D_LIB = $(IPIC_HOME)/libiPic3Dlib.a
LDLIBS = $(IPIC3D_LIB) $(H5HUTIO_LIB) $(H5HUT_LIB) $(HDF5_LIB) -ldl
all : io lib main
io :
CXX=$(CXX) HDF5_HOME=$(HDF5_HOME) H5HUT_HOME=$(H5HUT_HOME) IPIC_FLAGS=$(IPIC_FLAGS) $(MAKE) -C $(IPIC_HOME)/H5hut-io
lib : $(ALLOBJ)
$(AR) sr $(IPIC3D_LIB) $(ALLOBJ)
ranlib $(IPIC3D_LIB)
main : iPic3D.o
$(CXX) $(LDFLAGS) -I$(INC_DIR) -I$(INC_HDF6) iPic3D.cpp -o $(IPIC3D_EXE) $(LDLIBS)
clean : cleanio
$(RM) $(ALLOBJ)
$(RM) $(IPIC3D_LIB)
$(RM) iPic3D.o
$(RM) $(IPIC3D_EXE)
cleanio :
$(MAKE) -C $(IPIC_HOME)/H5hut-io clean
%.o : %.cpp
echo " Compiling " $#
$(CXX) $(CXXFLAGS) $(OPTIM) $(IPIC_FLAGS) -I$(INC_DIR) -I$(INC_H5HUTIO) -I$(INC_H5HUT) -I$(INC_HDF5) -c $< -o $#
I am unable to understand what exactly is causing this problem.

I would say you are missing linking in the libz library as this is where the compress2 function should come from. Try adding -lz to your LDLIBS.

Related

makefile, gcc, arm-cortex collect2.exe: error: ld returned 1 exit status

This makefile is autogenerated by STM32CubeMX. I am getting this linker error when I am using the arm-gnu-toolchain version > 9.2.1. I need to solve this problem. I cannot use the version in which the make is working fine because the openocd debugger is not compatible with arm-gnu-toolchain version 9.2.1
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.13.0-B3] date: [Thu Mar 11 18:44:56 IST 2021]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = Testing_fes_bms
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES = \
Core/Src/main.c \
Core/Src/freertos.c \
Core/Src/stm32l4xx_it.c \
Core/Src/stm32l4xx_hal_msp.c \
Core/Src/stm32l4xx_hal_timebase_tim.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c \
/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_can.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c \
Core/Src/system_stm32l4xx.c \
Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
Middlewares/Third_Party/FreeRTOS/Source/list.c \
Middlewares/Third_Party/FreeRTOS/Source/queue.c \
Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \
Middlewares/Third_Party/FreeRTOS/Source/tasks.c \
Middlewares/Third_Party/FreeRTOS/Source/timers.c \
Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \
BMS_OPERATION/BMS_OPERATION.c \
EXTERNAL_COMMUNICATION/USART_OPERATION.c \
AFE_OPERATION/AFE_OPERATION.c \
CAN_OPERATION/can.c
#===============================================#
# ASM CONFIG #
#===============================================#
# 433
#ASM_SOURCES = \
#startup_stm32l433rctxp.s
# 431
ASM_SOURCES = \
startup_stm32l431xx.s
#===============================================#
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
#===============================================#
# C DEFINE #
#===============================================#
# 433
#C_DEFS = \
#-DUSE_HAL_DRIVER \
#-DSTM32L433xx
# 431
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32L431xx
#===============================================#
# AS includes
AS_INCLUDES = \
-ICore/Inc
# C includes
C_INCLUDES = \
-ICore/Inc \
-IDrivers/STM32L4xx_HAL_Driver/Inc \
-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy \
-IMiddlewares/Third_Party/FreeRTOS/Source/include \
-IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
-IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \
-IDrivers/CMSIS/Device/ST/STM32L4xx/Include \
-IDrivers/CMSIS/Include \
-IAFE_OPERATION \
-IBMS_OPERATION \
-IEXTERNAL_COMMUNICATION \
-ICAN_OPERATION
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(#:%.o=%.d)"
#===============================================#
# LINKER CONFIG #
#===============================================#
# 433
#LDSCRIPT = STM32L433RCTXP_FLASH.ld
# 431
LDSCRIPT = STM32L431CBTx_FLASH.ld
#===============================================#
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $#
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $#
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $#
$(SZ) $#
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $#
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $#
$(BUILD_DIR):
mkdir $#
#flash: build/Testing_fes_bms.bin
# st-flash write build/Testing_fes_bms.bin 0x8000000
# python3 reader_python.py
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
This is the error I am getting
PS C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN> make
arm-none-eabi-gcc build/main.o build/freertos.o build/stm32l4xx_it.o build/stm32l4xx_hal_msp.o build/stm32l4xx_hal_timebase_tim.o build/stm32l4xx_hal_adc.o build/stm32l4xx_hal_adc_ex.o build/stm32l4xx_hal_can.o build/stm32l4xx_hal.o build/stm32l4xx_hal_i2c.o build/stm32l4xx_hal_i2c_ex.o build/stm32l4xx_hal_rcc.o build/stm32l4xx_hal_rcc_ex.o build/stm32l4xx_hal_flash.o build/stm32l4xx_hal_flash_ex.o build/stm32l4xx_hal_flash_ramfunc.o build/stm32l4xx_hal_gpio.o build/stm32l4xx_hal_dma.o build/stm32l4xx_hal_dma_ex.o build/stm32l4xx_hal_pwr.o build/stm32l4xx_hal_pwr_ex.o build/stm32l4xx_hal_cortex.o build/stm32l4xx_hal_exti.o build/stm32l4xx_hal_tim.o build/stm32l4xx_hal_tim_ex.o build/stm32l4xx_hal_uart.o build/stm32l4xx_hal_uart_ex.o build/system_stm32l4xx.o build/croutine.o build/event_groups.o build/list.o build/queue.o build/stream_buffer.o build/tasks.o build/timers.o build/cmsis_os2.o build/heap_4.o build/port.o build/BMS_OPERATION.o build/USART_OPERATION.o build/AFE_OPERATION.o build/can.o build/startup_stm32l431xx.o -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nano.specs -TSTM32L431CBTx_FLASH.ld -lc -lm -lnosys -Wl,-Map=build/Testing_fes_bms.map,--cref -Wl,--gc-sections -o build/Testing_fes_bms.elf
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/stm32l4xx_it.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/BMS_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:65: multiple definition of `USART_RX_Queue_Data'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:65: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:64: multiple definition of `USART_TASK_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:64: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:59: multiple definition of `USART_RX_st_tag_Obj'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:59: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/AFE_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
/11.3.1/thumb/v7e-m+fp/hard\libc_nano.a(libc_a-writer.o): in function `_write_r':/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/writer.c:49: warning: _write is not implemented and will always fail
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:225: build/Testing_fes_bms.elf] Error 1
This is line 225 where the error is occuring
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $#
$(SZ) $#
At last, after a month I was able to resolve this issue. The error was resolved once I solved the following errors
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/stm32l4xx_it.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/BMS_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: multiple definition of `QUEUE_bmsqueue_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/BMS_OPERATION/BMS_OPERATION.h:136: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:65: multiple definition of `USART_RX_Queue_Data'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:65: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:64: multiple definition of `USART_TASK_handler'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:64: first defined here
c:/users/syedk/downloads/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: build/USART_OPERATION.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:59: multiple definition of `USART_RX_st_tag_Obj'; build/main.o:C:\Users\syedk\Downloads\FES_BMS-v1.5.3_CAN\FES_BMS-v1.5.2_CAN/EXTERNAL_COMMUNICATION/USART_OPERATION.h:59: first defined here
The issue seems to be that the variables defined in header files need the extern keyword. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions, this error is ignored. From GCC 10 a linker error will be reported. Hence the reason why the code was not getting compiled in arm toolchain version > 9

Makefile is always 'up to date' while files have been changed

I have a Makefile to compile several fortran files, most of which are module files. Whenever I changed the module file and initiate make command, the make says:
make: `PRM' is up to date.
PRM is the executable name. No such problem when I changed the main file. Another problem is that sometimes I also get:
make: m2c: Command not found
error. My makefile looks like:
.SUFFIXES: .f90
F90 = pgf90
NETCDF_DIR = /opt/netcdf
F90_FLAGS = -Mbackslash -Mlarge_arrays
LIBS = -L$(NETCDF_DIR)/lib -lnetcdff -lnetcdf
INCLUDE_MODULES = -I$(NETCDF_DIR)/include
VPATH = /path/FORTRAN
util_module = \
precmod.o \
strings.o
EXEC = PRM
OBJS = \
${util_module} \
mo_date.o \
mo_utils.o \
module_metcro_lib.o \
module_plumerise1.o \
module_finn_lib.o \
main_plm.o
${EXEC} : ${OBJS}
${F90} -o $# ${OBJS} ${LIBS}
.f90.o:
${F90} -c ${F90_FLAGS} ${INCLUDE_MODULES} $<
clean:
rm -f ${EXEC} ${OBJS} *.mod
thanks for answering!

running linker in bare-metal arm example and linker can't find the loader file which exists

I found a bare-metal example for a board different from mine so I will have to modify the loader script but for now I just want to be able to compile and link the example as it is.
I copied the arm-none-eabi cross-compiler to the directory just above c_blinky which is where the source files are.
(I have a diagram of the directory structure on a page on my website)
Here's the makefile:
ifeq ($(GNU_ARM),)
GNU_ARM = ../arm-none-eabi/bin
endif
CC := $(GNU_ARM)/arm-none-eabi-gcc
CPP := $(GNU_ARM)/arm-none-eabi-g++
ASM := $(GNU_ARM)/arm-none-eabi-as
LINK := $(GNU_ARM)/arm-none-eabi-gcc
BIN := $(GNU_ARM)/arm-none-eabi-objcopy
RM := rm -rf
MKDIR := mkdir
BLDDIR = .
CCINC = -I$(BLDDIR)
APP_DEP = $(BLDDIR)/bsp.h \
$(BLDDIR)/arm_exc.h \
$(BLDDIR)/isr.h
APP_NAME = blinky
ARM_CORE = arm7tdmi
ifeq (rel, $(CONF)) # Release configuration
BINDIR = rel
CCFLAGS = -c -mcpu=$(ARM_CORE) -mthumb-interwork -Os \
-mlong-calls -ffunction-sections -Wall -DNDBEBUG -o$#
ASMFLAGS = -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
else # default Debug configuration
BINDIR = dbg
CCFLAGS = -g -c -mcpu=$(ARM_CORE) -mthumb-interwork -O \
-mlong-calls -ffunction-sections -Wall -o$#
ASMFLAGS = -g -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
endif
all: $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).bin : $(BINDIR)/$(APP_NAME).elf
$(BIN) -O binary $(BINDIR)/$(APP_NAME).elf $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).elf : \
./$(APP_NAME).ld \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o
$(LINK) \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o \
$(LINKFLAGS)
$(BINDIR)/startup.o: $(BLDDIR)/startup.s
$(ASM) $(ASMFLAGS) $<
$(BINDIR)/arm_exc.o: $(BLDDIR)/arm_exc.s
$(ASM) $(ASMFLAGS) $<
# choose the ARM or THUMB compilation for each module...
$(BINDIR)/low_level_init.o: $(BLDDIR)/low_level_init.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/isr.o: $(BLDDIR)/isr.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/bsp.o: $(BLDDIR)/bsp.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
$(BINDIR)/blinky.o: $(BLDDIR)/blinky.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
I set GNU_ARM in the makefile to ../arm-none-eabi/bin and ran make and got the following error:
(the file blinky.ld does exist in the source directory)
../arm-none-eabi/bin/arm-none-eabi-gcc \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: cannot open linker script file .blinky.ld: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [dbg/blinky.elf] Error 1
I thought the LINK assignment at the beginning should be:
LINK := $(GNU_ARM)/arm-none-eabi-ld
and not
LINK := $(GNU_ARM)/arm-none-eabi-gcc
and I got:
../arm-none-eabi/bin/arm-none-eabi-ld \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
../arm-none-eabi/bin/arm-none-eabi-ld: cannot open linker script file .blinky.ld: No such file or directory
make: *** [dbg/blinky.elf] Error 1
It looks like arm-none-eabi-gcc is calling collect2 in lib/gcc/arm-none-eabi/4.9.3 which in turn calls ld which is not in the main bin directory:
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
I tried making a symbolic link to arm-none-eabi-ld as ld and got the same error.

Including a static library in makefile

I have a directory structure
trunk
--lib--libParser.a
--objs
--src
--Makefile
I have the following makefile
CRYPTOLIB_TARGET = cryptolib.a
LOCALLIBS = ./objs
LOCALLIBS_IMAGE = ./cryptolib.a
CC = gcc
AR = ar
DEBUG_FLAGS =
LDEFSECOM_LOG_VERSION = -DSECOM_LOG_VERSION
CMPL_TIME_MACROS = -DENBL_DEBUG_PRINTF $(LDEFSECOM_LOG_VERSION)
ALLWARN =
ALL_INCS = -I./src/INCLUDE
LIBS = -lrt -laio -lrt -lpthread -lm -lpq -ldl
LINK = $(CC) $(DEBUG_FLAGS) $(CMPL_TIME_MACROS) $(ALLWARN) $(ALL_INCS) $(LIBS) -c
default = CRYPTOLIB_TARGET
CRYPTOLIB_OBJ = \
$(LOCALLIBS)/AES_crypt.o \
$(LOCALLIBS)/bigdigits.o \
$(LOCALLIBS)/DataEncryption.o \
$(LOCALLIBS)/SiaEncryption.o
$(CRYPTOLIB_TARGET): $(CRYPTOLIB_OBJ)
$(AR) r $(CRYPTOLIB_TARGET) $(CRYPTOLIB_OBJ)
$(LOCALLIBS)/AES_crypt.o : \
src/AES_crypt.c
mkdir -p ./objs
$(LINK) src/AES_crypt.c -o $(LOCALLIBS)/AES_crypt.o
$(LOCALLIBS)/bigdigits.o : \
src/bigdigits.c
$(LINK) src/bigdigits.c -o $(LOCALLIBS)/bigdigits.o
$(LOCALLIBS)/DataEncryption.o : \
src/DataEncryption.c
$(LINK) src/DataEncryption.c -o $(LOCALLIBS)/DataEncryption.o
$(LOCALLIBS)/SiaEncryption.o : \
src/SiaEncryption.c
$(LINK) src/SiaEncryption.c -o $(LOCALLIBS)/SiaEncryption.o
clean:
rm -rf objs
rm -rf cryptolib.a
I want to include the libParser.a in the output library which I am creating but I am not sure how to do that. Can you please give me the pointers to so that I can include the library(libParser.a) and create cryptolib.a as a final output library.
from gcc online docs:
-llibrary
-l library
...(text removed)...
Normally the files found this way are library files—archive files
whose members are object files. The linker handles an archive file by
scanning through it for members which define symbols that have so far
been referenced but not defined. But if the file that is found is an
ordinary object file, it is linked in the usual fashion. The only
difference between using an -l option and specifying a file name is
that -l surrounds library with ‘lib’ and ‘.a’ and searches several
directories.
So... you could specify the library include folder:
-L./lib
and put the libParser.a in the list of libraries (subracting 'lib' and '.a'):
-lParser -lrt -laio ...

makefile implicit rule -- confused

I am working on a project where makefile is used to make an target.
Here i am confused how makefile is generating .o files from the .cpp file.
Like file clientthread_level1_unix.o have to be generated from clientthread_level1_unix.cpp file.
But no where it is specified to use *.cpp file for it.
EXTRALIBS = -pthread -lz -ldl -lm
OPENGLLIBS =
LDFLAGS_GL =
LDLIBS = ${APPEXTRALIBS} ${top_builddir}/lib/libwx_based-2.6.a ${EXTRALIBS}
# Compiler used
CXX = c++
CC = gcc
CANALOBJS = ../../common/listenthread_unix.o ../../common/clientthread_level1_unix.o ../../common/devicethread_unix.o \
../../common/canalshmem_level1_unix.o ../../common/clientlist.o ../../common/controlobject.o \
../../common/devicelist.o ../../common/udpreceivethread_unix.o ../../../vscp/common/vscp.o \
../../common/clientthread_level2_unix.o ../../common/canalshmem_level2_unix.o \
../../common/tcplistenthread.o
CANALHDRS = ../../common/clientlist.h ../../common/controlobject.h ../../common/devicelist.h \
../../common/canal.h ../../common/canaldlldef.h \
../../common/version.h ../../common/canal_unix_ipc.h ../../common/CanalShMem_level1_unix.h \
../../common/CanalShMem_level2_unix.h ../../common/clientthread_level1_unix.h ../../common/clientthread_level2_unix.h
PROJOBJS = ../../../common/dllist.o ../../../common/configfile.o ../../../common/crc.o
PROJHDRS = ../../../common/dllist.h ../../../common/configfile.h
OBJS = canald.o
HDRS = canald.h
all: canald
# Build the Linux executable
canald: $(OBJS) $(HDRS) $(CANALOBJS) $(CANALHDR) $(PROJOBJS) $(PROJHDRS)
$(CXX) $(OBJS) $(CANALOBJS) $(PROJOBJS) -o canald $(LIBS) $(LDLIBS)
If we use the Implicit rule then also, then also canald target is not as per that.
http://www.gnu.org/software/make/manual/make.html#make-Deduces
http://www.gnu.org/software/make/manual/make.html#Implicit-Rules
Please sugest how is this line working to produce canald ?
$(CXX) $(OBJS) $(CANALOBJS) $(PROJOBJS) -o canald $(LIBS) $(LDLIBS)
The line
$(CXX) $(OBJS) $(CANALOBJS) $(PROJOBJS) -o canald $(LIBS) $(LDLIBS)
will approximately (I skipped not defined variables) be translated into:
c++ canald.o ../../common/listenthread_unix.o ../../common/clientthread_level1_unix.o ../../common/devicethread_unix.o \
../../common/canalshmem_level1_unix.o ../../common/clientlist.o ../../common/controlobject.o \
../../common/devicelist.o ../../common/udpreceivethread_unix.o ../../../vscp/common/vscp.o \
../../common/clientthread_level2_unix.o ../../common/canalshmem_level2_unix.o \
../../common/tcplistenthread.o \
../../../common/dllist.o ../../../common/configfile.o ../../../common/crc.o \
-o canald /lib/libwx_based-2.6.a -pthread -lz -ldl -lm
i.e., a "normal" compiler call. Since there is an explicit rule for canald, there is no need to search for implicite ones. In addition, it is the target rule in the Makefile, thus it is the default target.
Howerver, for objects canald depends on, no explicit rule exist, thus the implicit rules are used.
If you want to know, which implicit rules exist, call make -p and search in the output for the pattern, e.g. in your case for %.cpp.

Resources