How to prevent mangling for entire crate?

In my rust code I use #[no_mangle] to prevent mangling for each function.

Is there a configuration/build setting to prevent mangling for all functions in my crate?

There is but...

warning: attribute should be applied to a free function, impl method or static
warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

...using it puts you on a path to a "hard error".

@Coding-Badly I believe that warning says that it was previously ignored entirely.

@sniper There is no way to do this. In fact for things like generic functions disabling mangling is guaranteed to lead to symbol conflicts and as such forbidden. For everything else it is just likely to cause conflicts. You also likely don't want this anyway as only extern "C" functions have a stable abi, the rust abi is not stable so you can't call these functions even when using no_mangle. Why do you want all functions to be no_mangle?

1 Like

@bjorn3 Understood, don't need no_mangle for all. Thanks.

Don’t disable mangling if you’re not writing some kind of dynamic link library. Symbol mangling is a very convenient feature that allows you, for example, to have two functions with the same name in different modules. Disabling mangling can lead to errors.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.