Strange linker errors

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
AUsername
Member
Member
Posts: 54
Joined: Sun Feb 01, 2009 9:07 pm

Strange linker errors

Post by AUsername »

So recently I had to switch computers and setup my GCC again so I could compile the terminal for my OS. Well compiling used to work but now it's a mess.

I get the following errors:
C:\Users\Owner\DOCUME~1\MYDROP~1\Firefly\programs\HELLOW~1>compile
Compiling...
Linking...
..\entry.o(.text+0x1): undefined reference to `main'
compile\main.o(.text+0x21):main.c: undefined reference to `__alloca'
compile\main.o(.text+0x26):main.c: undefined reference to `___main'
Copying...
The system cannot find the file specified.

C:\Users\Owner\DOCUME~1\MYDROP~1\Firefly\programs\HELLOW~1>
What's strange is if I change "main" to "_main" this turns into:
C:\Users\Owner\DOCUME~1\MYDROP~1\Firefly\programs\HELLOW~1>compile
Compiling...
Linking...
..\entry.o(.text+0x1): undefined reference to `main'
Copying...
The system cannot find the file specified.

C:\Users\Owner\DOCUME~1\MYDROP~1\Firefly\programs\HELLOW~1>
So somehow __alloca and ___main (triple underscore?) both disappear. But a reference to main is still missing?
Plus in the original it should be able to call main.

compile.bat:
@echo off
@echo Compiling...
gcc -o compile\main.o -c main.c -I..\include\ -Wextra -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -fno-leading-underscores
@echo Linking...
ld-elf -L..\libraries\ -T compile\linker.ld -o hello.prg ..\entry.o compile\main.o -lstdio -lstdlib -l_sysapi -lstring

@echo Copying...
copy hello.prg A:\programs\hello.prg
entry.s:

Code: Select all

global entrypoint
extern main

section .text
align 4

entrypoint:
	jmp		main

section .bss
align 4
I honestly have no idea what's wrong.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Strange linker errors

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
AUsername
Member
Member
Posts: 54
Joined: Sun Feb 01, 2009 9:07 pm

Re: Strange linker errors

Post by AUsername »

Combuster wrote:GCC Cross-Compiler
Somehow, I knew I was going to get this reply.
Now, perhaps some people may not have attempted to set up GCC properly, however I have on at least 4 different machines, running 4 different OSs. Both Windows and Linux.

The problem was in not how I set GCC up because I'm using ld-elf, which would have fixed that. The problem was with the copy of GCC I had.

For some reason it ignored -fno-leading-underscores, so it compiled the objects with leading underscores, resulting in those errors.

I switched what flavor of GCC I was using and now it works.

But please stop posting "Setting up GCC" as your first response, it gets really annoying to see that as the first thing that comes out of your mouth, assuming that people haven't tried, or that is the problem.

By the way, it works now so don't worry about it.
Grunt
Member
Member
Posts: 37
Joined: Fri Nov 06, 2009 1:05 am

Re: Strange linker errors

Post by Grunt »

Actually, his advice was correct.

I know I had similar problems when trying MinGW and Cygwin. A cross-compiler helps not only for this kind of problems, but it is also a starting point to porting a C library, and eventually build a whole toolchain.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Strange linker errors

Post by Combuster »

You are contradicting yourself by saying that you don't know the solution, and yet you claim you knew in advance that you'll get the crosscompiler link as reply (and thus either did not read or bother to try, i.e. broke forum rules, or already knew the answer) :roll:

I could have told you to STFWiki instead, would that help you?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Wolf9466
Posts: 12
Joined: Sun Jun 28, 2009 11:17 pm

Re: Strange linker errors

Post by Wolf9466 »

Combuster wrote:You are contradicting yourself by saying that you don't know the solution, and yet you claim you knew in advance that you'll get the crosscompiler link as reply (and thus either did not read or bother to try, i.e. broke forum rules, or already knew the answer) :roll:

I could have told you to STFWiki instead, would that help you?
Hello? He obviously didn't know the solution, and you seemingly ALWAYS post a link to the wiki, like people haven't already read it. Which means that he didn't know the answer, but anticipated you being a prick.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Strange linker errors

Post by quok »

AUsername wrote:By the way, it works now so don't worry about it.
Great, glad to know that you got your problem fixed. Perhaps you could tell us more about what you ended up doing to fix the problem though, so it could be added to the wiki?
Thanks in advance!
AUsername
Member
Member
Posts: 54
Joined: Sun Feb 01, 2009 9:07 pm

Re: Strange linker errors

Post by AUsername »

quok wrote:
AUsername wrote:By the way, it works now so don't worry about it.
Great, glad to know that you got your problem fixed. Perhaps you could tell us more about what you ended up doing to fix the problem though, so it could be added to the wiki?
Thanks in advance!
The version of GCC I was using didn't support "-fno-leading-underscores" for some reason and didn't report that it didn't.
I switched what version I was using and it worked!
(not sure what the previous version was)
Post Reply