keywords: View Content of Static Library(.lib) and Shared Library(.dll)

List all obj files (symbols) from a static library

Windows

GUI

DLL Export Viewer
http://www.nirsoft.net/utils/dll_export_viewer.html

CLI

Open a visual command console (Visual Studio Command Prompt)

dumpbin /ARCHIVEMEMBERS openssl.x86.lib /OUT:dump.log

or

lib /LIST openssl.x86.lib

or just open it with 7-zip :) its an AR archive.

Reference: How to See the Contents of Windows library (*.lib)
https://stackoverflow.com/a/26689684/1645289

Linux

CLI

Command:

nm -C libschnoeck.a | less

Or:

#This will list all of the files in the archive.
ar -t mylib.a

Reference:
Contents of a static library
https://stackoverflow.com/questions/3757108/contents-of-a-static-library/21320738

Extract object (*.o) files from an iPhone static library
https://stackoverflow.com/a/21927224/1645289

Extract all obj files (symbols) from a static library

Windows

This is the batch file that I ended up using with usage extract.bat mylib.lib or extract.bat *.lib even.

@ECHO OFF
call "C:\Program_Filesx86\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"

SETLOCAL EnableDelayedExpansion

:Loop
IF "%1"=="" GOTO Continue

FOR %%F in (%1) DO (

    SET LIBFILE=%%F
    SHIFT

    @ECHO !LIBFILE!

    FOR /F %%O IN ('lib.exe /LIST !LIBFILE! /NOLOGO') DO (
        @SET OBJFILE=%%O
        @ECHO !OBJFILE!
        
        SET OBJPATH=%%~dO%%~pO
        SET OBJNAME=%%~nO

        IF NOT EXIST "!OBJPATH!" md !OBJPATH!

        IF EXIST "!OBJFILE!" ECHO !OBJFILE! exists, skipping...
        IF NOT EXIST "!OBJFILE!" lib.exe /NOLOGO !LIBFILE! "/EXTRACT:!OBJFILE!" "/OUT:!OBJFILE!"
    )
)
GOTO Loop
:Continue

Reference:
https://stackoverflow.com/a/62896582

Linux
$ mkdir object
$ cp libarith.a object/
$ cd object
$ ar x libarith.a
$ ls *.o
addition.o
multiplication.o

Or:

#This will extract the object give myobj.o from the library mylib.a
ar -xv mylib.a myobj.o 

UNIX ar Examples: How To Create, View, Extract, Modify C Archive Files (*.a)
https://www.thegeekstuff.com/2010/08/ar-command-examples/

Create / Combine / Build a new static library from obj files (symbols)

Windows

Create static library:

LIB.EXE /OUT:MYLIB.LIB FILE1.OBJ FILE2.OBJ

Create dynamic library:

LINK.EXE /DLL /OUT:MYLIB.DLL FILE3.OBJ FILE4.OBJ

Create library from all objects:

lib /out:libbgi.lib *.obj

Link from source file:

cl /LD foo.c bar.c baz.c /FeMyImage.dll

Or:

cl /LD foo.c bar.c baz.c /link /out:MyImage.dll

Reference:
https://stackoverflow.com/a/2727294/1645289

https://stackoverflow.com/a/31830252/1645289

Linux
ar -r libsmall.a obj1.o obj2.o obj3.o

or:

ar -rcs libexample.a *.o

Link the library with the switch:

-lexample

Reference:
https://stackoverflow.com/a/53522978/1645289

https://stackoverflow.com/a/33981949

Linking static libraries to other static libraries

Windows
lib.exe /OUT:compositelib.lib  lib1.lib lib2.lib

https://stackoverflow.com/a/2157735/1645289


你不知道的,就伤害不到你。──罗伯特·佩恩·沃伦(Robert Penn Warren)《国王的人马》(All The King's Men)