0

I'm planing to make my own unix like operating system and I just had a look at this tutorial over on github to get started.

Would it be possible to make some custom target in cmake that makes the same thing as this Makefile?
So build an executable ISO file using x86_64-elf-gcc in combination with grub-mkrescue and nasm.

and maybe as a bonus also work for auto-completion in clion?

My first goal would be to just compile all my source code to object files. Here are the source files if you want to test it out:

header.asm:

section .multiboot_header
header_start:
    ; magic number
    dd 0xe85250d6 ; multiboot2
    ; architecture
    dd 0 ; protected mode i386
    ; header length
    dd header_end - header_start
    ; checksum
    dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))

    ; end tag
    dw 0
    dw 0
    dd 8
header_end:

main.asm:

global start

section .text
bits 32
start:
    ; print `OK`
    mov dword [0xb8000], 0x2f4b2f4f
    hlt

And this is the CMakeLists.txt:

set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

cmake_minimum_required(VERSION 3.20)
project(NonameOs)

set(CMAKE_CXX_STANDARD 20)

enable_language(ASM_NASM)
set(CMAKE_ASM_FLAGS -f elf64)
set(CMAKE_LINKER /usr/bin/x86_64-elf-ld)
set(CMAKE_ASM_FLAGS -ffreestanding)

add_executable(NonameOs header.asm main.asm)

And the linker file that I haven't figured out how to use in cmake:

ENTRY(start)

SECTIONS
{
    . = 1M;

    .boot :
    {
        KEEP(*(.multiboot_header))
    }

    .text :
    {
        *(.text)
    }
}

Unfortunately I run into this error:

CMakeFiles/NonameOs.dir/header.asm.o: fatal: more than one input file specified: CMakeFiles/NonameOs.dir/main.asm.o

I'm assuming that this is due to the fact that I didnt tell cmake to use the x86_64-elf-ld linker. How could I fix this?

Gian Laager
  • 360
  • 1
  • 9
  • For set a linker, set [this question](https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker). For set a ld-script, see [that question](https://stackoverflow.com/questions/42978674/how-to-use-specific-link-script-lds-with-cmake). You could always check the generated compiler and linker command lines via `make V=1`. – Tsyvarev Nov 01 '21 at 17:13

0 Answers0