The solution to “undefined reference”and “relocation truncated” (mostly concern cell-id stuffs)

本文解决了在Symbian平台开发过程中遇到的undefined reference与relocation truncated错误。通过更换不同版本的库文件(如gsmbas.lib),成功解决了RBasicGsmPhone相关的问题。此外,还探讨了库文件版本不匹配可能导致的问题。

The solution to “undefined reference”and “relocation truncated” (mostly concern cell-id stuffs)

While covering a program concerning RBasicGsmPhone or so stuffs,i got into the problem that my program can compile in the emulator but cannot work in the ARMI release mode (or maybe THUMB which I have not tried). The Problem is mainly

undefined reference to `RBasicGsmPhone::RBasicGsmPhone(void)' relocation truncated to fit: ARM_26...
RBasicGsmPhone::RBasicGsmPhone(void) ...

Having checked up the program i could get it through on the emulator but not ARMI.I searched through the nokia forum and got nothing.Lots of people ever got the same problem as " undefined reference " and "relocation truncated",especially about the "cell-id" stuff,but without any solution. I saw one thread that is similar to my problem:
GeoLog.in(GeoLogContainer.o)(.text+0x494):GeoLogContaine: relocationtruncated to fit: ARM_26 RFs::Connect(int)
GeoLog.in(GeoLogContainer.o)(.text+0x4b4):GeoLogContaine: undefined reference to `RFile::Open(RFs &, TDesC16 const &, unsigned
http://discussion.forum.nokia.com/fo...runcated+write
here the problem is that it used RFile and RFs,and using the two you have to include : Location: f32file.h (include it in your .cpp file) Link against: efsrv.lib (include in your .mmp file)

Back to my problem,i have

include <etelbgsm.h>
include <etel.h>
and in my mmp
LIBRARY etel.lib // Telephony server LIBRARY
gsmbas.lib // Get cell id
Just as above,i also include a gsmbas.lib in the :Symbian/7.0s/Series60_v21_C/Epoc32/release/armi/urel,which i got from (SYSINFO60/data). i have got all needed then it may because of the wrong version of some *.h or *.lib.
Why not have a try? I download the Series60_v20 one and copy the wanted lib to my Series60_v21_C/.../urel and compile again .
Compile and BANG! IT WORKS.
So,i think that almost all similar problems are caused by short of *.lib(s) or *.h(s) for the needed ,or by short of PROPER ones. Or caused by broken ones.
Due to my little experience ,I do not know it to the deep , I hope someone can explain it more clearly or at least point out my misunderstand. easy way to solve the problem, you can just replace it with a proper one.
Then that is all. also i got a question for your experts: is there anything with the order in which the libraries were set in the mmp file? What does this thread mean? http://discussion.forum.nokia.com/fo...794#post290794

download the gsmbas.lib for armi urel here
http://dl2.youkuaiyun.com/down4/20070714/14095347908.rar
answer from nokia forum champion symbianyucca:
“undefined reference” mena that the implementation is not found, which means that the header for the class was located but the library was not.

So to get rid of this you just need to addd the library to the project and re-build the workspace (i.er. re-import with codewarrion for example), and then the bceed.

Anyway, if the library is not present in the SDK, then of course you can not use the API. You should never copy librarties from older SDK's to never ones, since they might not be compatible, instead you should check if you could use some other API that is present to get the task done.

If not, then you could check if ytou could use the channels available to obtain the required libraries from Nokia.
<think>我们正在处理一个关于VCS(可能是Synopsys VCS)和ld(GNU链接器)在链接过程中出现的错误:“failed to convert GOTPCREL relocation; relink with --no-relax”。这个错误通常发生在使用64位架构时,链接器在处理某些类型的重定位时出现问题。错误信息建议使用`--no-relax`选项重新链接。 根据错误信息,解决方案是尝试在链接步骤中添加`--no-relax`选项。但是,我们需要考虑如何在VCS编译流程中添加这个选项。 在VCS中,链接步骤通常由VCS的编译脚本自动管理。VCS在编译和链接设计时,会调用GCC(或者Clang等)以及ld。因此,我们需要将链接器选项传递给VCS。 通常,VCS允许用户通过特定的命令行选项来传递额外的链接器选项。具体来说,我们可以使用`-LDFLAGS`选项(或者在某些版本中是`-ldflags`)来传递链接器标志。例如: ``` vcs ... -LDFLAGS "--no-relax" ``` 但是,需要注意的是,VCS的版本和配置可能会影响具体的选项。另外,有些版本的VCS可能使用`-Wl,`来传递选项给链接器,类似于GCC的做法。因此,另一种形式可能是: ``` vcs ... -LDFLAGS "-Wl,--no-relax" ``` 但是,根据错误信息,直接使用`--no-relax`是ld的选项,所以第一种形式可能更直接。 另外,我们也可以考虑在VCS的配置文件中设置,或者通过环境变量来设置。但通常命令行传递是最直接的方式。 由于这个错误通常与位置无关代码(PIC)和重定位有关,在64位代码中,GOTPCREL重定位是常见的。链接器的`--no-relax`选项会禁止重定位的松弛优化,这可能会解决某些重定位问题。 如果上述方法不能解决问题,可能还需要检查其他方面,如编译器版本、链接器版本、库的兼容性等。 下面,我们按照要求生成相关问题: </think>针对 VCS 链接过程中出现的 `failed to convert GOTPCREL relocation; relink with --no-relax` 错误,以下是系统级的解决方案和原因分析: ### 错误成因 该错误发生在 64 位架构链接过程中,当链接器(ld)尝试优化 `R_X86_64_GOTPCREL` 类型的重定位时失败。主要原因是: 1. **重定位冲突**:目标文件的代码模型与某些外部库(如静态库)的编译方式不兼容 2. **链接器优化限制**:ld 的 `RELax` 优化在混合位置相关/无关代码时失效 3. **工具链版本问题**:常见于 GCC/binutils 旧版本(如 GCC <8 或 binutils <2.30)[^1] ### 解决方案 #### 方法 1:添加链接器选项(推荐) 在 VCS 编译命令中显式添加 `-Wl,--no-relax` 参数: ```bash vcs [其他选项] -LDFLAGS "-Wl,--no-relax" [设计文件] ``` - `-Wl,` 将参数传递给链接器 - `--no-relax` 禁用重定位优化,规避错误 #### 方法 2:全局链接器配置 在系统链接器配置中永久禁用 relax(需 root 权限): ```bash echo "INPUT ( /usr/lib/x86_64-linux-gnu/ld-no-relax.so )" > /etc/ld.so.conf.d/no-relax.conf ldconfig ``` #### 方法 3:源代码级修正 若控制源代码编译,添加位置无关代码标志: ```makefile CFLAGS += -fPIC # C 代码 CXXFLAGS += -fPIC # C++ 代码 ``` #### 方法 4:工具链升级 升级 binutils 和 GCC 至较新版本(推荐 GCC≥10): ```bash sudo apt-get install binutils=2.38* gcc-12 # Ubuntu 示例 ``` ### 验证步骤 1. 执行带 `--no-relax` 的编译命令 2. 检查生成的二进制文件: ```bash readelf -r [生成的可执行文件] | grep GOTPCREL ``` 应显示无重定位错误 ### 典型应用场景 此错误常见于: 1. 混合编译 C/C++ 与汇编代码时 2. 链接第三方静态库(尤其未使用 `-fPIC` 编译的库) 3. RISC-V 或 x86_64 架构的 VCS 仿真环境[^2]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值