秋·风

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

lazarus 5.99 project交叉编译为gtk3时链接出错(mips64el-Loongnix系统)

今天测试gtk3时发现链接出错:

C:\1\cross\bin-x86_64-win64\mips64el-linux\mips64el-linux-gnu-ld.exe: C:\1\lazarus\lcl\units\mips64el-linux\gtk3\lazatk1.o: in function `LAZATK1$_$TATKOBJECT_$__$$_SET_ACCESSIBLE_ID$PGCHAR':
lazatk1.pas:(.text.n_lazatk1$_$tatkobject_$__$$_set_accessible_id$pgchar+0x2c): undefined reference to `atk_object_set_accessible_id'
C:\1\cross\bin-x86_64-win64\mips64el-linux\mips64el-linux-gnu-ld.exe: C:\1\lazarus\lcl\units\mips64el-linux\gtk3\lazatk1.o: in function `LAZATK1$_$TATKTEXT_$__$$_SCROLL_SUBSTRING_TO$LONGINT$LONGINT$TATKSCROLLTYPE$$BOOLEAN32':
lazatk1.pas:(.text.n_lazatk1$_$tatktext_$__$$_scroll_substring_to$longint$longint$tatkscrolltype$$boolean32+0x3c): undefined reference to `atk_text_scroll_substring_to'
C:\1\cross\bin-x86_64-win64\mips64el-linux\mips64el-linux-gnu-ld.exe: C:\1\lazarus\lcl\units\mips64el-linux\gtk3\lazatk1.o: in function `LAZATK1$_$TATKTEXT_$__$$_SCROLL_SUBSTRING_TO_POINT$hxdHcfbopeQB':
lazatk1.pas:(.text.n_lazatk1$_$tatktext_$__$$_scroll_substring_to_point$hxdhcfbopeqb+0x4c): undefined reference to `atk_text_scroll_substring_to_point'
C:\1\cross\bin-x86_64-win64\mips64el-linux\mips64el-linux-gnu-ld.exe: C:\1\lazarus\lcl\units\mips64el-linux\gtk3\lazatk1.o: in function `LAZATK1$_$TATKPLUG_$__$$_SET_CHILD$PATKOBJECT':
lazatk1.pas:(.text.n_lazatk1$_$tatkplug_$__$$_set_child$patkobject+0x2c): undefined reference to `atk_plug_set_child'
Error: (9013) Error while linking
Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\1\fpc\bin\x86_64-win64\ppcrossmips64el.exe returned an error exitcode

链接失败到底是什么

不是缺库、也不是 sysroot 路径问题——是 54 个符号在 sysroot 里根本不存在:

atk_plug_set_child, atk_text_scroll_substring_to{,_point},
atk_object_{get,set}_accessible_id, gdk_pixbuf_init_modules,
g_array_copy, g_task_set_name, g_timer_is_active,
g_source_set_dispose_function, g_memory_monitor_dup_default,
gtk_cell_accessible_parent_get_column_header_cells ...

用 nm -D --defined-only 逐个核对过 C:\1\cross\lib\mips64el-linux 里的 libatk-1.0.so.0 / libglib-2.0.so.0 / libgdk_pixbuf-2.0.so.0 / libgtk-3.so.0 / libgio-2.0.so.0:一个都没有定义。这个 sysroot 是 buster 那一代(gtk3 3.24.4 / glib 2.58 / atk 2.30 / gdk-pixbuf 2.38),和真机完全一致,所以问题不在目标机。

根本原因是 LCL 的 gtk3 绑定(lcl/interfaces/gtk3/gtk3bindings/)头文件比Loongnix带的gtk3新,声明了一批这套库里没有的 API。它们只被"没人调用"的包装方法引用(每个方法一个 .text.n_ 段),所以让链接器把这堆未引用段丢掉即可,这是mips64el的gtk3版本老旧引起的链接问题。

处理方法:

project1.lpi → Compiler Options → Custom options添加:

-k--gc-sections

QQ_1792381139419

修改后重新编译project就可以。

posted on 2026-10-19 11:39  秋·风  阅读(32)  评论(4)    收藏  举报