0%

includeOS 初体验 - Hello World!

今天第一次体验 includeOS,决定写个 Hello World 耍一耍( •̀ ω •́ )✧

基本是按照 Getting started 来做。

自定义安装位置

编辑 ~/.bashrc 文件,使用命令 subl ~/.bashrc,在文件尾添加下面代码

1
2
export INCLUDEOS_PREFIX=~/includeos
export PATH=$PATH:$INCLUDEOS_PREFIX/bin

上述命令使 boost 程序全局可见,运行 boot <myservice> 命令就可以在任何服务文件夹中运行你自己写的服务。

20190406 更新
有个地方忘记写了,少了这一步可能会导致安装出问题。
自己也是装了两遍才成功。下面分析是我 瞎分析的 233,不知道究竟是不是这样。
因为在安装过程中有请求 root 权限,导致用户改变了,所以 root 的环境变量也得变,下面是我添加的

1
2
export INCLUDEOS_PREFIX=/home/tian/includeos
export PATH=$PATH:$INCLUDEOS_PREFIX/bin

安装 includeOS

直接运行下面命令即可

1
2
3
$ git clone https://github.com/hioa-cs/IncludeOS
$ cd IncludeOS
$ ./install.sh

install.sh 脚本帮你做了如下工作:

  1. 安装了一些必要的依赖: curl make clang-5.0 nasm bridge-utils qemu
  2. 用 CMake 编译 IncludeOS (将所有东西安装在 $INCLUDEOS_PREFIX/includeos ,如果在开始没有做自定义安装位置那一步则默认安装在 /usr/local 目录下)

测试是否安装成功

$ ./test.sh
这样貌似就成功了叭_(:△」∠)_
test.sh
includeOS-links

Hello World

终于到了这一步!(´ー∀ー`)
将 seed/service 目录复制一份,然后在 Service 类中实现 Service::start 函数即可(我发现里面已经有了 Hello world 2333
然后更新 CMakeLists.txt 来指定项目的名称

1
2
3
4
5
6
7
$ cp -r seed/service ~/includeos_hellowrold
$ cd ~/includeos_hellowrold
$ subl service.cpp
$ mkdir build && cd build
$ cmake ..
$ make
$ boot HelloWrold

正如上面所说,该 service.cpp 文件中其实已经输出了想要的 Hello world,所以我就加了一些额外的话。

1
2
3
4
5
6
7
8
9
void Service::start(const std::string& args)
{
#ifdef __GNUG__
printf("Built by g++ " __VERSION__ "\n");
#endif
printf("Hello world! --LewisTian\n");
printf("Congratulations! Your first IncludeOS program runs successfully!\n");
}

然后改了 CMakeLists.txt 中的服务名与生成文件名

1
2
3
4
5
# Human-readable name of your service
set(SERVICE_NAME "IncludeOS HelloWrold")

# Name of your service binary
set(BINARY "HelloWrold")

一颗赛艇!最后使用命令 boot HelloWrold 运行你写的 IncludeOS HelloWrold
运行结果:
includeOS-HelloWorld

Welcome to my other publishing channels