Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cpp stdlib include error #57

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

dbenusov
Copy link
Contributor

While trying to compile with your toolchain using C++ I ran into an error:

ERROR: /work/dbenusovich/sw/fw/app/arm_test/BUILD:6:10: Compiling fw/app/arm_test/main.cc failed: (Exit 1): arm-none-eabi-gcc failed: error executing CppCompile command (from target //fw/app/arm_test:binary) external/toolchains_arm_gnu~~arm_toolchain~arm_none_eabi_linux_x86_64/bin/arm-none-eabi-gcc -MD -MF bazel-out/k8-fastbuild-ST-bf8fd271169b/bin/fw/app/arm_test/_objs/binary/main.d ... (remaining 40 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from fw/app/arm_test/main.cc:3:
external/toolchains_arm_gnu~~arm_toolchain~arm_none_eabi_linux_x86_64/arm-none-eabi/include/c++/13.2.1/cstdlib:79:15: fatal error: stdlib.h: No such file or directory
   79 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.
Use --verbose_failures to see the command lines of failed build steps.

This is how I was including the toolchain:

bazel_dep(name = "toolchains_arm_gnu", version = "1.0.2")
arm_toolchain = use_extension("@toolchains_arm_gnu//:extensions.bzl", "arm_toolchain")

arm_toolchain.arm_none_eabi()
use_repo(arm_toolchain, "arm_none_eabi")
register_toolchains(
    "@sw//fw/toolchain/arm:all",
)

With a custom toolchain of:

# Cortex-M7 toolchain
arm_none_eabi_toolchain(
    name = "cortex_m7_toolchain",
    copts = [
        "-mcpu=cortex-m7",
        "-mthumb",
        "-mfloat-abi=hard",
        "-mfpu=fpv5-d16",
    ],
    linkopts = [
        "-mcpu=cortex-m7",
        "-mthumb",
        "-mfloat-abi=hard",
        "-mfpu=fpv5-d16",
        "-nostartfiles",
    ],
    target_compatible_with = [
        "@platforms//os:none",
        "//fw/toolchain/arm:cortex_m7_cpu",
    ]
)

Very similar to the examples you provided :) Thanks for making those!

@mark64 pointed out that the order of includes was incorrect. I am not sure if this will break something for other users so feel free to decline this change. However, this does compile for C++ now.

Signed-off-by: Daniel Benusovich <[email protected]>
@hexdae
Copy link
Owner

hexdae commented Jul 25, 2024

Hey, thanks for the addition, I really should include more C++ examples and tests. This change looks good and passed CI so I will merge it

@hexdae hexdae merged commit acc1716 into hexdae:master Jul 25, 2024
6 checks passed
@FaBrand
Copy link
Contributor

FaBrand commented Sep 30, 2024

Cool, we faced the same issue. @hexdae Do you have a plan, or how can we support in releasing this? :)

@hexdae
Copy link
Owner

hexdae commented Oct 1, 2024

Hey @FaBrand, this change should be released in the latest version on the registry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants