- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为ATmega328 micro编译一些代码,并且我想使用Arduino的库和核心。我正在使用CMake。我已经编译了核心库和代码的所有对象以及Arduino的库。但是,当链接时,它们向我显示以下错误。
..."relocation truncated to fit: R_AVR_13_PCREL against symbol"..."avr5/libgcc.a"...
cmake_minimum_required(VERSION 2.6)
Project(IMU)
set(ARDUINO_PROCESSOR atmega328p)
set(ARDUINO_PROCESSOR_FREQ 1600000L)
include(./arduino.cmake)
add_library(ardlib
libraries/EEPROM/EEPROM.cpp
libraries/Wire/utility/twi.c
libraries/Wire/Wire.cpp
libraries/HMC58X3/HMC58X3
)
LINK_DIRECTORIES(${IMU_SRC_DIR}/libarduinocore
${IMU_SRC_DIR}/libraries/EEPROM
${IMU_SRC_DIR}/libraries/Wire
${IMU_SRC_DIR}/libraries/HMC58X3
)
link_libraries(arduinocore ardlib)
include_directories(
libarduinocore
libraries/EEPROM
libraries/Wire
libraries/Wire/utility
libraries/HMC58X3
)
set(C_SRCS
ADXL345.cpp
ApplicationRoutines.cpp
DCM.cpp
HMC5883L.cpp
ITG3200.cpp
matrix.cpp
output.cpp
timing.cpp
vector.cpp
)
set(C_HDRS
ADXL345.h
ApplicationRoutines.h
DCM.h
HMC5883L.h
ITG3200.h
matrix.h
output.h
timing.h
vector.h
declarations.h
)
add_executable(IMU.elf main.cpp ${C_SRCS} ${C_HDRS})
add_subdirectory(libarduinocore)
set(ARDUINO_PROCESSOR atmega328p)
set(ARDUINO_PROCESSOR_FREQ 16000000L)
# This module defines macros intended for use by cross-compiling toolchain files when
# CMake is not able to automatically detect the compiler identification.
include (CMakeForceCompiler)
# Set this for cross compiling. Otherwise it is set to CMAKE_HOST_SYSTEM_NAME,
# which is the system we are developing on.
set (CMAKE_SYSTEM_NAME Generic)
# It sets CMAKE_<lang>_COMPILER to the given compiler and the cmake internal variable
# CMAKE_<lang>_COMPILER_ID to the given compiler-id. It also bypasses the check for
# working compiler and basic compiler information tests.
SET(CMAKE_C_COMPILER avr-gcc)
SET(CMAKE_CXX_COMPILER avr-g++)
cmake_force_cxx_compiler (avr-g++ CrossAVR)
cmake_force_c_compiler (avr-gcc CrossAVR)
# Appparently we want to use the gnuc99 standard.
#set (CSTANDARD "-std=gnu99")
# Generate .stabs debugging symbols for assembler source lines. This enables avr-gdb to
# trace through assembler source files.
#set (CDEBUG "-gstabs")
# Warn for functions declared or defined without specified argument types.
set (CWARN "-Wall -Wstrict-prototypes")
# -funsigned-char - Make any unqualfied char type an unsigned char. Without this option,
# they default to a signed char.
# -funsigned-bitfields - Make any unqualified bitfield type unsigned. By default,
# they are signed.
# -fpack-struct - Pack all structure members together without holes.
# -fshort-enums - Allocate to an enum type only as many bytes as it needs for the declared
# range of possible values. Specifically, the enum type will be equivalent to the
# smallest integer type which has enough room.
set (CTUNING_FLAGS "-ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
# Optimize for size. The special option -Os is meant to turn on all -O2 optimizations
# that are not expected to increase code size.
set (COPT "-Os")
SET(CINCS "-I${ArduinoCode_SOURCE_DIR}/libarduinocore")
# Finally the compilation flags are now configured.
set(CMAKE_CXX_FLAGS "-lc -lm -mmcu=${ARDUINO_PROCESSOR} -DF_CPU=${ARDUINO_PROCESSOR_FREQ} ${CTUNING_FLAGS} ${CWARN} ${CSTANDARD} ${CDEBUG} ${COPT} ${CINCS} -lc")
set(CMAKE_C_FLAGS "-lc -lm ${CMAKE_CXX_FLAGS} ${CTUNING_FLAGS} ${CWARN} ${CSTANDARD} ${CDEBUG} ${CINCS} -lc")
# On gentoo, -rdynamic is passed to the compiler. The avr compiler does not recognize this
# option. Also, we are not building shared libraries.
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ""
libarduinocore
目录中的CMakeList.txt文件。
include(../arduino.cmake)
add_library (arduinocore
HardwareSerial.cpp
pins_arduino.c
Print.cpp
Tone.cpp
WInterrupts.c
wiring_analog.c
wiring.c
wiring_digital.c
wiring_pulse.c
wiring_shift.c
WMath.cpp
WString.cpp
)
TARGET = IMU
PORT = /dev/ttyACM0
BAUD = 57600
PROGRAMMER = arduino
MCU = atmega328p
F_CPU = 8000000L
CXX_SRCS = ADXL345.cpp \
ApplicationRoutines.cpp \
DCM.cpp \
HMC5883L.cpp \
ITG3200.cpp \
matrix.cpp \
output.cpp \
timing.cpp \
vector.cpp
CXX_OBJ = $(CXX_SRCS:.cpp=.o)
CXX_HDRS = ADXL345.h \
ApplicationRoutines.h \
DCM.h \
declarations.h \
HMC5883L.h \
ITG3200.h \
matrix.h \
output.h \
timing.h \
vector.h
CORE_DIR = libarduinocore
CORE_CXX_SRCS = $(CORE_DIR)/HardwareSerial.cpp \
$(CORE_DIR)/Print.cpp \
$(CORE_DIR)/Tone.cpp \
$(CORE_DIR)/WMath.cpp \
$(CORE_DIR)/WString.cpp
CORE_CXX_OBJ = $(CORE_CXX_SRCS:.cpp=.o)
CORE_CC_SRCS = $(CORE_DIR)/pins_arduino.c \
$(CORE_DIR)/WInterrupts.c \
$(CORE_DIR)/wiring_analog.c \
$(CORE_DIR)/wiring.c \
$(CORE_DIR)/wiring_digital.c \
$(CORE_DIR)/wiring_pulse.c \
$(CORE_DIR)/wiring_shift.c
CORE_CC_OBJ = $(CORE_CC_SRCS:.c=.o)
CORE_HDRS = $(CORE_DIR)/binary.h \
$(CORE_DIR)/HardwareSerial.h \
$(CORE_DIR)/pins_arduino.h \
$(CORE_DIR)/Print.h \
$(CORE_DIR)/Stream.h \
$(CORE_DIR)/WCharacter.h \
$(CORE_DIR)/WConstants.h \
$(CORE_DIR)/wiring.h \
$(CORE_DIR)/wiring_private.h \
$(CORE_DIR)/WProgram.h \
$(CORE_DIR)/WString.h
ARD_LIB_DIR = libraries
ARD_LIB_CXX_SRCS = $(ARD_LIB_DIR)/EEPROM/EEPROM.cpp \
$(ARD_LIB_DIR)/Wire/Wire.cpp \
$(ARD_LIB_DIR)/HMC58X3/HMC58X3.cpp
ARD_LIB_CC_SRCS = $(ARD_LIB_DIR)/Wire/utility/twi.c
ARD_LIB_CXX_OBJ = $(ARD_LIB_CXX_SRCS:.cpp=.o)
ARD_LIB_CC_OBJ = $(ARD_LIB_CC_SRCS:.c=.o)
CC = avr-gcc
CXX = avr-g++
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AR = avr-ar
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
ARD_LIB_INC = -I$(ARD_LIB_DIR) -I$(ARD_LIB_DIR)/EEPROM -I$(ARD_LIB_DIR)/Wire -I$(ARD_LIB_DIR)/HMC58X3 -I$(ARD_LIB_DIR)/Wire/utility
FLAGS_WARN = -Wall -Wstrict-prototypes
FLAGS_TUNING = -ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
FLAGS_OPT = -Os
ALL_INC = -I. $(ARD_LIB_INC) -I$(CORE_DIR)
OBJS = $(CXX_OBJ) $(CORE_CXX_OBJ) $(CORE_CC_OBJ) $(ARD_LIB_CC_OBJ) $(ARD_LIB_CXX_OBJ)
ALL_OBJS := $(addprefix build/, $(notdir $(OBJS)))
ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) $(ALL_INC) $(FLAGS_WARN) $(FLAGS_TUNNIG) $(FLAGS_OPT)
ALL_CXXFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) $(ALL_INC) -Wall $(FLAGS_TUNNIG) $(FLAGS_OPT)
#ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
all : $(TARGET).hex
avr-objcopy -O ihex -R .eeprom $(TARGET).out $(TARGET).hex
$(TARGET).out : $(OBJS)
$(CXX) $(ALL_CXXFLAGS) main.cpp $(ALL_OBJS) -o $(TARGET).out -lc -lm
upload : $(TARGET).hex
avrdude -c$(PROGRAMMER) -p$(MCU) -P$(PORT) -U flash:w:$(TARGET).hex
serialmon :
picocom -b$(BAUD) $(PORT)
.SUFFIXES: .hex .cpp .o .c
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $(addprefix build/, $(notdir $@)) -lc -lm
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $(addprefix build/, $(notdir $@)) -lc -lm
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o build/$@ -lc -lm
最佳答案
解释:
正如错误消息所暗示的那样,问题与(代码的)重定位有关,该重定位会导致某些截断的发生。该消息来自链接器,该链接器正在尝试将代码段映射到程序存储器中的适当位置。
当将代码放置或移动到某个位置(“重定位”)并且通过JMP
或CALL
(即函数调用)从另一段代码引用该代码时,必须将重定位的地址添加到JMP
或CALL
指令中引用它。
AVR设备支持两种跳转/调用指令:JMP
与RJMP
以及CALL
与RCALL
。 R
变体相对于当前位置进行调用,并且在程序存储器的使用和执行时间上均更加有效。但是,这需要付出一定的代价:RJMP
和RCALL
仅可用于距离其在程序存储器中位置+/- 4kb范围内的地址。对于程序存储器不超过8kb的设备,这绝不是问题,因为可以通过RCALL
或RJMP
从任何位置寻址整个8kb范围。
但是,在程序存储器超过8kb的设备上,并非在所有可能的位置上都如此。因此,如果链接器决定可以将要调用的代码放在RJMP
/RCALL
的+/- 4kb范围内,则不会有问题,但是如果链接器无法(重新)定位该代码在该范围内,RJMP
/RCALL
不能用于到达代码的新地址,因此地址被截断了(就像在C语言中执行uint16_t value = 12345; uint8_t truncatedValue = value;
时一样),并且生成的代码中断了。
请注意,这可能会或可能不会在任何时候超过程序存储器4kb的任何给定项目(在程序存储器> 8kb的设备上)发生,因为这取决于所需代码的重定位,这可能基本上随着每行的新行而改变。添加或删除C代码,添加要链接的每个库,甚至链接库或其他代码段的顺序(例如,当链接器找到代码时,从“A”到“B”的调用都可以工作)像“ABC”一样,但是当链接器决定像“ACB”那样重新定位时失败。
解决方案:
您必须让编译器知道它需要生成JMP
/CALL
指令,而不是(更有效的)RJMP
/RCALL
指令。在AVR Studio/Atmel Studio中,这可以通过项目的属性,工具链,AVR/GNU C编译器,优化来完成。相关选项是“在> 8k设备(-mshort-calls)上使用rjmp/rcall(有限范围)” ,需要将其设置为,未选中以防止命名错误。
如标签所示,相关的命令行选项是-mshort-calls
,当从IDE外部调用gcc时,需要将其从gcc命令行参数列表中删除以实现相同的功能。
更新:
为避免不必要的困惑,此错误可能会导致Avr-gcc 4.7 中不赞成使用-mshort-calls
,并将其从4.8中删除。资料来源:GCC 4.8 Changes。
用户现在应该改为使用-mrelax
生成二进制文件,这些二进制文件在可能的情况下具有调用优化功能,但绝不会产生错误。
关于linker - AVR链接器错误 "relocation truncated to fit",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8188849/
我正在编译 linux-4.19(gcc-8.2 bintutils-2.31),但是它总是失败并出现如下错误: aarch64-oe-linux-ld.bfd: drivers/platform/g
我在 Macbook Pro 上的 VirtualBox 上运行 Ubuntu 14.04 64 位 MAC。我在 hello_kernel.c 中有以下内容,我想运行它。 #include #in
这是我在 AArch64 上遇到的问题的简化版本: 我有一个宏,可以不断地将一些数据转储到一个部分中。 #define GEN_DATA(_type) \ .pushsection .mydat
我们已经将我们的 subversion 存储库移到了不同的服务器上。我跑了svn swtich --relocate将我的开发工作站存储库更改为新位置。 问题是它看起来像它工作,因为没有报告错误消
这是一个与u-boot相关的基本问题。 为什么 u-boot 代码会自行重定位? 好的,如果 u-boot 是从 NOR-flash 或引导 ROM 空间执行是有道理的,但如果它已经从 SDRAM 运
我们的 svn 存储库的位置已更改为不同的 url,此外主干、分支和标签的相对路径也移动了一点。现在,当我尝试 svn relocate 时,我收到此消息。 无效的重定位目标:'https://my-
当有人这样做时 svn switch ,我知道它将工作目录切换到目标路径。 我想了解 --relocate 的用途。我认为这仅在存储库的 url 发生更改并且想要更新工作副本 url 以指向新的
我正在尝试将工作副本文件夹从旧的专用 svn 服务器移动到新的 svn 服务器,其中包含子文件夹。使用以下重定位命令: svn switch --relocate https://oldserver/
我想用 gfortran 创建一个共享库,出于可移植性的原因将它与静态版本的 libgfortran 链接起来。不幸的是,我没有设法适本地链接不同的对象。我已经找到一些解决类似问题的帖子,但我不知道如
我的应用旨在在 android 6 上运行,据我所知,它不允许加载共享库。 有没有人遇到过这个问题并且能够成功解决? java.lang.UnsatisfiedLinkError: dlopen fa
在我的 Debian x86 32 位中,当我执行 readelf -r/usr/lib/libstdc++.so.6 | grep pthread,我得到这个输出: 000eceac 000062
我想知道为什么某些 Windows 可执行文件确实有重定位。与 DLL 不同,当可执行文件始终可以加载到任何虚拟地址时,为什么需要它? 最佳答案 是的,EXE 中的重定位是可选的,可以去除。但如果我们
我无法在我的 linux 电脑上编译任何东西。我不知道为什么,可能是我安装了一些软件包并弄得一团糟。我已经卸载并重新安装了 gcc 和其他软件包,但没有好消息.. 仍然是这个问题。 这是消息: /us
我正在 Nexus 5 上测试 Android 6.0,我正在使用 Metaio(我知道该服务将于 12 月 15 日结束,但在那一天我们将转移到另一个 AR 平台)。问题是当我启动 ARActivi
我正在尝试将静态库链接到共享库,但出现以下错误 /usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): re
如果你做 dumpbin/header 它会给你所有 7 个部分的数据转储。 。数据 .idata .rdata .reloc .rsrc 。文本 .textbss 其中 .rsrc 和 .idata
这个问题的变体已被问过很多次,但没有一个答案阐明我感兴趣的内容: 我想(显然...:) 将我的本地工作副本与两个不同服务器上的两个存储库同步。如果我将 svn switch 与 --relocate
我正在尝试为ATmega328 micro编译一些代码,并且我想使用Arduino的库和核心。我正在使用CMake。我已经编译了核心库和代码的所有对象以及Arduino的库。但是,当链接时,它们向我显
我是这个社区的新手,因为我以前从未创建过帐户并提出过问题,但我一直使用这个网站来解决我的编程难题。所以谢谢!不过这一次,我找不到另一个符合我确切需求的问题。如果重复,我深表歉意。 我使用的是 elem
鉴于我已经编译了一些 unix 程序,我可能需要做些什么来将它重新定位到不同的目录并让它继续正常运行。 我正在考虑 Perl,但对其他系统(如 Apache)感兴趣,这些系统在完成后似乎也会失败。为了
我是一名优秀的程序员,十分优秀!