Hackmd 好讀版:https://hackmd.io/@YUIN/HyR6haYkGx
This guide shows how to build and run NachOS 4.0 on Ubuntu.

Tested on Ubuntu 24.04.
sudo apt update
sudo apt install g++ csh make wget vim g++-multilib gcc-multilib libc6-dev-i386 -ymkdir -p ~/oslab
cd ~/oslab
wget -O nachos-4.0.tar.gz \
https://raw.githubusercontent.com/Yuin0329/NachOS-Setup/8deec2b725c1bcf115cc81fc5694bf478afdb154/nachos-4.0.tar.gz
wget -O mips-x86.linux-xgcc.tar.gz \
https://raw.githubusercontent.com/Yuin0329/NachOS-Setup/8deec2b725c1bcf115cc81fc5694bf478afdb154/mips-x86.linux-xgcc.tar.gzfile nachos-4.0.tar.gz
file mips-x86.linux-xgcc.tar.gzThey should show gzip compressed data.
tar -xzvf nachos-4.0.tar.gz
sudo tar -xzvf mips-x86.linux-xgcc.tar.gz -C /Check the cross compiler:
ls /mips-x86.linux-xgcccd ~/oslab/nachos-4.0/code/test
vim MakefileSet:
GCCDIR = /mips-x86.linux-xgcc/
CPP = /mips-x86.linux-xgcc/cpp0
CFLAGS = -G 0 -c $(INCDIR) -B/mips-x86.linux-xgcc/cd ~/oslab/nachos-4.0/code
vim Makefile.commonSet:
CFLAGS = -m32 -g -Wall $(INCPATH) $(DEFINES) $(HOST) -DCHANGED
LDFLAGS = -m32
CPP=/lib/cpp
CC = g++ -m32 -Wno-deprecated
LD = g++ -m32 -Wno-deprecated
AS = as --32cd ~/oslab/nachos-4.0/code/bin
vim MakefileSet:
CC=gcc -m32
CFLAGS=-m32 -I../lib -I../threads $(HOST)
LD=gcc -m32If you already built NachOS with wrong settings, or make clean does not fully clean old files, remove old build files manually:
cd ~/oslab/nachos-4.0/code
find . -name "*.o" -delete
find . -name "nachos" -delete
find . -name "coff2noff" -delete
find . -name "swtch.s" -delete
find . -name "makedep" -delete
find . -name "eddep" -delete
cd test
rm -f *.o *.coff *.noff halt test1 test2 add createFile fileIO*cd ~/oslab/nachos-4.0/code
makecd ~/oslab/nachos-4.0/code/userprog
./nachos -e ../test/test1You should see something similar to:
Total threads number is 1
Thread ../test/test1 is executing.
Print integer:9
Print integer:8
Print integer:7
Print integer:6
return value:0
Machine halting!
- If you already built with wrong settings, clean old build files before rebuilding.
- If
test1runs successfully, the setup is complete.