Goal
I'm building a portable Linux c++ environment for a course to avoid sudo
bureaucracy at our site and have a ready-made solution with VSCode included. I've done this with success for a Python course and a Julia course (see Juliawin), but g++ seems to be a different beast.
Bundling dependencies
I used a technique to download all .deb
programs and libraries (like build-essential
, liblapack-dev
and libblas-dev
) along with their dependencies and extracted it into a pseudo root directory, e.g.
Environment wrapper
I then created a bash script emdw-deps
to allow a user to activate this environment via source emdw-deps
. In this script, I set a bunch of environment variables for our build tools to pick up all the headers and libraries included in this system. Specifically, I set LD_LIBRARY_PATH
, LIBRARY_PATH
, C_LIBRARY_PATH
, CPLUS_LIBRARY_PATH
, CMAKE_LIBRARY_PATH
, INCLUDE
, C_INCLUDE_PATH
, CPLUS_INCLUDE_PATH
, CMAKE_INCLUDE_PATH
, CMAKE_PREFIX_PATH
, PATH
, CC
, and CXX
.
Cannot link libc_nonshared.a
This allows me access to all my bundled tools from a terminal session. E.g. when I type which g++
, I get the portable location:
/home/emdw/Downloads/portable_cpp/linux/usr/bin/g++
This also allows me to get the linker to link to all the bundled libraries, shared libraries, and headers. However, ld
keeps throwing a linking error for what seems to be a hardcoded location /usr/lib/x86_64-linux-gnu/libc_nonshared.a
. This is the output I get when I compile this hello world example:
$ g++ hello.cpp -o hello
/usr/bin/ld: cannot find /usr/lib/x86_64-linux-gnu/libc_nonshared.a
collect2: error: ld returned 1 exit status
The symptom
If I make a symlink from my bundled libc_nonshared.a
to the system path:
sudo ln /home/emdw/Downloads/portable_cpp/linux/usr/lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib/x86_64-linux-gnu/libc_nonshared.a -s
Then I can successfully compile hello.cpp
$ g++ hello.cpp -o hello
$ ./hello
Hello world!
Since I work on a clean Linux Mint VM with no software installed, I can confirm that this is indeed a successful compilation from my portable pipeline with only libc_nonshared.a
as a non-portable hardcoded component. This is obviously not a solution, but only a way to point to the real problem.
Question
Are there any environment variables or compiler flags that can allow me to point the build tools to an alternative location for libc_nonshared.a
?