【问题标题】:Unable to find uint8_t despite having build the freestanding libs for C++尽管已经为 C++ 构建了独立的库,但仍无法找到 uint8_t
【发布时间】:2023-01-26 00:56:18
【问题描述】:

尽管已经为 C++ 构建了独立的库,但仍无法找到 uint8_t

我得到的错误是:

/home/jared/projects/cpp_projects/NakOS/Kernel/src/kernel.cpp:3:1: note: 'uint8_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?

这似乎是一个简单的修复,只需添加 #include &lt;cstdint&gt;,但我的文件如下所示:

#include "inc/kernel.hpp"
#include <cstdint>

void Kernel::kernel_main()
{
    uint8_t a;
}

这是加重。我知道我有库本身,因为我在我的工具链中看到它:

$ find . -name cstdint
./Toolchain/src/gcc-12.2.0/libstdc++-v3/include/tr1/cstdint
./Toolchain/src/gcc-12.2.0/libstdc++-v3/include/c_global/cstdint
./Toolchain/src/gcc-12.2.0/libstdc++-v3/testsuite/tr1/8_c_compatibility/cstdint
./Toolchain/src/gcc-12.2.0/libstdc++-v3/testsuite/18_support/headers/cstdint
./Toolchain/src/build-gcc/i686-elf/libstdc++-v3/include/tr1/cstdint
./Toolchain/src/build-gcc/i686-elf/libstdc++-v3/include/cstdint
./Toolchain/opt/cross/i686-elf/include/c++/12.2.0/cstdint

我的工具链文件 Toolchain/os-dev-toolchain.cmake 看起来像:

set(CMAKE_C_COMPILER_WORKS 1)   # Skip Test because we are in a free-standing environment
set(CMAKE_CXX_COMPILER_WORKS 1) # Skip Test because we are in a free-standing environment
set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_CXX_COMPILER ${CMAKE_SOURCE_DIR}/Toolchain/opt/cross/bin/i686-elf-gcc)
set(CMAKE_CXX_COMPILER ${CMAKE_SOURCE_DIR}/Toolchain/opt/cross/bin/i686-elf-g++)

这就是我编译的方式(这些参数是用 CMake 生成的)

/home/jared/projects/cpp_projects/NakOS/Toolchain/opt/cross/bin/i686-elf-g++  -I/home/jared/projects/cpp_projects/NakOS/Kernel -I/home/jared/projects/cpp_projects/NakOS/Kernel/Graphics -I/home/jared/projects/cpp_projects/NakOS -g -pedanti
c -Wall -Wextra -Wundef -Werror -Wno-unused-parameter -ffreestanding -fno-exceptions -fno-rtti -std=gnu++20 -MD -MT CMakeFiles/nak.dir/Kernel/src/kernel.cpp.o -MF CMakeFiles/nak.dir/Kernel/src/kernel.cpp.o.d -o CMakeFiles/nak.dir/Kernel/s
rc/kernel.cpp.o -c /home/jared/projects/cpp_projects/NakOS/Kernel/src/kernel.cpp

所以,你看到我正在按照我的第一个参数使用我的交叉编译器构建

/home/jared/projects/cpp_projects/NakOS/Toolchain/opt/cross/bin/i686-elf-g++

我尝试将 sysroot 设置为我的工具箱,但没有成功

【问题讨论】:

    标签: c++ gcc linux-kernel libstdc++ freestanding


    【解决方案1】:

    /home/jared/projects/cpp_projects/NakOS/Kernel/src/kernel.cpp:3:1 它说明了第 3 行的错误,但显示的代码在第 6 行使用了 uint8_t。我想文件中的实际代码没有任何 #include 指令:

    void Kernel::kernel_main()
    {
        uint8_t a;
    }
    

    确保文件保存在该位置并且其内容与显示的代码相同。

    【讨论】:

      猜你喜欢
      • 2022-12-31
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多