Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building linuxbrew (homebrew) standalone version on Ubuntu 14.04

The Primary Question

I'm trying to build the linuxbrew standalone installation on Ubuntu 14.04.3 LTS, but the script in the original link is currently broken. My ideal answer would be a script that sets it up correctly in one go. I've improved the script to run with fewer hiccups.

Current progress towards fixing the script

I'm not able to get past a crti.o error when building gcc via linuxbrew as part of the standalone setup. However, I found some resources explaining the problem:

  • stackoverflow crti.o file missing
  • stackoverflow cannot find crti.o
  • askubuntu crti.o
  • old launchpad bug

I searched for the file and it was right there!

find -name crti.o
./.linuxbrew/lib/crti.o
./.linuxbrew/Cellar/glibc/2.19/lib/crti.o

I'm currently on the following compiler error for crtn.o:

/home/hbr/.linuxbrew/Cellar/binutils/2.25.1/x86_64-unknown-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/home/hbr/.linuxbrew/Cellar/binutils/2.25.1/x86_64-unknown-linux-gnu/bin/ld: cannot find -lc
/home/hbr/.linuxbrew/Cellar/binutils/2.25.1/x86_64-unknown-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
make[3]: *** [libgcc_s.so] Error 1
make[3]: Leaving directory `/tmp/gcc20150929-3726-hif3of/gcc-5.2.0/build/x86_64-unknown-linux-gnu/libgcc'
make[2]: *** [all-stage1-target-libgcc] Error 2
make[2]: Leaving directory `/tmp/gcc20150929-3726-hif3of/gcc-5.2.0/build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/tmp/gcc20150929-3726-hif3of/gcc-5.2.0/build'
make: *** [bootstrap] Error 2

Essentially, at this step I need to figure out how to make sure brew/linuxbrew/the gcc compilation command knows where to find it. I tried adding it to PATH, LIBRARY_PATH, and LD_LIBRARY_PATH in the script all without any luck. So, there must be some other way to make sure the path is set correctly and the object file is found. Any ideas?

Note: I originally searched for help in this github issue but they haven't been able to solve this at the moment.

Update

I think a linuxbrew case may be needed in this linuxbrew gcc formula that implements one of the solutions found in stackoverflow crti.o file missing.

This is the original homebrew gcc formula for reference.

like image 948
Andrew Hundt Avatar asked Sep 29 '15 22:09

Andrew Hundt


1 Answers

I've updated the linuxbrew standalone installation instructions with the solution. I've also created an updated linuxbrew-standalone.sh that's tested and working in 14.04 with a couple of small caveats listed below in the TODO comments.

# /bin/bash
set -e
set -u
set -x

cd $HOME

# TODO: The next ln -s line breaks cross compiling with multiarch, need an alternative!
#       source: https://stackoverflow.com/a/9004026/99379
sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
sudo apt-get update -y
sudo apt-get update --fix-missing -y
sudo apt-get install build-essential curl g++ git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev gawk make patch tcl -y

unset LD_LIBRARY_PATH PKG_CONFIG_PATH HOMEBREW_CC
PATH=$HOME/.linuxbrew/bin:/usr/local/bin:/usr/bin:/bin
yes | ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/linuxbrew/go/install)"

# hang on here. you will have to press return
# note that even if brew doctor is a little unhappy we want to keep going
brew doctor || true

mkdir $HOME/.linuxbrew/lib
ln -s lib $HOME/.linuxbrew/lib64
ln -s $HOME/.linuxbrew/lib $HOME/.linuxbrew/lib64
ln -s /usr/lib64/libstdc++.so.6 /lib64/libgcc_s.so.1 $HOME/.linuxbrew/lib/
PATH=$HOME/.linuxbrew/lib:$PATH
export PATH
LIBRARY_PATH=$HOME/.linuxbrew/lib
export LIBRARY_PATH
LD_LIBRARY_PATH=$HOME/.linuxbrew/lib
export LD_LIBRARY_PATH

# before this, you may want to `brew edit glibc` to produce compatibility for your particular kernel, for example:
# "--enable-version=2.6.18"

#brew unlink gawk
brew install glibc
brew unlink glibc
brew install https://raw.githubusercontent.com/Homebrew/homebrew-dupes/master/zlib.rb
brew reinstall binutils
brew link glibc
brew install patchelf
brew install gcc --with-glibc --only-dependencies -v
# When tested gcc was working except for the linking step, that's why it is force-accepted with ||true
# TODO: make it so force accepting isn't necessary and errors are shown correctly
brew install gcc --with-glibc -v || true
rm -f $HOME/.linuxbrew/lib/{libstdc++.so.6,libgcc_s.so.1}
brew link gcc --overwrite
export HOMEBREW_CC=gcc

brew install bzip2 curl expat
brew install git --with-brewed-curl --with-brewed-openssl --without-tcl-tk
brew tap homebrew/dupes
brew install coreutils findutils gawk gnu-sed gnu-which grep libpng libxml2 libxslt make ncurses readline
#ln -s ncursesw/curses.h ncursesw/form.h ncursesw/ncurses.h ncursesw/term.h ncursesw/termcap.h $HOME/.linuxbrew/include/
#ln -s libncurses.a $HOME/.linuxbrew/lib/libcurses.a
#ln -s libncurses.so $HOME/.linuxbrew/lib/libcurses.so
brew install ruby
PATH=$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin
brew install hello && brew test hello; brew remove hello

The primary line that fixed things was sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64, but this comes with a caveat for which I'm interested in a fix, because it breaks cross compiling with multiarch.

like image 198
Andrew Hundt Avatar answered Nov 04 '22 02:11

Andrew Hundt