Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 main.c 中,我有int cursor = 0;.
int cursor = 0;
这稍后在我使用的函数中使用cursor += 1.
cursor += 1
当我编译/链接时,我得到一个错误:
cursor' referenced in section .text' of main.o: defined in discarded section .bss' of main.o
我对使用 GCC 比较陌生。我以前使用过 MSVC,但我从来没有遇到过这样的错误。有什么我需要添加到链接器脚本中以便它不会丢弃 BSS 部分吗?
谢谢
我不确定它是否会有所帮助。你可以试试:
static int cursor = 0;
您可以尝试的另一件事是:
int cursor;
作为全局然后在 main() 中放置 cursor=0; 也许它不喜欢初始化全局?
BSS 用于未初始化的全局变量。因此,出于某种原因,我认为它没有初始化您的游标变量。因此,将初始化移入 main() 例程可能会修复它。