OSX: How to statically link a library and dynamically link the standard library?
Put your static libraries in, say, dir ./MyStaticLibs
and simply use -L./MyStaticLibs/ -l<StaticLibraryName>
.
Compiler prefers dynamic version over static version of library
If you have your dynamic library (random.dylib
) and static library (random.a
) in same directory then compiler will prefer and link with .dylib
not .a
Linking static libraries to other static libraries
Static libraries do not link with other static libraries. The only way to do this is to use your librarian/archiver tool (for example ar on Linux) to create a single new static library by concatenating the multiple libraries.
Edit: In response to your update, the only way I know to select only the symbols that are required is to manually create the library from the subset of the .o files that contain them. This is difficult, time consuming and error prone. I'm not aware of any tools to help do this (not to say they don't exist), but it would make quite an interesting project to produce one.
Where/When to link against the Standard C Library when compiling C programs?
Essentially every hosted C implementation requires you to link programs with an implementation of the standard C library.
Some commands for building programs have the inclusion of the standard C library built-in as a default, so you do not need to add it explicitly on the command library. Some commands do not have it as a default, so you do need to add it on the command line.
Related Topics
Redirecting Cout to a Console in Windows
Finding the Centroid of a Polygon
Convert Float to String with Precision & Number of Decimal Digits Specified
Std::Map Emplace Without Copying Value
How to Find and Replace String
Converting Multidimensional Arrays to Pointers in C++
Is the Memory Allocated for Struct Members Continguous? What If a Struct Member Is an Array
A Warning - Comparison Between Signed and Unsigned Integer Expressions
Qt: Resizing a Qlabel Containing a Qpixmap While Keeping Its Aspect Ratio
Is the Order of Iterating Through Std::Map Known (And Guaranteed by the Standard)
Send and Receive a File in Socket Programming in Linux with C/C++ (Gcc/G++)
Is There Any "Standard" Htonl-Like Function for 64 Bits Integers in C++
How Are Iterators and Pointers Related
How to Get a "Useful" C++ Binary Search Algorithm
How to Convert Std::Chrono::Time_Point to Calendar Datetime String with Fractional Seconds