Linking error - undefined references
Re: Linking error - undefined references
Did you mean me?
- abcdef4bfd
- Member

- Posts: 492
- Joined: Fri Apr 03, 2015 9:41 am
Re: Linking error - undefined references
If Combuster meaned me, i'm using the cross-compiler.
- BASICFreak
- Member

- Posts: 284
- Joined: Fri Jan 16, 2009 8:34 pm
- Location: Louisiana, USA
Re: Linking error - undefined references
And that's where the problem is.catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
Bran's Tutorial is written for DJGPP and NASM on windows.
DJGPP adds a leading underscore to all external ASM names.
GCC (or a cross compiler) does not.
EXAMPLE (Directly from Bran's Kernel)
under the original is:
Code: Select all
; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global _gdt_flush ; Allows the C code to link to this
extern _gp ; Says that '_gp' is in another file
_gdt_flush:
lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
* reload the new segment registers */
extern void gdt_flush();Code: Select all
; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global gdt_flush ; Allows the C code to link to this
extern gp ; Says that '_gp' is in another file
gdt_flush:
lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
* reload the new segment registers */
extern void gdt_flush();So effectively ALL the ASM in Bran's Tutorial is DEAD - unless you really want DJGPP, which is not worth it I have tried.
I am curious why this is not mentioned under Bran's Known Bugs... http://wiki.osdev.org/Bran's_Known_Bugs
EDIT: No longer curious as I have added the section "Does not use Cross-Compiler".
Woot, first WiKi Edit
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
BOS Expanded Commentary
Both under active development!
Sortie wrote:
- Don't play the role of an operating systems developer, be one.
- Be truly afraid of undefined [behavior].
- Your operating system should be itself, not fight what it is.
- abcdef4bfd
- Member

- Posts: 492
- Joined: Fri Apr 03, 2015 9:41 am
Re: Linking error - undefined references
Thanks, now code is linking fine. *goed creating vm86*BASICFreak wrote:And that's where the problem is.catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
Bran's Tutorial is written for DJGPP and NASM on windows.
DJGPP adds a leading underscore to all external ASM names.
GCC (or a cross compiler) does not.
EXAMPLE (Directly from Bran's Kernel)
under the original is:and with a cross compiler it should be:Code: Select all
; This will set up our new segment registers. We need to do ; something special in order to set CS. We do what is called a ; far jump. A jump that includes a segment as well as an offset. ; This is declared in C as 'extern void gdt_flush();' global _gdt_flush ; Allows the C code to link to this extern _gp ; Says that '_gp' is in another file _gdt_flush: lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump! flush2: ret ; Returns back to the C code! ...---... /* This will be a function in start.asm. We use this to properly * reload the new segment registers */ extern void gdt_flush();Notice the lack of the leading underscore in the ASM (this does not affect the C code)Code: Select all
; This will set up our new segment registers. We need to do ; something special in order to set CS. We do what is called a ; far jump. A jump that includes a segment as well as an offset. ; This is declared in C as 'extern void gdt_flush();' global gdt_flush ; Allows the C code to link to this extern gp ; Says that '_gp' is in another file gdt_flush: lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump! flush2: ret ; Returns back to the C code! ...---... /* This will be a function in start.asm. We use this to properly * reload the new segment registers */ extern void gdt_flush();
So effectively ALL the ASM in Bran's Tutorial is DEAD - unless you really want DJGPP, which is not worth it I have tried.
I am curious why this is not mentioned under Bran's Known Bugs... http://wiki.osdev.org/Bran's_Known_Bugs
EDIT: No longer curious as I have added the section "Does not use Cross-Compiler".
Woot, first WiKi Edit