Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Sunday, December 13, 2015

Build git from source on Ubuntu

Install git from source on a linux/unix based system, we need to pre-install some dependent libraries:

1. tcl/tk

sudo apt-get install tcl-dev

2. gettext
otherwise, we will get an error message like this:
/bin/sh: 1: msgfmt: not found                                   Makefile:2069: recipe for target 'po/build/locale/pt_PT/LC_MESSAGES/git.mo' failed                                  
make: *** [po/build/locale/pt_PT/LC_MESSAGES/git.mo] Error 127

sudo apt-get install gettext

3. libcurl
This lib is for https support. This means you can clone repo from https:// 

You can use apt-get to install curl:



sudo apt-get install libcurl-dev
or build curl of latest version from souce tarball: curl-7.46.0.tar.gz
and make sure ssl is enabled(for https support)

/configure --with-ssl
make
sudo make install
Note:If you failed on build curl with ssl support, you can do:
sudo apt-get install libssl-dev

after that, build git
tar xf git-2.6.4.tar.gz
cd git-2.6.4

./configure
make
sudo make install



After you build curl, you can test whether https: is supported or not by:

curl https://github.com
Note:
1) if you don't install gettext before you build git, then you probably will encounter such errors when you do make command,
even if you specify an option like ./configure --without-tcltk you still will get a error like this:

after you do apt-get install gettext, all these errors will be fixed.

2) If you don't install libcurl, then when you clone a repository like this:
git clone https://github.com/xxx/abc.git
it will pop an error saying:
Cloning into gitflow...
fatal: Unable to find remote helper for 'https'
just install libcurl and rebuild git will solve this error.

Saturday, December 12, 2015

Build Python from source

Build Python from source

Here is the regular buiding process of python from source after you download the source tarball

Python is built from source using standard autotools. For example, to install it in /usr to override the old python2
tar xzvf Python-2.7.11.tgz
cd Python-2.7.11
./configure --prefix=/usr --enable-shared --with-system-ffi --enable-unicode=ucs4
make
sudo make install
This will build IDLE, too. (The --enable-shared option is needed if you ever build Python extension modules or other programs that link with Python.)

Important!
If you have an old python in your system and you want to install the new version to override the old one, you should remove the old lib files(/usr/lib/python_dir, /usr/local/lib/python_dir) in case that when you execute make and it issues an error like this:
above simple shows an error make: *** [libinstall] Error 1 without telling any useful information about what causes this error.

NOTE:
If you want to check configure options before you set the configuration, type ./configure --help

As you see in the above example, we specify a --enable-shared option, this will
generate a shared lib namely libpython2.7.so in /usr/lib/ directory, and if you don't specify this option, you may encounter compile errors when other libraries is build with python support.
I encountered this error when I compile YouCompleteMe library:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libpython2.7.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
ycm/CMakeFiles/ycm_client_support.dir/build.make:408: recipe for target '/home/xxx/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_client_support.so' failed
make[3]: *** 
...

the above error simply means it can't find libpython2.7.so, so it links to a static library which is libpython2.7.a, however it found bad values (e.g. undefined variable names). To solve this, rebuild python by specifying option  --enable-shared

Another, if you don't want to rebuild python and you know you have a libpython2.7.so in other directories(e.g. /usr/lib/x86_64-linux-gnu/libpython2.7.so), you can create a symbolic link like this: ln -s /usr/lib/x86_64-linux-gnu/libpython2.7.so /usr/lib/libpython2.7.so


It is recommended that you build with libffi dependency: --with-system-ffiAlso, you can also specify options to build OpenSSL-1.0.2e, SQLite-3.9.2 and Tk-8.6.4 Modules,

--enable-unicode=ucs4
By default Python is build with ucs2 for Unicode, however almost all linux distribution overrides it and uses ucs4. If you have a vim that is built with ucs4, and then you build python with ucs2 (by default), you will get an error like this:
error:
vim: symbol lookup error: vim: undefined symbol: PyUnicodeUCS4_AsEncodedString

Some other options:
--enable-ipv6           Enable ipv6 (with ipv4) support
--with-dbmliborder=db1:db2:...
                          order to check db backends for dbm. Valid value is a
                          colon separated string with the backend names
                          `ndbm', `gdbm' and `bdb'.
--with-fpectl           enable SIGFPE catching

after you execute make, you can do make -k test to test the result, and then do make install


Other options:

--with-system-expat: This switch enables linking against system version of Expat.
--with-system-ffi: This switch enables linking against system version of libffi. Remove if you have not installed libffi-3.2.1.
--enable-unicode=ucs4: This switch enables 32bit Unicode support in Python.


here is an nice script that can simplify the process

Install vim with python support

  1. vim has a dependency of libnurses and readline, 
    sudo apt-get install libncurses5-dev libreadline6-dev
    
  2. If you're not using vim 7.4, make sure to set the VIMRUNTIMEDIR variable correctly below (for instance, with vim 7.4a, use /usr/share/vim/vim74a):
    cd ~
    git clone https://github.com/vim/vim.git
    cd vim
    ./configure --with-features=huge \
                --enable-multibyte \
                --enable-rubyinterp \
                --enable-pythoninterp \
                --with-python-config-dir=/usr/lib/python2.7/config \
                --enable-perlinterp \
                --enable-luainterp \
                --enable-gui=gtk2 --enable-cscope --prefix=/usr
    make VIMRUNTIMEDIR=/usr/share/vim/vim74
    sudo make install
    If you want to be able to easily uninstall the package use checkinstall instead of sudo make install
    sudo apt-get install checkinstall
    cd vim
    sudo checkinstall
    Set vim as your default editor with update-alternatives.
    sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim 1
    sudo update-alternatives --set editor /usr/bin/vim
    sudo update-alternatives --install /usr/bin/vi vi /usr/bin/vim 1
    sudo update-alternatives --set vi /usr/bin/vim
  3. Double check that you are in fact running the new Vim binary by looking at the output of vim --version.
    If you don't get gvim working,try changing --enable-gui=gtk2 to --enable-gui=gnome2
    You may need to add the below option
    --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/ 
    In a Debian-like distribution, Vim's runtime directory(specified by VIMRUNTIMEDIR) is placed in /usr/share/vim/vim74/ by default. Same thing goes for--prefix=/usr in the configure call.
    However, this VIMRUNTIMEDIR may be different with a Linux distro that is not based on Debian. In such a case, just try to build vim in default directory, and not specifying --prefix=.
  4. gconftool-2 command not found

    If you open vim and see above error message, just do
  5. sudo apt-get install gconf2

Ubuntu Commands to Check Package Version

Check Package Version
apt-cache
The option policy can show the installed and the remote version (install candidate) of a package.


apt-cache policy <package>
apt-get
You can run a simulation to see what would happen if you upgrade/install a package:
apt-get -s install <package>
To see all possible upgrades, run a upgrade in verbose mode and (to be safe) with simulation, press n to cancel:
apt-get -V -s upgrade
apt-show-versions
If installed, shows version information about one or more packages:
apt-show-versions <package>
Passing the -u switch with or without a package name will only show upgradeable packages.
aptitude
The console GUI of aptitude can display upgradeable packages with new versions. Open the menu 'Upgradable Packages'. Pressing v on a package will show more detailed version information.
Or on the command-line:
aptitude versions <package>
Passing -V will show detailed information about versions, again to be safe with the simulation switch:
aptitude -V -s install <package>
Substituting install <package> with upgrade will show the versions from all upgradeable packages.

Another way using dpkg and grep:
dpkg -s <package> | grep Version
4
"The program 'apt-show-versions' is currently not installed. You can install it by typing.." – Peter Ehrlich Jul 2 '12 at 20:45

Friday, December 11, 2015

Install boost 1.59.0 (build from source)

Install boost 1.59.0 (build from source)

Get a copy of Boost distribution, download boost_1_59_0.tar.bz2.
Unzip it:
$ tar xf boost_1_59_0.tar.bz2

Type the below commands int the command line:
$ cd boost_1_59_0.tar.bz2
$ ./booststrap.sh --help

Most of boost libraries are only header libraries which does not require a compilation, however there are some libs require a compilation which may slow down you build time, consider using the --show-libraries to see what boost module you want, and using --with-libraries=library-name-list options to specify what you want.(Note: It is recommanded to build all libraries if you are not proficient in or familiar with boost, even if you it may take you more time to build.)
After we are clear about the options need to specifil, we can issue commands like
this:
$ ./bootstrap.sh --prefix=/usr/local --with-libraries=all --libdir=/usr/local/lib --includedir=/usr/local/include 
$ sudo ./b2 install

Refer to official Site:
http://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html

# Run the script which prepares Boost's build process
sudo ./bootstrap.sh --prefix=/usr/local --with-libraries=all
sudo ./b2 install
 
# Add the Boost libraries path to the default Ubuntu library search path
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/boost.conf'
 
# Update the default Ubuntu library search paths
sudo ldconfig





















Sunday, December 6, 2015

Alt Tab switch between windows group on Ubuntu 15.04

Alt Tab switch between windows group on Ubuntu 15.04

The classic Alt Tab on old Ubuntu distribution(versions before Ubuntu 12.10) will switch between all open windows in the current workspace. However, on my Ubuntu 15.04, the Alt Tab switchs between windows of different application(windows of same application will be grouped), if you have multiple windows of the same application(e.g: terminal windows), Alt Tab won't do switch for you. This causes a lot of inconvenience especially when you heavily work with multiple terminal windows, Ubuntu 15.04 provides Alt + ` for us to switch windows of the same application.(Note: ` is caret, above Tab key).

If we want to revert back to the classic Alt Tab behavior, we can follow the below method:
1 – Install Compiz Config Settings Manager and the compiz-plugins-extra (which includes the old application switcher).
sudo apt-get install compizconfig-settings-manager compiz-plugins-extra
2 –press Alt F2 and type unity in Filter input box, Start Compiz Config Settings Manager and disable the Ubuntu Unity Switcher like the below:


Find the Ubuntu Unity Switcher
Find the Ubuntu Unity Switcher

Select the switcher tab and this disable everything. If you don’t disable all the features then you can have a key binding conflict.
changing_the_behavior_of_ubuntu_unity_applicaiton_switcher_2

3 – Enable the old Compiz Switcher like so:
Close the Unity Plugins, search for the application switcher in Filter


Search for the application switcher.
Search for the application switcher.

Uncheck the “icon” select box because otherwise you end up with a rather ugly icons which are massive.
changing_the_behavior_of_ubuntu_unity_applicaiton_switcher_4
Finally Enable the Applcation Switcher.
enable_old_application_switcher.
You should now have a happy switcher. Hurray! Let me know if you have any improvements to this recipe.

Monday, August 17, 2015

Building GCC requires GMP 4.2+, MPFR 2.4+ and MPC 0.8.0+

This article addresses how to build the latest version of these three libraries(GMP, MPFR, and MPC)
at the time, they are GMP6.1.0, MPFR3.1.3, and MPC1.0.3

GMP: https://gmplib.org/
MPFR: http://www.mpfr.org/mpfr-current/#download
MPC: http://www.multiprecision.org/index.php?prog=mpc&page=download

Note: build these libraries in the above order, which means GMP > MPFR > MPC.

1.GMP
GMP has a dependency on M4, we should install this dependency library first:
sudo apt-get install M4
GMP also need to install texinfo otherwise it will pop a error message(saying you are missing makeinfo)
sudo apt-get install texinfo
2. MPFR has a dependency on aclocal
sudo apt-get install autotools-dev automake
All pre-work should have been done, now we can do ./configure and make && make install.

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH


Monday, June 29, 2015

ubuntu 15.04 installation problems(intel_rapl:no rapl domains found in package...)

When I install Ubuntu 15.04 on my VirtualBox,  an error message pops up and says"intel_rapl:no rapl domains found in package 0alized upgrade biod or use force_addr=0xaddr"



enable PAE/NX in VirtualBox, and this message dissapears!



Reference:http://askubuntu.com/questions/449574/intel-rapl-no-valid-rapl-domains-message-upon-boot

Saturday, June 27, 2015

Install the latest gcc 5.3 on Ubuntu 12.04(Build from source code)

Steps to Build GCC 5.3 From Source Code

<1> Pre-Knowledge
The regular procedure to build any program from source code is simply the below three steps:
① ./configure
make
③ make install
Note: Make sure you run ③ as root, which means: sudo make install

Besides the above step,  the non-trivial part of building a lib or application from source on Ubuntu( or any other Unix/Linux) systems is that you need to deal with the dependencies, otherwise you will suffer from a bunch of headache problems. 

Usually, ./configure will help you check the dependency that you have in your system, this help you identify what you are missing. However, according to my experience, it sometimes give false positive, which means, even if it says that the everything are ready, and when you do a make command, it tell you that something failed to be built, and even worse it doesn't even tell what the reason of failure, it simply gives a failure message and nothing else, this make it very hard to track what is the reason it failed.

So, same with the process of building GCC,  we need to be care of the dependencies, so let's go. 

<2> Build & Installation:

Dependency installation:
1) First, we need to build dependencies before we can install gcc: apt-get install build-essential
2) Second, we need to install these three libs, check this out: install gmp mpfr mpc

STEP 1: 
So first of all, we should get the latest version of gcc from its offical site or any mirror site.
You can manually download from the mirror site or use command:
sudo wget http://www.netgull.com/gcc/release/gcc-5.3/gcc-5.3.tar.bz2
STEP 2:
After we download the source code, we unzip(for *tar.bz2 files, use command: tar -xjf filename) it to a temporary directory, usually $HOME/Downloads or /opt. actually it doesn't matter where you put because we will delete them after we compile the source successfully.

STEP 3:
Enter the directory that you unzipped just now, say in $HOME/Downloads/gcc-5.3, then type command:
./configure --disable-checking --enable-languages=c,c++,objc 
--disable-multilib --with-system-zlib prefix=/usr/bin/gcc-5.3

options explaining:
--prefix=/usr/bin/gcc-5.3 means you want to install GCC in /usr/bin/gcc-5.3 directory, this happens when you want to custom the installation place and preserve the old compiler(in case you want keep two versions of compiler so that you can test some changes).
(GCC will be installed in /usr/local by default if you don't specify a --prefix=your_dir, If you want to override the old GCC, you should set --prefix=/usr because the default gcc that comes with Ubuntu is located at /usr/bin)

If nothing errors happened during above process, configuration should be successful now and we can jump to step 4. However, if errors happened, then we should see how we deal with them:

(1)error: build GCC requires GMP4.2+, MPFR 2.4.0+, and MPC 0.8.0+

This means it cannot find these libraries and if you are sure you have them and you know where they were installed, you can try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their respective hosting sites.

or if you don't understand what exactly wrong, you can do:
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev
this will simply update these libraries and after that you should be okay now.

or if you want to build the latest version of above libraries, you can read this tutorial:http://juniway.blogspot.com/2015/08/building-gcc-requires-gmp-42-mpfr-231.html

(2) it says you don't have for 32bit, but only have necessary file for 64bit system, which means you need to specify whether you build only for 64bit programs, you add options:
--disable-multilib
(3) it says that it cannot find some specific libs for language GO or JAVA, blablabla, this is because when build gcc, it automatically build the compiler for other language also, if you missing some lib for those language then error will happen, the simplest way is to specify a option the you don't build compiler for those languge:

--enable-languages=c,c++,objc
this means you only build compiler for c, c++ and objc.

(4) it says some error associating with zlib, add this options will fix it:

--with-system-zlib
and also, if you still get errors message like "Failed to build lto-compress.c, zlib.h not found!"
you can do the below to fix it:
apt-get install zlib1g-dev

STEP 4:
make 
If an error happens like this:

it means that you are trying to build gcc without a C++ compiler.
To solve this, we need to install a C++ compiler first:
sudo apt-get install g++
after this, you should be good to sudo make
and then:
sudo make install
If you encounter an error like this:
error while loading shared libraries: libmpc.so.3: cannot open shared object file: 
No such file or directory
make[5]: *** [install-exec-hook] Error 1
this is probably because your /usr/local/lib directory is not in your system search path, therefore when it was linked it say can't find the target so file. the solution is to add the lib directory where you installed in to the system path:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH

STEP 5:
Now gcc-5.3 should be installed successfully!
You can check that you have /usr/bin/gcc-5.3.0 directory now, and the gcc executable file should be in /usr/bin/gcc-5.3.0/bin.



<2>Post-Installation Configuration:
Note: if you install gcc into a default directory, the below operations may not be necessary.
However, if you specific a different target installation directory instead of the default, when you type gcc --version, it still says a old version information, this is because the user-defined directory is either not in the system search path or its path is placed after the path of the old version of GCC(e.g. PATH=/usr/bin;/usr/local/new_gcc_dir, you type gcc, it will search this PATH in order, if your old GCC is in /usr/bin/gcc, your new gcc won't get executed),  usually, /usr/bin/gcc is a symbolic link which points to a executable /usr/bin/gcc_oldversion, and if our new gcc executable is /usr/local/new_gcc_dir/gcc5.3, we can do this to update the gcc link:
remove old links first:
sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
then update:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5.3/bin/gcc 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/gcc-5.3/bin/g++ 50
Note: alternatives are located in /etc/alternatives

How to enable c++11 features?
Compile your *.cpp files, use -std=c++11 options(use gcc -std=c11 if you compile *.c file) to specify that you need c++11 feature supports.
a more complete command may look like this:
g++ -std=c++11 -O2 -Wall -pedantic -lpthread main.cpp
Note: If you want to enable -std=c++11 as default, you can type command: g++='g++ -std=c++11'
so every time when you use g++ to compile *.cpp files, c++11 features are enabled.

If you want this config to be permanent(which means when you reboot the system or open a new session window it still works), you can open ~/.bashrc file, and add one line: alias g++="g++ -std=c++11'.

However, there are some on whether you should enable c++11 features as default, since it may lead to unpleasant surprises when you work with some old codes or code from others, which make this option not portable.
My solution is to specify a different name for g++ command.
e.g :alias g++11 = "g++ -std=c++11 -O2 -Wall -pedantic'
by doing this you avoid polluting the global g++, and still can use g++11 for off-line programming, or you can specify the c++11 option in a Makefile for your specific project.(Makefile Tutorial)
Note:
As the new ISO C++ standard published in 2011, most of new features have been implemented in an experimental C++11 mode in GCC, therefore, to select this standard in GCC, use the option '-std=c++11 or std=c++14'; also, to obtain all the diagnostics required by the standard, you should specify '-pedantic' (or '-pedantic-errors' if you want them to be errors rather than warnings).

Also, as the official gnu site noted, C++14 features are available as part of "mainline" GCC in the trunk of GCC's repository and in GCC 4.8 and later. To enable C++14 support, add the command-line parameter -std=c++14 to your g++ command line. Or, to enable GNU extensions in addition to C++14 extensions, add -std=gnu++14.

In gcc6.0, -std=gnu++14 is specified by default, which means you don't need to manually add an alias for this.

C++ 2014
In this implementation the -std=gnu++14 or -std=c++14 flag must be used to enable language and library features. 


C++ 2017
In this implementation the -std=gnu++1z or -std=c++1z flag must be used to enable language and library features.


Run your test program:
./a.out

If an error happened like this:
/usr/lib/x86_64_linux-gnu/libstdc++.so.6: version 'GLIBCXX_3.4.21' not found

this is because you old libstdc++.so.6 file is located at /usr/lib/x86_64_linux-gnu/ directory(we can try command: locate libstdc++.so.6  to find all the references in file system),


but after you intall the newest gcc-5.3 to a user-defined location, for example, the lib files are installed in /usr/bin/gcc-5.3/lib64, however the old symbolic link isn't updated, that's why it says it cannot find *.so, blablabla

we need to remove the old links
cd /usr/lib/x86_64_linux-gnu
sudo mv libstdc++.so.6.libstdc++.so.6_bak
sudo mv libstdc++.so.6.0.16 libstdc++.so.6.0.16_bak
(1) then, add this directory in our system lib search path:
export LD_LIBRARY_PATH=/usr/lib/gcc-5.3/lib64:$LD_LIBRARY_PATH
or
(2) relink old links to the right place:
sudo ln -s /usr/bin/gcc-5.3/lib64/libstdc++.so.6
sudo ln -s /usr/bin/gcc-5.3./lib64/libstdc++.so.6.0.16

A useful method to deal with lib not found problem
When you install(build) other libs, it may use dependent libs for its building process, and it's highly possible you will see error messages like :"libstdc++.so.6: version `GLIBCXX_3.4.20`" not found(required by ...somefile), this is because the dependent lib GLIBCXX_3.4.20 is not found in libstdc++.so.6, and therefore your target lib or exe cannot be built.



use the below command to list all the `GLIBC` libs that libstdc++.so.6 contains:
strings /usr/lib/libstdc++.so.6|grep "GLIBC"


usually after you install the latest gcc compiler, all the dependencies should possibly be latest version, all you need to do is to find where they are located. usually they are located in /usr/lib/YOUR_GCC_INSTALLATION_DIRECTORY/lib64/

and make sure this directory is in your system path, so the system can find it automatically.
if you don't konw how to do it, just copy the files to some system-recognized location, say:

sudo cp /usr/bin/gcc-5.3/lib64/libstdc++.so.6 /usr/lib/x86_64_linux-gnu/
sudo cp /usr/bin/gcc-5.3/lib64/libstdc++.so.6.0.21 /usr/lib/x86_64_linux-gnu/

another, use  -static-libstdc++ options to compile source code if you don't fix the problem using the above ways.

Finally, if all errors are solved, remove the source code files you put in $HOME/Download directory if you don't want to save them for the future re-install of gcc



<3> GDB Debugger update!
Don't forget this step if you use GDB to debug your program.
When you update your gcc compiler, if the gdb is not updated accordingly, it will not work because of the new symbols and new features. So update your gdb the similar way as you do to the gcc.
The lastest GDB source: http://www.gnu.org/software/gdb/download/

Done! Now enjoy the latest GCC!