0

I'm having issues buidling projects with rust, my lib.rs only has this

use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen};

near_sdk::setup_alloc!();

#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Counter {
    // See more data types at https://doc.rust-lang.org/book/ch03-02-data-types.html
    val: i8, // i8 is signed. unsigned integers are also available: u8, u16, u32, u64, u128
}

#[near_bindgen]
impl Counter {
  
    pub fn get_num(&self) -> i8 {
        return self.val;
    }

        self.val += 1;
        let log_message = format!("Increased number to {}", self.val);
        env::log(log_message.as_bytes());
        after_counter_change();
    }

 
    pub fn decrement(&mut self) {
       
        self.val -= 1;
        let log_message = format!("Decreased number to {}", self.val);
        env::log(log_message.as_bytes());
        after_counter_change();
    }
    pub fn reset(&mut self) {
        self.val = 0;
        // Another way to log is to cast a string into bytes, hence "b" below:
        env::log(b"Reset counter to zero");
    }
}

fn after_counter_change() {
    // show helpful warning that i8 (8-bit signed integer) will overflow above 127 or below -128
    env::log("Make sure you don't overflow, my friend.".as_bytes());
}

when i run RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release i get this error:

error: linker cc not found | = note: No such file or directory (os error 2)

error: could not compile proc-macro2 due to previous error

if i add proc-macro2 to the dependecy, the error changes to cannot compile ...'other dependency' and it keeps adding new ones as i try to solve it adding them to Cargo.toml

[package]
name = "contract"
version = "0.1.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "=4.0.0-pre.4"

[profile.release]
codegen-units=1
opt-level = "z"
lto = true
debug = false
panic = "abort"
overflow-checks = true

any help?

2 Answers2

1

No, you just need to install:

sudo apt install build-essential

EDIT (Adding more info):

The Linux Rust installer doesn't check for a compiler toolchain, but seems to assume that you've already got a C linker installed! The best solution is to install the tried-and-true gcc toolchain.

How do I fix the Rust error "linker 'cc' not found" for Debian on Windows 10?

Credits to: https://stackoverflow.com/users/4498831/boiethios

Juan Peña
  • 81
  • 1
  • 3
0

it was something wrong with my WSL ubuntu, my cargo version was different from the windows one, was able to build it with windows

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 12 '22 at 00:26