Reputation: 659
In my main.c, I have int cursor = 0;
.
This is later used in a function, where I use cursor += 1
.
When I compile / link, I get an error:
cursor' referenced in section .text' of main.o: defined in discarded section .bss' of main.o
I'm relatively new to using GCC. I used to use MSVC previously, but I never got an error like this. Is there something I need to add into the linker script so it does not discard the BSS section?
Thanks
Upvotes: 0
Views: 1206
Reputation: 144
I'm not sure if it will help. You could try:
static int cursor = 0;
another thing you could try is, put:
int cursor;
as the global and then in main() put cursor=0; maybe it doesn't like initializing the global?
BSS is for uninitialized globals. So for some reason I think it's not initializing your cursor variable. So moving the initialization into the main() routine might fix it.
Upvotes: 1