C++ executable allocation policy

C++ executable allocation policy … here is a solution to the problem.

C++ executable allocation policy

Recently I asked about what I should use to Create self-contained executables that would be deployed under a number of Linux distribution issues. I was scared at first, but after reading some C++ knowledge, I managed to get the first version of my executable up and running.

A day full of joy, just happened to be in a dilemma again, and hit a wall again. The resulting executable had to be installed in many Linux distributions (Slackware, Arch, Ubuntu, Debian, CentOS, etc.), and I had absolutely no idea how to implement it. Both CentOS and Debian-based operating systems that I know have package managers, such as apt or yum, but I’m not sure if these apply to my situation.

The code I wrote relied on several libraries (more specifically RudeSocket and yaml-cpp 。 I was told that I can compile the executable and link it dynamically, so I just need to distribute the executable

It happens that I can’t find the .a file for the yaml-cpp library (only for RudeSocket). So far, here’s my question :

At first, I used dynamic linking, but (obviously) when I copied the executable to another box :

$ ./main
./main: error while loading shared libraries: libyaml-cpp.so.0.2: cannot open shared object file: No such file or directory

I also get an error when trying to compile it statically (because I don’t have the yaml-cpp .a file I mentioned):

$ g++ main.cpp parse.cpp parse.h rudesocket-1.3.0/.libs/librudesocket.a -o main -static -L/usr/local/librudesocket-1.3.0/.libs/librudesocket.a(socket_connect_ normal.o): In function `rude::sckt::Socket_Connect_Normal::simpleConnect(int&, char const*, int)':
/root/webbyget/sockets/rudesocket-1.3.0/src/socket_connect_normal.cpp:250: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/cc3cEVK1.o: In function `operator>>(YAML::Node const&, Job&)':
parse.cpp:(.text+0x1a83): undefined reference to `YAML::Node::size() const'
/tmp/cc3cEVK1.o: In function `handle_job(rude::Socket, char const*)':
parse.cpp:(.text+0x1b79): undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
parse.cpp:(.text+0x1bfd): undefined reference to `YAML::Node::Node()'
parse.cpp:(.text+0x1c10): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)'
parse.cpp:(.text+0x1dc6): undefined reference to `YAML::Node::size() const'
parse.cpp:(.text+0x1dee): undefined reference to `YAML::Node::~Node()'
parse.cpp:(.text+0x1e18): undefined reference to `YAML::Node::~Node()'
parse.cpp:(.text+0x1e37): undefined reference to `YAML::Parser::~Parser()'
parse.cpp:(.text+0x1e61): undefined reference to `YAML::Parser::~Parser()'
(...)

It’s obvious to me that g++ can’t statically compile the yaml-cpp class without telling it where to find it.

It is very important that the installation be carried out in an automated manner without human interaction.

So my question is actually twofold:

  • How can I distribute this compiler for all these distributions in the least complicated way?

  • Is there a de facto standard solution to such problems?

Thank you in advance,

Felipe.

Solution

You might give this technique to try.

Related Problems and Solutions