Cross Compiling Go - linux

I am trying to cross compile Go for ubuntu linux x86_64 on my macbook. I have followed instructions outlined here but when I run go-linux-amd64 build I get the following message go build runtime: linux/amd64 must be bootstrapped using make.bash. Any help with this will be appreciated.

What it's saying you need to do is rebuild the library and runtime for linux-amd64. You can do that this way:
Find the root of your Go installation (if you don't know where this is, running which go may help - the binary is often installed with the rest of the sources).
cd into the src directory
Run GOOS=linux GOARCH=amd64 ./make.bash --no-clean (or GOOS=linux GOARCH=amd64 bash make.bash --no-clean if make.bash is not executable). This will rebuild the library and runtime using the specified OS and architecture.
Once you've done this, you can build a go package or binary for this architecture using GOOS=linux GOARCH=amd64 go build. You can follow the same instructions for other architectures and operating systems.
Edit (08/13/15):
As of Go 1.5, cross compiling is much easier. Since the runtime is written in Go, there's no need to set anything up in order to be able to cross-compile. You can now just run GOOS=<os> GOARCH=<arch> go build from a vanilla Go installation and it will work.
However, there's one exception to this. If you're using cgo, you'll still need to set stuff up ahead of time. And you'll need to inform the tooling that you want to enable cgo cross-compiling by setting the CGO_ENABLED environment variable to 1. So, to be precise:
cd into the src directory of your Go installation (see the instructions above).
Run CGO_ENABLED=1 GOOS=<os> GOARCH=<arch> ./make.bash --no-clean
Run CGO_ENABLED=1 go build to build your project. It is important that you specify CGO_ENABLED=1 even when you're compiling.

Following the above answer https://stackoverflow.com/a/27413148/3675575, I needed to set GOROOT_BOOTSTRAP to recompile my GO source tree:
GOROOT_BOOTSTRAP=/usr/lib/golang/ CGO_ENABLED=1 GOOS=linux GOARCH=386 ./make.bash --no-clean
(I'm using Fedora 23, so the GOROOT_BOOTSTRAP may vary in your operating system)

You must cd %goroot%/src/,find make.bash
Then execute ./make.bash
execute your command. Try it!

Related

Create a ready to use install package on linux with cmake or gcc, including shred dependencies

I have completed a small project that uses several libraries. the CMakeList.txt looks like this:
cmake_minimum_required(VERSION 3.5)
project(tf_ct_log C)
set(CMAKE_C_STANDARD 99)
include_directories(include /usr/local/include/hiredis /usr/include/openssl)
link_directories(/usr/lib/x86_64-linux-gnu)
set(HDR include/ct_logger.h)
add_executable(tf_ct_logger src/main.c src/ct_logger.c ${HDR})
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
find_library(PostgreSQL REQUIRED)
find_library(jansson REQUIRED)
target_link_libraries(tf_ct_logger OpenSSL::SSL jansson pthread pq)
I would like to be able to build a package that can be installed in another machine, without downloading any dependencies. with ldd, I 've got all dependencies of the application and copied those files (libxyz.so...) into a subdirectory deps in my project. How can I create that package using those dependencies so that the end user will just use the object files of my project along with the dependencies libraries to create the executable?
It gets really hairy real quick when you need to create a native package for multiple flavors of installers (Debian, RH, Arch, etc.), especially if customization is involved.
If you just need a clean reproducible to get it on a box and run -- I would strongly suggest looking towards packaging it as a Docker container.
You start from some lightweight Linux distro container (Alpine is the latest trend), derive it into one with C and C++ runtime and anything else you depend on and call this "my prod container". From that you derive one with C++ compiler and debugger installed and call it "my dev container".
We actually wrote a little memo a while back, while making our open source hobby usable for others.
You will probably still need to clean up your CMake file to an extent that the "install" target works (mine is here).
I may have not expressed myself correctly. I just wanted to compile and build executables from my project, then find a way to copy it on another machine without having to install all dependencies before running the app.
The solution I found (with the help of a more experienced developer) was as follows:
1- Get all dependencies using ldd
2- Copy dependencies in a directory dependencies
3- On the target environment, copy content of dependencies into /usr/local/lib/myapp/
4- On the target environment, goto /etc/ld.so.conf.d/
5- create the file myapp.conf with one line in it: /usr/local/lib/myapp
6- run ldconfig
Then, the executable I created on my development machine runs here smoothly!
Of course all the steps I described up there must be listed in a script for automation

How do I build vala from scratch

When I try to build vala (https://github.com/gnome/vala), I get an error from autogen that vala must already be installed in order to build vala. So how can I build it on a system that doesn't have it already? I get that it is self hosting, but there has to be some way to boot strap it.
My os is Android-x86 6.x
You can download a source tarball from download.gnome.org and build from there. The tarballs contain generated C code to build the compiler without a Vala compiler installed.
The procedure would be something like:
curl --location https://download.gnome.org/sources/vala/0.38/vala-0.38.4.tar.xz \
--output vala-0.38.4.tar.xz
tar --extract --file vala-0.38.4.tar.xz
cd vala-0.38.4/
./configure
make
The configure script should detect there is no valac installed and select the bootstrap option. You could also try make bootstrap if you run in to problems.
You can then run the test suite and install to the usual Unix file locations with:
make check
make install
Although the install part may not be relevant to Android.

how I can build mozilla projects

I found https://github.com/mozilla/gecko-dev/tree/master/b2g Mozilla repositories where have the moz.build file, can anybody help, how I can build this plugin. What are tools I need use for build project with use moz.build ?
thank you
If you are trying to build B2G (Firefox OS), then you should follow the procedure documented here. But I have to advise you that you're using the wrong repository if that's your objective, since the correct one for B2G should be this.
In any case, you would need to install the build prerequisites for Linux, as described here, by using the following command:
wget -O bootstrap.py https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py && python bootstrap.py
Now, if you really wanted to just build the b2g folder in the repository you linked, once you've downloaded and installed the prerequisites, simply issue the following command from the root of gecko-dev:
./mach build b2g
This will invoke mach, the build system Mozilla uses, to build the code in the b2g directory.

Install lldb only in llvm

I'm starting to work with llvm infrastructure, and i'm interested in the use of the debugger tool lldb instead of default gdb. I followed the tutorial of installation of clang (Linux System, through svn options) and now wanted to know if is possible to install lldb only, instead of rebuild the whole structure of llvm. I don't found a especific documentation for that and i don't know any especific forum for llvm, so if anyone know some forum of llvm,
Sorry about my english, i'm a brazilian developer.
I actually found the solution yesterday, but was not sure how the policies to answer your own questions work here, but according to this it's allright. :)
In fact, it is quite simple.
First, you must identify the directory 'src-root' of the installation of the tools llvm/clang using the command 'llvm-config':
llvm-config --src-root
Once you find the directory, you must navigate to the path $src-root/tools and checkout the lldb:
svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb
The next step is go to the build directory, if the steps of the tutorial has been followed, is just necessary to clean the build directory:
rm -rf *
Now, is the step of building the lldb, I personally have used the autoconf options (classical configure make && make install), but cmake can be used as well. When the configure script runs, the binaries of llvm and clang already installed will be detected, avoiding rebuild the whole structure of llvm/clang.
The parameters of the configure script can be changed, I use as follow because I intend to use the llvm libraries:
../llvm/configure --enable-optimized --enable-assertions --enable-shared --enable-targets=host
Then:
make -j4
sudo make install
where -j4 option is the number of threads (jobs) to be created.
Reference: http://www.felixmorgner.ch/en/blog/building-clang-lldb-and-libc-on-ubuntu/

Following instructions to build LLVM to the letter, but executables aren't produced

I am running 64-bit Linux and I am attempting to build the LLVM trunk. I follow the instructions to the letter, and invoke configure with the arguments I want, followed by make. Running make install leaves each directory with no action, and running locate on a name of an llvm executable (such as clang) comes up with no results.
I do not understand what could be wrong here, but I am quite sure that no executables are produced. This exact process works for software in general. Is there some absurdly obvious thing that I am missing?
I'm using gcc 4.5 and 3.81.
Depending on whether you asked for debug or release build, you can check the stuff inside bin subdir of Debug or Release (alternatively, Debug+Assert, Release+Assert) directory in your build directory for the binaries.
If there is still nothing, then you can go to tools/ and invoke make directly to check what's going there. Doing "make VERBOSE=1" might provide some additional information.
You probably want to say what's happening and maybe take a look at what's going on and how exactly you invoked configure and make.
Here is what has been working for me on the last 4 or so Ubuntu 64 bit distros.
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm
cd tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ..
./configure --enable-optimized --disable-doxygen --prefix=/llvm
make
make install

Resources