Linux equivalent of Windows DLL forwarders or MacOS reexport_library
Someone outside StackOverflow gave me a solution to my problem.
A .so file doesn't need to be an actual ELF file. It can also be a linker script. A linker script is a text file that contains instructions for the linker. In my case, the script is very simple. I simply install this text file as libmine.so
:
INPUT ( /install/prefix/lib/libmine.so.1 -lother )
This instructs the linker to, at the point where libmine.so
(or -lmine
) appears in the command line, to look for my library (with version suffix, so it picks up the actual ELF file), and then search the library paths for the other
library.
Then I just substitute /install/prefix
with the actual configured install prefix in my build script and I'm good to go.
Linking a shared library to a static libtool library using automake
Haven't I already linked in $(LAPACK) when I build the libA.la convenience lib?
As your linker has already told you, no. libA.la
being a convenience library is somewhat like a static library (a collection of object files).
It's unclean because now compLibB has to concern itself with the details of libA. Is there no way to link in the LAPACK libs at the libA build stage so that I don't have to re-specify it at the compLibB build stage?
You shouldn't need to specify the LAPACK libs when libA.la
is built because the final link hasn't happened yet. There's no way I know of accomplishing what you want without making libA
a shared library.
clang appears not to be linking to a library
It looks like you need to add -lsupc++
after main.cpp (see it live):
clang++ -std=c++11 -stdlib=libc++ -O2 -Wall -pedantic -pthread main.cpp -lsupc++
^^^^^^^^
As Andre Kostur notes the libc++ documentation recommends the following, although I can not seem to get this to work on Coliru:
Unfortunately you can't simply run clang with "-stdlib=libc++" at this
point, as clang is set up to link for libc++ linked to libsupc++. To
get around this you'll have to set up your linker yourself (or patch
clang). For example,
- clang++ -stdlib=libc++ helloworld.cpp -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
Alternately, you could just add libcxxrt to your libraries list, which
in most situations will give the same result:
- clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
This looks related to issues being discussed in this thread Making libc++ on Linux user-friendly, with selective quotes below:
Here's the problem: when building libc++, the linker finds the various
ABI functions in libstdc++, and is quite happy with them being there.
When Clang calls the linker for the actual program, though, it doesn't
pass along a link flag for libstdc++, only for libc++. Thus, the links
fails.
and:
This again can be worked around by explicitly specifying linking against the source library, and here -lsupc++ works.
Also see Linux equivalent of Windows DLL forwarders or MacOS reexport_library.
Related Topics
Are the 'Dot' and 'Dot Dot' Files in Unix and Linux Real Files
Where Is $Path Set? Specifically Where Is My MAC Port Path Being Set
How Provide Nested Mount of Overlayfs
How to Read Input from the Terminal Using /Dev/Stdin and Read.Csv()
Nginx Location Deny by File Extension Syntax
Terminal Closes When I Source My Script (Run with Dot at the Start)
Calculating Memory of a Process Using Proc File System
Ssh Times Out While Connecting via Ipv6 But Works with Ipv4
Apache Proxypass Not Loading Resources
Overhead of Supporting Floating Point Arithmetic Inside the Linux Kernel
Linux Script Start,Stop,Restart
Start Docker-Compose Automatically on Ec2 Startup
Gnuplot Doesn't Work Through Ssh Command
Docker in Wsl2 Alpine Without Docker Desktop