xv6_lecture2 C in xv6

经典的一道指针和数组题: 假设 x 的地址为 0x7fffdfbf7f00, 打印出来的值分别是多少? #include <stdio.h> int main() { int x[5]; printf("%p\n", x); printf("%p\n", x+1); printf("%p\n", &x) printf("%p\n", &x+1); return 0; } 0x7fffdfbf7f00 # 打印的数组的地址 0x7fffdfbf7f04 # 打印的是数组第二个元素的地址 0x7fffdfbf7f00 # &x也是数组的地址 0x7fffdfbf7f14 # x + sizeof(x)的地址

2024-12-26 · 1 min

Professional CMake: A Practical Guide Part III The Bigger Picture

Chapter 23. Finding Things 中等规模以上的项目除了本身的项目之外, 可能还依赖于其他东西. 比如 a particular library or tool, location of a specific configuration file or a header for a library. 甚至项目可能需要找一个 package, 其中定义了一系列内容, 包括 targets, functions, variables… find_...命令提供了搜索 file、library 或 progaram,甚至 package 的能力. 23.1 Finding Files and Paths find_file(outVar name | NAMES name1 [name2...] [HINTS path1 [path2...] [ENV var]...] [PATHS path1 [path2...] [ENV var]...] [PATH_SUFFIXES suffix1 [suffix2 ...]] [NO_DEFAULT_PATH] [NO_PACKAGE_ROOT_PATH] [NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH] [NO_SYSTEM_ENVIRONMENT_PATH] [NO_CMAKE_SYSTEM_PATH] [CMAKE_FIND_ROOT_PATH_BOTH | ONLY_CMAKE_FIND_ROOT_PATH | NO_CMAKE_FIND_ROOT_PATH] [DOC "description"] ) 搜索顺序按如下表格:...

2024-11-30 · 5 min

Professional CMake: A Practical Guide Part II Builds In Depth

Chapter 13. Build Type 13.1 Build Type Basics cmake 有以下几种 build type, 不同的 tpye 会导致 compiler 和 linker flags 不同: Debug: no optimization and full debug information. Release: typically full optimization and no debug information. RelWithDebInfo: 有优化 + debug info. MinRizeRel: 优化 size. 13.1.1 Single Configuration Generators 像 make, ninja, 每个 build directory 只支持一种 build type, 需要在编译时指定 cache variable CMAKE_BUILD_TYPE: cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug ../source cmake --build . 一种可能的文件布局方式: 13.1.2 Multiple Configuration Generators 类似 Xcode and Visual Studio, 不关注, 跳过....

2024-11-29 · 13 min

Professional CMake: A Practical Guide Part I Fundamentals

Reference Professional CMake A Practical Guide version 1.0.0 2018 年出版, 基于 cmake 3.12 版本(2018-7-17). 目前该书出到了 19th Edition, 支持到 cmake 3.30, 不断更新中. Chapter 1. Introduction From Wikipedia: CMake is a free, cross-platform, software development tool for building applications via compiler-independent instructions. It also can automate testing, packaging and installation. It runs on a variety of platforms and supports many programming languages. Build 部分由其他不同的 build tool 负责, 比如 make, ninja, Visual Studio, XCode…...

2024-11-20 · 14 min

Modern Cmake

Getting Started Installing CMake Running CMake Building a project ~/package $ mkdir build ~/package $ cd build ~/package/build $ cmake .. ~/package/build $ make make 可以替换成 cmake --build . 新版本的 cmake 可以使用-S, -B 指定 source 和 build 目录: ~/package $ cmake -S . -B build ~/package $ cmake --build build install 命令: # From the build directory (pick one) ~/package/build $ make install ~/package/build $ cmake --build . --target install ~/package/build $ cmake --install ....

2024-11-13 · 3 min