Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find package math/bits

Tags:

go

I'm getting the following error when I execute my tests. This was working previously. Not sure what I need to do in order to fix this error.

golang.org/x/crypto/ripemd160/ripemd160block.go:12:2: cannot find package "math/bits" in any of:
    /usr/local/Cellar/[email protected]/1.8.7/libexec/src/math/bits (from $GOROOT)
like image 369
Pubudu Avatar asked Dec 18 '22 00:12

Pubudu


1 Answers

Go 1.9 Release Notes

New bit manipulation package

Go 1.9 includes a new package, math/bits, with optimized implementations for manipulating bits. On most architectures, functions in this package are additionally recognized by the compiler and treated as intrinsics for additional performance.

You need Go version 1.9 or later.


I have several versions of Go installed from source in my $HOME directory: ~/go1.4, ~/go1.8, ~/go1.9, ~/go1.10, and ~/go (devel). Copy the src/math/bits folder from go1.9 or later to go1.8. From go1.8/src run go1.8 install -v math/bits.

go1.8:

#!/bin/sh

# $HOME/bin/go1.8

export GOARCH=amd64
export GOOS=linux
export GOROOT=$HOME/go1.8 
export GOBIN=$GOROOT/bin

exec $GOBIN/go "$@"

Output:

$ cd ~/go1.8/src
$ go1.8 install -v math/bits 
math/bits

For example,

package main

import (
    "fmt"
    "math/bits"
)

func main() {
    fmt.Println(bits.UintSize)
}

Output:

$ go1.8 run bits.go
64
like image 79
peterSO Avatar answered Dec 20 '22 14:12

peterSO