How I solved the “error: linking with cc failed” in Large Rust Projects with Mold.

How I solved the “error: linking with cc failed” in Large Rust Projects with Mold.

When I began contributing to open supply initiatives, I began with extremely technical initiatives like Cairo Native, Madara, kakarot-rpc, amongst others.

It seems that these initiatives have a VERY giant codebase, which makes them take a very long time to put in, compile and devour an excessive amount of reminiscence sources. This causes the set up and compilation course of to fail with an error that claims one thing like this:

error: linking with cc failed: exit standing: 1
This linking error with cc on the finish has a be aware that claims:
collect2: deadly error: ld terminated with sign 9 [Killed]

It is an error that has to do with the linking of the cc compiler. When I used to be attempting to unravel it whereas looking out on the web, I spotted that it’s a quite common error and that it’s brought on by a number of elements. And that is what makes it troublesome to unravel. But in my case it has all the time been an issue of lack of reminiscence.

What I’m going to clarify is predicated on my expertise coping with that error. When we’re putting in and constructing a venture, this compilation course of is being performed with a default compiler configuration. And this default configuration doesn’t imply that it’s the most effective. Causing this course of to fail in initiatives with enormous codebases. It seems that there’s a instrument referred to as mould. Mold is a contemporary linker that makes this linking course of way more environment friendly than the default configuration that the compiler already has. Saving sources and permitting the venture in query to be constructed. Setting it up is kind of easy. It is configured as follows:

When I used to be coping with this error I used to be utilizing WSL2 and Rust, in order that’s why I’m utilizing Linux command line:

sudo apt set up mould

Follow these steps for Rust.

All the initiatives I discussed are primarily based on Rust and I used to be all the time utilizing that programming language. Curiously, I had this error not too long ago in a venture referred to as Trust-Bridge when putting in it. Luckily, I already knew the recipe I needed to apply to unravel the error. That could be it people. If you ever have that downside it is in all probability as a consequence of reminiscence points and also you simply have to alter to a mould linker.

Here you’ll be able to see a graph that exhibits how environment friendly is the executables that the mould linker produce. The variations in sizes are insane.

Image description

Note: I had this error for the primary time when contributing to Cairo Native, it took me greater than 3 days to repair that error. Some time later I additionally had the identical error with the Madara and Kakarot initiatives. But the distinction was that I did not spend days fixing the error haha.

Vinyl

by way of DEV Community https://dev.to

February 10, 2025 at 04:58PM