Setting compiler and linker options from Mbed Studio

Hello there,

I’m trying to compile and link code using Mbed Studio, including a library file (comprising Rust code) built externally. I’ve got a bunch of linker errors caused by incompatible char width. An example:

Error: L6242E: Cannot link object ./rust-libs/librust_code.ar(aeabi_div0.o) as its attributes are incompatible with the image attributes.
… wchart-16 clashes with wchart-32.

I’d like to try and address these (and other errors which will no doubt pop up) by setting compiler/linker options to make the compiled code compatible with the compiler settings for the library. The Rust toolset has limited control over some things, so I’d like to fix it on this side. Is there a way to set compiler and linker options from Mbed Studio, or do I need to use the CLI tools instead?

I’m running Mbed studio in Windows, and (for purposes of bringing up the toolchain) using the mbed-os-example-blinky project template with modifications to main.cpp to add a call to a test function in my library, which I have added to a new directory in the code tree so that Mbed Studio can see it. The target is DISCO_H747I (an STM32H747 dev board). All other project settings are as installed defaults.

Any help gratefully received!

Regards,
David

OK, so I found the settings in mbed-os-example-blinky\mbed-os\tools\profiles\debug.json (there’s a json file for each build profile). I couldn’t find any documentation for this configuration location, and found it by searching the code tree for some options I knew were being used.

I set -fno-short-wchar and it now links and runs.

Hi,

I tried this same approach to change some other compiler options, i.e. modifying mbed-os/tools/profiles/<profile>.json, but apparently mbed Studio needs to be re-started for such changes to be granted. Otherwise, when building, the generated (inside BUILD/<target>/<compiler>/) .profile-{asm, c, cxx, ld} files still reflect the situation before the changes. I’m a Windows user.

Closing mbed Studio and launching it again solved it, though. Is this the expected behaviour?

As an aside, how does one change the compiler options for a single file?

Thanks & regards.

Hi,

Closing and opening Mbed Studio shouldn’t be required, that sounds like a bug! I’ll add that to our backlog and a fix should land in a future version.

Have you tried a custom build profile, rather than modifying the built-in profiles? The “Building a program” section in these docs show how to use a custom build profile in Mbed Studio:
https://os.mbed.com/docs/mbed-studio/current/building-running/index.html

As an aside, how does one change the compiler options for a single file?

I’m not sure on this one I’m afraid. This might be better posted as a separate question in a different category :slight_smile:

Thanks,
Matthew

1 Like

Change the compiler options for a single file: I’m sure the Mbed Studio team will give you the best solution.

If there isn’t a way to give that granularity of control, you could try building the single file (or several files requiring the same treatment, if that’s the case) as a library, then linking that into the final application. The library would have its own project, and hence its own .json file to provide unique compiler settings (and linker settings to make a library file).

Regards,

David

1 Like