I'm attempting to get a very basic program compiled and run on multiple OS's. The program just attempts to print it's filename to stream, using boost::filesystem
, so that I can verify that loading .so
's works as expected.
I compile it on an Ubuntu box:
$ uname -a
Linux ubuntu 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
And I have a CentOS box which I attempt to run it on:
$ uname -a
Linux localhost.localdomain 3.10.0-123.20.1.el7.x86_64 #1 SMP Thu Jan 29 18:05:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
I compile the executable using $ORIGIN
so that the linked boost libraries will be picked up from my directory, then I ldd
the boost libraries and cp
them into the same. So, the lib directory looks as follows:
deliverable/
deliverable/hello
deliverable/.lib/
deliverable/.lib/libc.so.6
deliverable/.lib/libboost_system.so.1.58.0
deliverable/.lib/libpthread.so.0
deliverable/.lib/libm.so.6
deliverable/.lib/libstdc++.so.6
deliverable/.lib/libboost_filesystem.so.1.58.0
deliverable/.lib/libboost_filesystem.so
deliverable/.lib/libfoo.so
deliverable/.lib/libboost_system.so
deliverable/.lib/libgcc_s.so.1
where hello
is the executable I want to run. However, on the CentOs box, I get the following error:
$ ./hello
$ ./hello: relocation error: ~/deliverable/.lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
How can this be fixed? I'd also like to know if this pattern violates best practices regarding shipping compiled code between Linux machines . . .
More info if relevant:
$ cat Makefile
CXX = g++
CPPFLAGS := -Wall -g -Wfatal-errors -std=c++11 -I./inc -fPIC
DELIVERABLE = $(CURDIR)/deliverable
LIB = $(DELIVERABLE)/.lib
all: $(DELIVERABLE)/hello
$(DELIVERABLE)/hello: main.o $(LIB)/libfoo.so
$(CXX) -L./deliverable/.lib -Wl,--allow-shlib-undefined -Wl,-rpath='$$ORIGIN/.lib' -o $@ $< -lfoo
main.o: main.cc
$(CXX) $(CPPFLAGS) -c $< -o $@
$(LIB)/libfoo.so: foo.o
$(CXX) -L./deliverable/.lib -Wl,--allow-shlib-undefined -Wl,-rpath='$$ORIGIN/.lib' -shared -o $@ $^ -lboost_system -lboost_filesystem
foo.o: foo.cc
$(CXX) $(CPPFLAGS) -c $< -o $@
clean:
rm -f *.o $(LIB)/libfoo.so $(DELIVERABLE)/hello
$ cat main.cc
#include "foo.hh"
int main()
{
hello();
}
$ cat foo.hh
#ifndef FOO_HH
#define FOO_HH
void hello();
#endif
$ cat foo.cc
#include "foo.hh"
#include <boost/filesystem.hpp>
#include <iostream>
void hello()
{
boost::filesystem::path p{__FILE__};
std::cout << "p.parent_path() " << p.parent_path() << '\n';
std::cout << "p.string() " << p.string() << '\n';
std::cout << "__FILE__ " << __FILE__ << '\n';
}
I also tried this on a RHEL box, which gave an even worse error:
$ uname -a
Linux localhost.localdomain 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 ... EXT 2009 x86_64 x86_64 GNU/Linux
Running it on this machine crashed with:
$./hello
./hello: error while loading shared libraries: ~/deliverable/.lib/libm.so.6: unexpected PLT reloc type 0x25