Using FFMPEG library in PPAPI: Naclports with FFmpeg - ffmpeg

I have configured Webports, ffmpeg; and I have created the following Makefile for the current project. However, I have met some problem with ffmpeg library linking.
$ TOOLCHAIN=pnacl make
LINK pnacl/Release/client_unstripped.bc
pnacl/Release/src/client.o: error: undefined reference to 'av_register_all'
make: *** [pnacl/Release/client_unstripped.bc] Error 1
Can you tell me what I am doing wrong here, my Makefile is shown below:
VALID_TOOLCHAINS := pnacl glibc clang-newlib win
NACL_SDK_ROOT ?= $(abspath $(CURDIR)/../..)
TARGET = client
OTHERDIR=src
INC_DIR = inc
FFMPEG_INC_DIR = ../../toolchain/mac_pnacl/le32-nacl/usr/include
INCLUDES = -I$(INC_DIR) -I$(FFMPEG_INC_DIR)
include $(NACL_SDK_ROOT)/tools/common.mk
CHROME_ARGS += --allow-nacl-socket-api=localhost
LIBS = nacl_io ppapi_cpp ppapi
CFLAGS = -Wall -g -O2 $(INCLUDES)
-L../../toolchain/mac_pnacl/le32-nacl/usr/lib -lavformat \
-lvpx -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lavcodec -lvpx -lvorbisenc -lvorbis -logg \
-ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lswresample -lm -lavutil -lm -lavdevice -lavfilter
SOURCES = $(OTHERDIR)/tcp_util.cc $(OTHERDIR)/tpool.cc
$(OTHERDIR)/net.cc $(OTHERDIR)/rtsp_response.cc \ $(OTHERDIR)/rtsp.cc
$(OTHERDIR)/rtsp_common.cc \ $(OTHERDIR)/rtsp_client.cc
$(OTHERDIR)/udp_util.cc \ $(OTHERDIR)/client.cc
# Build rules generated by macros from common.mk:
$(foreach src,$(SOURCES),$(eval $(call
COMPILE_RULE,$(src),$(CFLAGS))))
# The PNaCl workflow uses both an unstripped and finalized/stripped binary.
# On NaCl, only produce a stripped binary for Release configs (not Debug). ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring
Release,$(CONFIG)))) $(eval $(call
LINK_RULE,$(TARGET)_unstripped,$(SOURCES),$(LIBS),$(DEPS))) $(eval
$(call STRIP_RULE,$(TARGET),$(TARGET)_unstripped)) else $(eval $(call
LINK_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS))) endif
$(eval $(call NMF_RULE,$(TARGET),))
And here is the way, how the library has been used in the class context.
class VideoDecodePack {
public:
VideoDecodePack() {
av_register_all();
}
};
class ClientInstance : public pp::Instance {
public:
explicit ClientInstance(PP_Instance instance) : pp::Instance(instance){
cses = InitRtspClientSession();
_videoDecoder = new VideoDecodePack();
}
...

I have solved this problem by adding linking with additional libraries for FFMPEG: vpx, vorbis, lame. And it is very important to keep the order of linked libraries.
.....
...
TARGET = client
INC_DIR := inc
include $(NACL_SDK_ROOT)/tools/common.mk
DEPS = ppapi_simple nacl_io
LIBS = ppapi_simple nacl_io ppapi pthread \
avformat vpx vorbisenc vorbis ogg theoraenc \
theoradec mp3lame m avcodec swresample avutil \
avdevice avfilter
OTHERDIR = src
CFLAGS = -Wall
# -I$(INC_DIR)
SOURCES = $(OTHERDIR)/client.cc
# Build rules generated by macros from common.mk:
$(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
....
...

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

Why does my makefile never stop building?

I am trying to create a makefile to control the build process. I use eclipse and I have a lot of projects some of which are shared libraries. So if I build a project that is using a library, then I would like the library to be built if it is out of date. The seems pretty standard. I just cannot make it work.
I am making the linking dependent on the libraries, and I (try to) provide a rule for building the libraries. But when I do it this way, it seems to be building the library over and over again - and it never finishes. What am I missing?
CPPUTEST_HOME = ...
PROJECTROOT := ...
SDKTARGETSYSROOT := /opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa9hf-neon-poky-linux-gnueabi
COMPONENT_NAME := Jehova
USER_LIB :=
INCLUDE_DIRS := $(PROJECTROOT)/Log/source \
$(PROJECTROOT)/Config/source \
LIBS := $(PROJECTROOT)/Log/bin/libLog.so \
$(PROJECTROOT)/Config/bin/libConfig.so \
# Links to the commands to be used
REMOVE := rm -rf
COMPILER := arm-poky-linux-gnueabi-g++
# All of the sources participating in the build are defined here
SOURCEDIR = source
OBJECTDIR = objects
TEST_DIR = utest
PATH_TO_MAIN = source/main.cpp
SOURCES = $(wildcard $(SOURCEDIR)/*.cpp)
OBJECTS = $(patsubst $(SOURCEDIR)/%.cpp, $(OBJECTDIR)/%.o, $(SOURCES))
DEPENDENCIES = $(patsubst $(SOURCEDIR)/%.cpp, $(OBJECTDIR)/%.d, $(SOURCES))
# Paths to the headerfiles
get_dirs_from_dirspec = $(wildcard $1)
INCLUDE_DIRS += $(USER_LIB) \
$(SDKTARGETSYSROOT)/usr/include/ \
$(SDKTARGETSYSROOT)/usr/include/c++/7.3.0/ \
$(SDKTARGETSYSROOT)/usr/include/c++/7.3.0/arm-poky-linux-gnueabi/
INCLUDE_DIR_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS))
COMPILE_INCLUDE = $(foreach dir, $(INCLUDE_DIR_EXPANDED), -I$(dir))
LINK_INCLUDE = $(foreach dir, $(INCLUDE_DIR_EXPANDED), -L$(dir))
# Compiler and linkerflags
COMPILER_FLAGS := -Wall -c -fmessage-length=0 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 -Wno-unknown-pragmas --sysroot=$(SDKTARGETSYSROOT)
LINKER_FLAGS := -mfloat-abi=hard -lpthread
# If main.cpp does not exist the project is assumed to be a shared library
ifeq ("$(wildcard $(PATH_TO_MAIN))","")
COMPILER_FLAGS += -fPIC
LINKER_FLAGS += -shared -o
BIN := ./bin/lib$(COMPONENT_NAME).so
else
LINKER_FLAGS += -o
BIN := ./bin/$(COMPONENT_NAME)
endif
# Optimization and debug levels
ifeq ($(MAKECMDGOALS),release)
COMPILER_FLAGS += -O3
else
COMPILER_FLAGS += -O0 -g3
endif
# Include dependencies
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPENDENCIES)),)
-include $(DEPENDENCIES)
endif
endif
# All Target
all: $(BIN) test
-$(REMOVE) makeenv
# Compile source to create object files
./objects/%.o: ./source/%.cpp
#echo 'Building file: $<'
#echo 'Invoking: Cross G++ Compiler'
-$(COMPILER) $(COMPILE_INCLUDE) $(COMPILER_FLAGS) -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#)" -o "$#" "$<"
#echo 'Finished building: $<'
#echo ' '
# Link objects to build target
$(BIN): $(OBJECTS) $(LIBS)
#echo 'Building target: $#'
#echo 'Invoking: Cross G++ Linker'
-$(COMPILER) $(LINK_INCLUDE) --sysroot=$(SDKTARGETSYSROOT) $(LINKER_FLAGS) $(BIN) $(OBJECTS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
# All Target release build
release: clean $(BIN)
-$(REMOVE) makeenv
# Run the test
test: $(BIN)
make -C $(TEST_DIR)
# Other Targets
clean:
-$(REMOVE) $(OBJECTS)$(DEPENDENCIES) $(BIN)
make -C $(TEST_DIR) clean
-$(REMOVE) makeenv
-#echo ' '
$(LIBS):
-cd $(PROJECTROOT)/Config && $(MAKE) clean all release
-cd $(PROJECTROOT)/Log && $(MAKE) clean all release

Adding static library file to the makefile

I have following makefile executed by python script:
SOURCES_DIRECTORY = sources
# These directories should be created by build.py script
BUILD_DIRECTORY = builds
OBJECTS_DIRECTORY = objs
CORE = cortex-m4
LINKER_SCRIPT = linker_rom.ld
# C definitions
ifeq ($(RAM_FLASH), 1)
C_DEFS = -DRAM_FLASH
else
C_DEFS =
endif
INC_DIRS = sources
SRCS_DIRS = sources
# extension of C files
C_EXT = c
# wildcard for C source files (all files with C_EXT extension found in current
# folder and SRCS_DIRS folders will be compiled and linked)
C_SRCS = $(wildcard $(patsubst %, %/*.$(C_EXT), . $(SRCS_DIRS)))
# extension of ASM files
AS_EXT = s
# wildcard for ASM source files (all files with AS_EXT extension found in
# current folder and SRCS_DIRS folders will be compiled and linked)
AS_SRCS = $(wildcard $(patsubst %, %/*.$(AS_EXT), . $(SRCS_DIRS)))
# optimization flags ("-O0" - no optimization, "-O1" - optimize, "-O2" -
# optimize even more, "-Os" - optimize for size or "-O3" - optimize yet more)
OPTIMIZATION = -Og
# set to 1 to optimize size by removing unused code and data during link phase
REMOVE_UNUSED = 1
C_WARNINGS = -Wall -Wextra -Werror
# C language standard ("c89" / "iso9899:1990", "iso9899:199409",
# "c99" / "iso9899:1999", "gnu89" - default, "gnu99")
C_STD = c99
VPATH = $(SRCS_DIRS)
#============================================#
# Toolchain Configuration #
#============================================#
TOOLCHAIN = arm-none-eabi-
CXX = $(TOOLCHAIN)g++
CC = $(TOOLCHAIN)gcc
AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
SIZE = $(TOOLCHAIN)size
RM = rm -f
.PHONY: all clean
#=============================================================================#
# various compilation flags
#=============================================================================#
# core flags
CORE_FLAGS = -mcpu=$(CORE) -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard
# flags for C compiler
C_FLAGS = -std=$(C_STD) -g -ggdb3 -fverbose-asm -Wa,-ahlms=$(OBJECTS_DIRECTORY)/$(notdir $(<:.$(C_EXT)=.lst)) -DSTM32F429xx $(FLAGS)
# flags for assembler
AS_FLAGS = -g -ggdb3 -Wa,-amhls=$(OBJECTS_DIRECTORY)/$(notdir $(<:.$(AS_EXT)=.lst)) $(FLAGS)
# flags for linker
LD_FLAGS = -T$(LINKER_SCRIPT) -g -Wl,-Map=$(OBJECTS_DIRECTORY)/test.map,--cref,--no-warn-mismatch
# process option for removing unused code
ifeq ($(REMOVE_UNUSED), 1)
LD_FLAGS += -Wl,--gc-sections
OPTIMIZATION += -ffunction-sections -fdata-sections
endif
LIBS = libmylib.a
LIB_DIRS = ./sources
#=============================================================================#
# do some formatting
#=============================================================================#
C_OBJS = $(addprefix $(OBJECTS_DIRECTORY)/, $(notdir $(C_SRCS:.$(C_EXT)=.o)))
AS_OBJS = $(addprefix $(OBJECTS_DIRECTORY)/, $(notdir $(AS_SRCS:.$(AS_EXT)=.o)))
OBJS = $(AS_OBJS) $(C_OBJS) $(CXX_OBJS) $(USER_OBJS)
DEPS = $(OBJS:.o=.d)
INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
LIB_DIRS_F = $(patsubst %, -L%, $(LIB_DIRS))
ELF = $(BUILD_DIRECTORY)/$(NAME).elf
HEX = $(BUILD_DIRECTORY)/$(NAME).hex
BIN = $(BUILD_DIRECTORY)/$(NAME).bin
LSS = $(BUILD_DIRECTORY)/$(NAME).lss
DMP = $(BUILD_DIRECTORY)/$(NAME).dmp
# format final flags for tools, request dependancies for C++, C and asm
C_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(C_WARNINGS) $(C_FLAGS) $(C_DEFS) -MD -MP -MF $(OBJECTS_DIRECTORY)/$(#F:.o=.d) $(INC_DIRS_F)
AS_FLAGS_F = $(CORE_FLAGS) $(AS_FLAGS) $(AS_DEFS) -MD -MP -MF $(OBJECTS_DIRECTORY)/$(#F:.o=.d) $(INC_DIRS_F)
LD_FLAGS_F = $(CORE_FLAGS) $(LD_FLAGS) $(LIB_DIRS_F)
#contents of output directory
GENERATED = $(wildcard $(patsubst %, $(BUILD_DIRECTORY)/*.%, bin d dmp elf hex lss lst map o))
#=============================================================================#
# make all
#=============================================================================#
all : $(ELF) $(LSS) $(DMP) $(HEX) $(BIN)
# make object files dependent on Makefile
$(OBJS) : $(MAKEFILE_NAME)
# make .elf file dependent on linker script
$(ELF) : $(LINKER_SCRIPT)
#-----------------------------------------------------------------------------#
# linking - objects -> elf
#-----------------------------------------------------------------------------#
$(ELF) : $(OBJS)
$(CC) $(LD_FLAGS_F) $(OBJS) $(LIBS) -o $#
#-----------------------------------------------------------------------------#
# compiling - C source -> objects
#-----------------------------------------------------------------------------#
objs/%.o : %.$(C_EXT)
$(CC) -c $(C_FLAGS_F) $< -o $#
#-----------------------------------------------------------------------------#
# assembling - ASM source -> objects
#-----------------------------------------------------------------------------#
objs/%.o : %.$(AS_EXT)
$(AS) -c $(AS_FLAGS_F) $< -o $#
#-----------------------------------------------------------------------------#
# memory images - elf -> hex, elf -> bin
#-----------------------------------------------------------------------------#
$(HEX) : $(ELF)
$(OBJCOPY) -O ihex $< $#
$(BIN) : $(ELF)
$(OBJCOPY) -O binary $< $#
#-----------------------------------------------------------------------------#
# memory dump - elf -> dmp
#-----------------------------------------------------------------------------#
$(DMP) : $(ELF)
$(OBJDUMP) -x --syms $< > $#
#-----------------------------------------------------------------------------#
# extended listing - elf -> lss
#-----------------------------------------------------------------------------#
$(LSS) : $(ELF)
$(OBJDUMP) -S $< > $#
# include dependancy files
-include $(DEPS)
This is the project tree
-> /sources/
-> /sources/libmylib.a
-> /makefile
I thought adding
LIBS = libmylib.a
LIB_DIRS = ./sources
will solve the problem. My lib is libmylib.a file. However console still outputs the errors with undefined references to functions. What should I change?
Path to the directories with sources, objects, headers and flags are passed dynamically by the python script as arguments.
It should be:
LIBS = -lmylib
The compiler will prepend lib and append .a to the libraries you specify, making it look for a library file named libmylib.a which is what you want.

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.

Nvidia Cuda compilation - OpenCl error [duplicate]

I'm running Arch Linux and have installed the cuda-sdk and cuda-toolkit from the repositories. I've compiled the libraries inside /opt/cuda-sdk/CUDALibraries fine.
No I go to compile the sdk examples by running make in /opt/cuda-sdk/C and get the following error:
# make
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/shared'
make[1]: Leaving directory `/opt/cuda-sdk/shared'
make[1]: Entering directory `/opt/cuda-sdk/C/src/newdelete'
make[1]: Leaving directory `/opt/cuda-sdk/C/src/newdelete'
make[1]: Entering directory `/opt/cuda-sdk/C/src/simpleTextureDrv'
/usr/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
make[1]: *** [../../bin/linux/release/simpleTextureDrv] Error 1
make[1]: Leaving directory `/opt/cuda-sdk/C/src/simpleTextureDrv'
make: *** [src/simpleTextureDrv/Makefile.ph_build] Error 2
The Makefile itself essentially seems to just include the file /opt/cuda-sdk/C/common/common.mk, which is:
################################################################################
#
# Copyright 1993-2011 NVIDIA Corporation. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property and
# proprietary rights in and to this software and related documentation.
# Any use, reproduction, disclosure, or distribution of this software
# and related documentation without an express license agreement from
# NVIDIA Corporation is strictly prohibited.
#
# Please refer to the applicable NVIDIA end user license agreement (EULA)
# associated with this source code for terms and conditions that govern
# your use of this NVIDIA software.
#
################################################################################
#
# Common build script for CUDA source projects for Linux and Mac platforms
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin .ptx
# Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := 10 11 12 13 20 21 30
CUDA_INSTALL_PATH ?= /opt/cuda-toolkit
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)))
ifneq ($(DARWIN),)
SNOWLEOPARD = $(strip $(findstring 10.6, $(shell egrep "<string>10\.6" /System/Library/CoreServices/SystemVersion.plist)))
LION = $(strip $(findstring 10.7, $(shell egrep "<string>10\.7" /System/Library/CoreServices/SystemVersion.plist)))
endif
# detect 32-bit or 64-bit platform
HP_64 = $(shell uname -m | grep 64)
OSARCH= $(shell uname -m)
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
ROOTDIR ?= ..
ROOTBINDIR ?= $(ROOTDIR)/../bin
BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
ROOTOBJDIR ?= obj
LIBDIR := $(ROOTDIR)/../lib
COMMONDIR := $(ROOTDIR)/../common
SHAREDDIR := $(ROOTDIR)/../../shared/
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++ -fPIC
CC := gcc -fPIC
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(SHAREDDIR)/inc
# 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 \
# architecture flag for nvcc and gcc compilers build
CUBIN_ARCH_FLAG :=
CXX_ARCH_FLAGS :=
NVCCFLAGS :=
LIB_ARCH := $(OSARCH)
# Determining the necessary Cross-Compilation Flags
# 32-bit OS, but we target 64-bit cross compilation
ifeq ($(x86_64),1)
NVCCFLAGS += -m64
LIB_ARCH = x86_64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
else
# 64-bit OS, and we target 32-bit cross compilation
ifeq ($(i386),1)
NVCCFLAGS += -m32
LIB_ARCH = i386
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
ifeq "$(strip $(HP_64))" ""
LIB_ARCH = i386
NVCCFLAGS += -m32
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
LIB_ARCH = x86_64
NVCCFLAGS += -m64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
endif
endif
endif
# Compiler-specific flags (by default, we always use sm_10, sm_20, and sm_30), unless we use the SMVERSION template
GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\"
GENCODE_SM20 := -gencode=arch=compute_20,code=\"sm_20,compute_20\"
GENCODE_SM30 := -gencode=arch=compute_30,code=\"sm_30,compute_30\"
CXXFLAGS += $(CXXWARN_FLAGS) $(CXX_ARCH_FLAGS)
CFLAGS += $(CWARN_FLAGS) $(CXX_ARCH_FLAGS)
LINKFLAGS +=
LINK += $(LINKFLAGS) $(CXX_ARCH_FLAGS)
# This option for Mac allows CUDA applications to work without requiring to set DYLD_LIBRARY_PATH
ifneq ($(DARWIN),)
LINK += -Xlinker -rpath $(CUDA_INSTALL_PATH)/lib
endif
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# If we are enabling GPU based debugging, then we want to use -G, warning that this
# May have a significant impact on GPU device code, since optimizations are turned off
ifeq ($(gpudbg),1)
NVCCFLAGS += -G
dbg = $(gpudbg)
endif
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
CXXFLAGS += -D_DEBUG
CFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O2
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# architecture flag for cubin build
CUBIN_ARCH_FLAG :=
# 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
OPENGLLIB += -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
# this case for linux platforms
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
# check if x86_64 flag has been set, otherwise, check HP_64 is i386/x86_64
ifeq ($(x86_64),1)
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
else
ifeq ($(i386),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
# check if i386 flag has been set, otehrwise check HP_64 is i386/x86_64
ifeq ($(i386),1)
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
ifeq ($(x86_64),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
endif
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
ifeq ($(x86_64),1)
OPENGLLIB += -lglut -L/usr/lib64
endif
ifeq ($(i386),1)
OPENGLLIB += -lglut -L/usr/lib
endif
ifeq ($(x86_64),)
ifeq ($(i386),)
OPENGLLIB += -lglut
endif
endif
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USENVCUVID), 1)
ifneq ($(DARWIN),)
NVCUVIDLIB := -L../../common/lib/darwin -lnvcuvid
endif
endif
# Libs
ifneq ($(DARWIN),)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib $(NVCUVIDLIB)
else
ifeq "$(strip $(HP_64))" ""
ifeq ($(x86_64),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
else
ifeq ($(i386),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
endif
endif
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} -ldl -rdynamic
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB}
else
ifeq ($(emu),1)
LIB += -lcudartemu
else
LIB += -lcudart
endif
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${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
ifeq ($(USECURAND),1)
LIB += -lcurand
endif
ifeq ($(USECUSPARSE),1)
LIB += -lcusparse
endif
# Lib/exe configuration
# Lib/exe configuration
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,_$(LIB_ARCH)$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
ifneq ($(OMIT_CUTIL_LIB),1)
LIB += -lcutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifneq ($(OMIT_SHRUTIL_LIB),1)
LIB += -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
# 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)
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
ifeq ($(ptxas), 1)
NVCCFLAGS += --ptxas-options=-v
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# 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)/$(LIB_ARCH)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
################################################################################
# Set up cubin output files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Set up PTX output files
################################################################################
PTXDIR := $(SRCDIR)data
PTXBINS += $(patsubst %.cu,$(PTXDIR)/%.ptx,$(notdir $(PTXFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
$(PTXDIR)/%.ptx : $(SRCDIR)%.cu ptxdirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -ptx $<
#
# 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:
# This will be used over the default rule abov
#
# 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))))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_sm_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
# $(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) $(1)
$(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) $(GENCODE_SM30) -o $$# -c $$< $(NVCCFLAGS)
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) $(PTXBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
ptxdirectory:
$(VERBOSE)mkdir -p $(PTXDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f *.stub.c *.gpu *.cu.cpp *.i *.ii
$(VERBOSE)rm -f *.cubin *.ptx *.fatbin.c *.hash
$(VERBOSE)rm -f *.cudafe1.c *.cudafe2.c *.cudafe1.cpp *.cudafe2.cpp
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(PTXBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.ppm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.pgm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bin
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bmp
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.txt
$(VERBOSE)rm -f $(CUBINDIR)/*.cubin $(PTXDIR)/*.ptx
$(VERBOSE)rm -rf $(ROOTOBJDIR)
$(VERBOSE)rm -rf $(LIBDIR)
$(VERBOSE)rm -rf $(OBJDIR)
$(VERBOSE)rm -rf $(TARGETDIR)
clobber : clean
$(VERBOSE)rm -rf $(COMMONDIR)/lib/*.a
$(VERBOSE)rm -rf $(SHAREDDIR)/lib/*.a
$(VERBOSE)rm -rf $(COMMONDIR)/obj
$(VERBOSE)rm -rf $(SHAREDDIR)/obj
The output of echo $LD_LIBRARY_PATH is blank.
I have checked for libcuda and can find it where I think it should be:
# ls /usr/lib | grep libcuda
libcuda.so.1
libcuda.so.304.32
Is there something obvious I need to do to get these to compile? Is this a problem with the CUDA makefile or with my system?
The answer was suggested in comments, and the OP found the solution:
I added a symlink:
ln -s /usr/lib/libcuda.so.1 /usr/lib/libcuda.so
and it compiled fine.

Resources