J-find your present(2)

本文介绍了一种使用位运算解决问题的方法,特别是通过异或运算找出数组中唯一出现奇数次的元素。文中详细解释了异或运算的基本法则及其应用场景。

运用位运算,真的强!!位运算法则,a^b=b^a   ,    (a^b)^c=a^(b^c)  ,   a^b^a=b   ,0^a=a,   a^a=0;

由于给的数组里都出现偶数次,只有一个出现奇数次,所以一直位运算,最后只剩下一个出现奇数次的

异或位运算:http://blog.youkuaiyun.com/tangyanzhi1111/article/details/21696943

Build directory for the kernel ------------------------------ When compiling the kernel, all output files will per default be stored together with the kernel source code. Using the option ``make O=output/dir`` allows you to specify an alternate place for the output files (including .config). Example:: kernel source code: /usr/src/linux-4.X build directory: /home/name/build/kernel To configure and build the kernel, use:: cd /usr/src/linux-4.X make O=/home/name/build/kernel menuconfig make O=/home/name/build/kernel sudo make O=/home/name/build/kernel modules_install install Please note: If the ``O=output/dir`` option is used, then it must be used for all invocations of make. Configuring the kernel ---------------------- Do not skip this step even if you are only upgrading one minor version. New configuration options are added in each release, and odd problems will turn up if the configuration files are not set up as expected. If you want to carry your existing configuration to a new version with minimal work, use ``make oldconfig``, which will only ask you for the answers to new questions. - Alternative configuration commands are:: "make config" Plain text interface. "make menuconfig" Text based color menus, radiolists & dialogs. "make nconfig" Enhanced text based color menus. "make xconfig" Qt based configuration tool. "make gconfig" GTK+ based configuration tool. "make oldconfig" Default all questions based on the contents of your existing ./.config file and asking about new config symbols. "make silentoldconfig" Like above, but avoids cluttering the screen with questions already answered. Additionally updates the dependencies. "make olddefconfig" Like above, but sets new symbols to their default values without prompting. "make defconfig" Create a ./.config file by using the default symbol values from either arch/$ARCH/defconfig or arch/$ARCH/configs/${PLATFORM}_defconfig, depending on the architecture. "make ${PLATFORM}_defconfig" Create a ./.config file by using the default symbol values from arch/$ARCH/configs/${PLATFORM}_defconfig. Use "make help" to get a list of all available platforms of your architecture. "make allyesconfig" Create a ./.config file by setting symbol values to 'y' as much as possible. "make allmodconfig" Create a ./.config file by setting symbol values to 'm' as much as possible. "make allnoconfig" Create a ./.config file by setting symbol values to 'n' as much as possible. "make randconfig" Create a ./.config file by setting symbol values to random values. "make localmodconfig" Create a config based on current config and loaded modules (lsmod). Disables any module option that is not needed for the loaded modules. To create a localmodconfig for another machine, store the lsmod of that machine into a file and pass it in as a LSMOD parameter. target$ lsmod > /tmp/mylsmod target$ scp /tmp/mylsmod host:/tmp host$ make LSMOD=/tmp/mylsmod localmodconfig The above also works when cross compiling. "make localyesconfig" Similar to localmodconfig, except it will convert all module options to built in (=y) options. You can find more information on using the Linux kernel config tools in Documentation/kbuild/kconfig.txt. - NOTES on ``make config``: - Having unnecessary drivers will make the kernel bigger, and can under some circumstances lead to problems: probing for a nonexistent controller card may confuse your other controllers. - A kernel with math-emulation compiled in will still use the coprocessor if one is present: the math emulation will just never get used in that case. The kernel will be slightly larger, but will work on different machines regardless of whether they have a math coprocessor or not. - The "kernel hacking" configuration details usually result in a bigger or slower kernel (or both), and can even make the kernel less stable by configuring some routines to actively try to break bad code to find kernel problems (kmalloc()). Thus you should probably answer 'n' to the questions for "development", "experimental", or "debugging" features. ——详述一下这段话的步骤
最新发布
08-09
<think>我们被要求详述用户提供的关于内核构建目录和内核配置的步骤。用户提供的文本主要分为两部分:构建目录(Build directory for the kernel)和配置内核(Configuring the kernel)。我们将分别详述这两个部分的步骤,并按照用户的要求在最后提出3-5个相关问题。 ### 第一部分:构建目录(Build directory for the kernel) 1. **默认情况**:编译内核时,所有输出文件默认与内核源代码存储在同一目录。 2. **使用O=选项**:通过`make O=output/dir`可以指定一个替代目录来存放输出文件(包括.config文件)。 3. **示例**: - 内核源代码位置:`/usr/src/linux-4.X` - 构建目录:`/home/name/build/kernel` 4. **配置和构建内核的步骤**: - 步骤1:进入内核源代码目录:`cd /usr/src/linux-4.X` - 步骤2:使用指定的构建目录进行配置(例如使用menuconfig):`make O=/home/name/build/kernel menuconfig` - 步骤3:使用指定的构建目录构建内核:`make O=/home/name/build/kernel` - 步骤4:安装模块和内核:`sudo make O=/home/name/build/kernel modules_install install` 5. **重要提示**:如果使用了`O=output/dir`选项,则必须在所有make命令中使用相同的选项。 ### 第二部分:配置内核(Configuring the kernel) 1. **不要跳过配置步骤**:即使只是升级一个小版本,也不要跳过配置。因为每个版本都会添加新的配置选项,如果配置文件没有按预期设置,可能会出现奇怪的问题。 2. **使用oldconfig**:如果想将现有配置迁移到新版本,可以使用`make oldconfig`,它只会询问新配置选项的问题。 3. **其他配置命令**: - `make config`:纯文本界面,逐项询问配置。 - `make menuconfig`:基于文本的彩色菜单,单选列表和对话框。 - `make nconfig`:增强的文本彩色菜单。 - `make xconfig`:基于Qt的配置工具。 - `make gconfig`:基于GTK+的配置工具。 - `make oldconfig`:基于现有`./.config`文件的内容,只询问新的配置符号。 - `make silentoldconfig`:类似于oldconfig,但避免在屏幕上显示已回答的问题,并更新依赖关系。 - `make olddefconfig`:类似于oldconfig,但将新符号设置为默认值而不提示。 - `make defconfig`:使用架构的默认配置(`arch/$ARCH/defconfig`或`arch/$ARCH/configs/${PLATFORM}_defconfig`)创建.config文件。 - `make ${PLATFORM}_defconfig`:使用特定平台的默认配置(`arch/$ARCH/configs/${PLATFORM}_defconfig`)创建.config文件。 - `make allyesconfig`:尽可能将符号设置为'y'。 - `make allmodconfig`:尽可能将符号设置为'm'。 - `make allnoconfig`:尽可能将符号设置为'n'。 - `make randconfig`:将符号设置为随机值。 - `make localmodconfig`:基于当前配置和已加载模块(lsmod)创建配置。禁用已加载模块不需要的任何模块选项。也可以为其他机器创建,通过传递该机器的lsmod文件作为参数。 - `make localyesconfig`:类似于localmodconfig,但将所有模块选项转换为内置选项(=y)。 4. **注意事项**: - 不必要的驱动程序会使内核变大,有时可能导致问题(例如探测不存在的控制器卡可能会干扰其他控制器)。 - 即使编译了数学仿真,如果有协处理器,内核仍会使用协处理器(数学仿真将不会被使用)。内核会稍微变大,但可以在不同的机器上工作。 - “内核调试”配置通常会使内核变大或变慢,甚至可能通过主动尝试破坏错误代码来使内核不稳定(例如kmalloc())。因此,对于“开发”、“实验”或“调试”功能的问题,应该回答'n'。 ### 步骤总结 1. **准备构建目录**:如果需要,使用`O=output/dir`指定构建目录,并在后续所有命令中保持一致。 2. **配置内核**:根据需求选择合适的配置命令(如`make menuconfig`等),并完成配置。 3. **构建内核**:使用`make`命令编译内核。 4. **安装内核**:使用`make modules_install install`安装模块和内核。 ### 注意事项 - 配置时,建议备份当前配置(复制.config文件)。 - 使用`make help`可以查看可用平台的列表。 --- §§相关问题§§ 1. 为什么在构建内核时推荐使用单独的构建目录(O=选项)? 2. 使用`make localmodconfig`配置内核时,如何为另一台机器生成配置文件? 3. 在配置内核时,`make olddefconfig`和`make silentoldconfig`之间有什么主要区别? 4. 为什么在升级内核版本时即使只是小版本升级也需要重新配置? 5. 在配置内核时,哪些类型的选项通常应该被禁用以避免性能下降或系统不稳定?</think>### 内核构建目录与配置流程详解 #### 一、构建目录(Build directory)操作步骤 1. **默认行为** - 内核编译时,所有输出文件(包括 `.config`)默认存储在内核源码目录中 2. **指定独立构建目录** ```bash make O=/path/to/build/dir [command] ``` - **示例**: ```bash cd /usr/src/linux-4.X # 进入源码目录 make O=/home/name/build/kernel menuconfig # 在独立目录配置 make O=/home/name/build/kernel # 在独立目录编译内核 sudo make O=/home/name/build/kernel modules_install install # 安装内核 ``` 3. **关键规则** ⚠️ 一旦使用 `O=` 参数,后续所有 `make` 命令必须**保持相同路径**,否则会导致构建失败 #### 二、内核配置(Configuring)核心步骤 1. **配置必要性** - 即使升级小版本也**必须重新配置** - 新版本会引入新配置项,忽略配置可能导致异常问题 2. **配置升级流程** ```bash make oldconfig # 基于现有.config自动升级,仅询问新增选项 ``` 3. **配置工具选择** | 命令 | 界面类型 | 特点 | |----------------------|------------------|----------------------------------------------------------------------| | `make config` | 纯文本问答 | 需手动回答所有问题 | | `make menuconfig` | 文本彩色菜单 | 最常用(服务器环境友好) | | `make xconfig` | Qt图形界面 | 需桌面环境 | | `make localmodconfig`| 自动精简 | **根据当前加载模块(lsmod)自动禁用未用模块** | | `make olddefconfig` | 静默升级 | 继承旧配置,新选项直接取默认值(无交互) | 4. **特殊配置场景** - **跨机器配置**(示例): ```bash # 在目标机器获取模块列表 target$ lsmod > /tmp/mylsmod # 在编译机执行(支持交叉编译) host$ make LSMOD=/tmp/mylsmod localmodconfig ``` #### 三、配置注意事项(关键警告) 1. **精简原则** - ❌ 避免不必要驱动:增大内核体积,可能引发硬件探测冲突 - ❌ 谨慎启用调试选项:`DEBUG_FS`/`KGDB` 会降低性能并增加不稳定风险 - ✅ 数学协处理:启用数学仿真仍会优先使用物理协处理器 2. **危险选项** - 避免启用 `EXPERIMENTAL`(实验性功能) - 生产环境禁用 `kmalloc()` 等主动错误注入功能 - 慎用 `allyesconfig`/`allmodconfig`(过度膨胀内核) ### 完整工作流示例 ```bash # 1. 准备构建目录 mkdir -p /home/user/kernel_build # 2. 配置内核(使用旧配置升级) cd /usr/src/linux-5.15 make O=/home/user/kernel_build olddefconfig # 3. 定制配置 make O=/home/user/kernel_build menuconfig # 4. 编译安装 make O=/home/user/kernel_build -j8 sudo make O=/home/user/kernel_build modules_install install ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值