How to link without errors? [SOLVED, lmao so easy]

Programming, for all ages and all languages.
Post Reply
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

How to link without errors? [SOLVED, lmao so easy]

Post by NunoLava1998 »

Original question i asked on SO: http://stackoverflow.com/questions/3991 ... -linker-ld
I am currently following the Bare Bones tutorial from OSDev and i have set up everything and compiled the kernel and bootloader into object files, and i have the .ld file. However, when i try to link the files and produce it into a bin using:

Code: Select all

i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
, i get this error:

"

Code: Select all

.../i686/bin/../lib/gcc/i686-elf/4.8.2/../../../../i686-elf/bin/ld.exe: cannot open linker script file linker.ld

collect2.exe: error: ld returned 1 exit status
"

I know what "ld returned 1 exit status" means (ld has gotten a error, not a error itself, just indicating errors.). The other solutions i have tried either give more errors or do absolutely nothing. Adding -T does nothing. I'm using Windows 10 and have the .exe's and etc. from a source which i don't have the link to, and i'm using GCC. I also put 4 dll's for gcc to work without errors. I have already compiled the assembly and C into object files, but nothing. I removed every part that has to do with GRUB/Multiboot except protected mode (possibly) and 32 bit code, and there are no errors in the code. I've never seen a solution that involves "cannot open linker script file linker.ld", and linking by default either literally ignores every piece of assembly code beacuse it's not "machine code" (it is, normally ignores /001 or /000 or /003 or &) or gives the same error (possibly with a few more errors).
Last edited by NunoLava1998 on Mon Oct 10, 2016 2:51 am, edited 1 time in total.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to link without errors?

Post by iansjack »

The error message seems quite clear. Either linker.ld does not exist in the current working directory or its permissions forbid you access.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How to link without errors?

Post by NunoLava1998 »

iansjack wrote:The error message seems quite clear. Either linker.ld does not exist in the current working directory or its permissions forbid you access.
So where can i get linker.ld then?
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to link without errors?

Post by iansjack »

NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How to link without errors?

Post by NunoLava1998 »

iansjack wrote:http://wiki.osdev.org/Bare_Bones#Linking_the_Kernel
Oh, just realized i didn't name my linker "linker.ld". #-o :lol:
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How to link without errors?

Post by NunoLava1998 »

And now it's giving a syntax error on linker.ld saying the code between the triple parenthesis is incorrect (the real code doesn't include the paranthesis and i don't want the OS to be started with GRUB) in this code is incorrect:

Code: Select all

ENTRY(_start)

SECTIONS
{

	. = 1M;



	.rodata BLOCK(4K) : ALIGN(4K)
	{
		*(.rodata)
	}


	.data BLOCK(4K) : ALIGN(4K)
	{
		*(.data)
	}


	.bss BLOCK(4K) : ALIGN(4K)
	{
		*(COMMON)
		*(.bss)
	}


((( } )))
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How to link without errors?

Post by NunoLava1998 »

nvm, got it working. it was the return 0; i had put, lol now it's linked and i can make a quick bat file to make the linked .bin finally
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to link without errors?

Post by iansjack »

How are you going to boot the kernel if you don't use GRUB?
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How to link without errors?

Post by NunoLava1998 »

@iansjack a 512 byte bootloader which should load sector 2, which contains the ASM file to load the C file and it's headers and link.ld. i have dd to place the code into sector 2 (it can extend beyond sector 2, it just starts at sector 2).
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: How to link without errors?

Post by Schol-R-LEA »

NunoLava1998 wrote:@iansjack a 512 byte bootloader which should load sector 2, which contains the ASM file to load the C file and it's headers and link.ld. i have dd to place the code into sector 2 (it can extend beyond sector 2, it just starts at sector 2).
Is there a compelling reason why you want to write your own boot loader?

(NB: just saying "I want to learn how to write one" is enough to count, though I would caution against then using that boot loader as your OS loader unless you are willing to spend more time on the boot loader than on the rest of the OS and dealing with an excessive amount of frustration along the way.)

The boot loader is a very small part of the system, takes a disproportionate amount of development time for its significance, and is very difficult to get right to a production scale (even for a hobbyist level of 'production'), which is why we usually recommend going with an existing boot loader for your actual OS.

There are reasons to write your own boot loader, but the are usually not very good ones. While I am intending to write one myself, it is because my own system is meant to use a very anomalous document system that doesn't play well with conventional file structures, and because I think I might be able to improve on GRUB (unlikely, but why not try?). In the end, though, I realize I am driven by egotism rather than rational goals, and have accepted that.

The point is that you need to think of both your motivations and your goals before committing to a substantial project that is, in the final analysis, likely to be a detour rather than a direct route. Will writing your own boot loader teach you anything significant? Possibly; it can serve as a decent warm-up for more complex problems. Does it further your goal of writing an operating system? Probably not, unless you are doing something very exotic with the file system or the boot sequence. I suggest you give that some thought before going further.

And set up a repo on somewhere like GitHub or Cloudforge. Seriously, you will come to regret it if you don't, and it would make showing us your code problems a loooot easier.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply