2

I use install Arch Linux with duel booted Linux Mint 18.1 .In my college we have lubuntu 16.04 and Ubuntu 14.04 installed. I have also enabled testing repos in arch Linux so I get newer packages, thus due to this when I compile any C++ program on Arch it won't run on Linux Mint due to version of shared libraries don't match in mint.

like libMango.so.64 is in arch and libMango.so.60 is on mint. How can I overcome with this ?

so I am asking for how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ? Just like I compile 32 bit programs on 64 bit machine with -m32 flag , is there flag for old shared libraries too ?

I am using gcc 8.1.

orayan
  • 165
  • 2
  • 9
  • 2
    Why can't you transfer your source code to your college and compile on your college computer? – Basile Starynkevitch May 04 '18 at 11:53
  • 1
    @BasileStarynkevitch Idea is nice but I can't depend on college when I i will get job . – orayan May 04 '18 at 11:55
  • 1
    I don't understand. You can develop at home, and transfer source code. Or put your source code (assuming it is free software) on [github](http://github.com/) and develop at several places. If the code is not college homework and not free software, you probably should not (and probably are not allowed to) compile it on the college computer (in most colleges, you cannot use their computing resources for stuff unrelated to your college education) – Basile Starynkevitch May 04 '18 at 11:56
  • @BasileStarynkevitch I am currently compiling from mint. But due personal choice I am looking if there is any way of doing this without switching OS :) – orayan May 04 '18 at 12:02
  • 1
    Even with relatively simple libraries, cross-compilation is difficult: https://stackoverflow.com/q/4032373/8120642 – hegel5000 May 04 '18 at 12:05
  • 3
    You may use build container (like [docker](https://www.docker.com/) on any other) with exact library versions your collegue using, or even run your project on the same container on your and your collegue's computer (if he won't mind installing additional software) – Denis Sheremet May 04 '18 at 12:16
  • Don't enable the *testing* repos on Arch unless you are testing the packages themselves. Those repositories are separate for a reason and you are not guaranteed to have a stable system mixing testing and core, extra and community. – David C. Rankin Oct 21 '18 at 08:50

1 Answers1

7

how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ?

You cannot do that reliably if the API (or even the ABI, including size and alignment of internal structures, offsets of fields, vtables organization) of those libraries have changed incompatibly.

In general, you'll better recompile your source code on the other computer (and your college might forbid that, if that source is unrelated to your education). BTW, if your source code sits in some git repository (e.g. github if it is open source) transferring on multiple computers is very easy.

Some very few libraries make genuine (and documented) efforts on being compatible with other versions of them in binary form (e.g. at the ABI level), but this is not usual. The Unix and free software tradition is to care about source level compatibility. And the POSIX standard cares only about source compatibility.

You might consider using some chroot-ed environment (see chroot(2) and path_resolution(7) & credentials(7)) to have the essential parts of your older distribution on your newer one. Details are distribution specific (on Debian & Ubuntu, see also schroot and debootstrap). You could also consider running a full distribution in some VM, or using containers à la Docker.

And you might try to link (locally) your executable statically, so compile and link with g++ -static

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547