OP solution and conclusions
Based on previous answers here is the solution I ended up doing.
1. Copy the source code
Copy your source code to the VM or other machine.
I've used :
scp -R /host/path/to/src/ user@remoteHost:/remote/build/path/
It's like going on a road trip, so pack well, gather all the sources that you require for compile, minus the shared libs and other resources that you can find on the other machine.
2. Install dependencies (libs/build tools)
Reverted VM to basic install (centOS7 min) and updated the tools used to build my app, based on trial and error (yum search, install, try build command)
yum -y update
yum -y install boost-* #probably could have used only boost-devel
yum -y install glibc-utils
yum -y install gcc-c++
yum -y install git
yum -y install libtool
yum -y install zlib-devel
yum -y install ncurses-devel
yum -y install make
yum -y install cmake
yum -y install openssl-devel
yum -y install libssh2-devel
...
In case your project depends on (newer) libraries not available in the OS repository, install from source:
For example I needed curl built with c-ares, and the updated mysql client library.
#mysqlclient
if [[ -z $(ldconfig -p | grep libmysqlclient) ]]
then
mkdir -p "${INSTALL_PREQ_PATH}/lib/mysql/";
cd "${INSTALL_PREQ_PATH}lib/mysql/"
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum -y localinstall mysql-community-release-el7-5.noarch.rpm
sudo yum install mysql-community-client
sudo yum install mysql-community-devel
fi
#c-ares
if [[ -z $(ldconfig -p | grep libcares) ]]
then
mkdir -p "${INSTALL_PREQ_PATH}lib/libcares/"
cd "${INSTALL_PREQ_PATH}lib/libcares/"
git clone git://github.com/bagder/c-ares.git
cd c-ares
./buildconf
./configure
make
sudo make install
ldconfig
fi
#libcurl
if [[ -z $(ldconfig -p | grep libcares) ]]
then
mkdir -p "${INSTALL_PREQ_PATH}lib/libcurl/"
cd "${INSTALL_PREQ_PATH}lib/libcurl/"
wget http://curl.haxx.se/download/curl-7.39.0.tar.gz
tar -xvzf curl-7.39.0.tar.gz
cd curl-7.39.0
./configure --enable-ares --with-libidn --with-zlib --disable-ipv6
make
sudo make install
ldconfig
fi
Obs: each build comes with it's own dependencies, and were added to the step above.
3. Foreach dependency installed, verify it's working and check if you broke anything
Check if libraries are loaded by the system:
ldconfig # update library cache
ldconfig -p | grep libcurl # check for library
In my case libraries were installed in /usr/local/lib/ folder, which is not included by default in the link builder search path. To fix this:
echo "/usr/local/lib/">/etc/ld.so.conf.d/local.conf #add lib search path
ldconfig #reload library cache
Also check if the other programs that use that shared lib are still working.
In my case the curl install broke yum as it was missing ssh and ssl, fix:
rm /etc/ld.so.conf.d/local.conf #remove the new libs search path
ldconfig #reload
yum install openssl-devel #install ssl dependency
yum install libssh2-devel #install ssh dependency
cd "${INSTALL_PREQ_PATH}lib/libcurl/" #go to libcurl source path
./configure --enable-ares --with-libidn --with-zlib --disable-ipv6 --with-ssl --with-libssh2 # configure build with ssl and ssh
make #compile
sudo make install #install binary, libs and headers
echo "/usr/local/lib/">/etc/ld.so.conf.d/local.conf #add lib search path
ldconfig #reload library cache
4. Build your program
In my case I used the same compiler I used on ubuntu, gcc-c++ (g++).
In case it's not working:
- See if any dependency is missing, read warnings and errors
- Check compiler version on both machines, check if there are differences in support for your code and compiler flags, use the internet to find ways to update your compiler for your OS
Other notes:
- Write down your steps, preferably in a bash script so you can retry or (re)install on another machine.
- This is not good advice for a production machine, run trials somewhere else.
- If you're using a VM, take snapshots, otherwise backup, and always be prepared to fail
- Don't take my advice, this is what worked for me, it might not work for all, and might be a bad choice for other cases. I'm no expert just writing to help out other noobs like me :)
binutils
,glibc
,gcc
,libtool
,make
, and a few others all to versions supporting C++11. See Packages to rebuild after upgrading gcc on gentoo systems for another related answer. Once you get the build chain updated, you need to follow slm's advice in the answer below and use the native packaging tools for CentOS. – eyoung100 Nov 25 '14 at 14:44