Skip to content

Instantly share code, notes, and snippets.

@SolomonSklash
Created September 25, 2020 23:57
Show Gist options
  • Select an option

  • Save SolomonSklash/fc02b48a7a70ecb1508977a8e41d43e5 to your computer and use it in GitHub Desktop.

Select an option

Save SolomonSklash/fc02b48a7a70ecb1508977a8e41d43e5 to your computer and use it in GitHub Desktop.
Creating msvcrt.lib
# On Windows, within a VS developer prompt
# Dump the exports of msvcrt.dll
dumpbin.exe /exports C:\Windows\System32\msvcrt.dll > msvcrt.txt
# Copy msvcrt.txt to a Linux box
# Convert the file to Unix line endings
dos2unix msvcrt.txt
# Remove the header from dumpbin
sed -i '1,19d' msvcrt.txt
# Create msvcrt.def file and add the required "EXPORTS" line to the beginning
echo "EXPORTS" > msvcrt.def
# Get the list of functions and remove everything else, redirecting it to the .def file
awk '{print $4}' msvcrt.txt | sed '/^[[:space:]]*$/d' >> msvcrt.def
# Copy back to Windows in a developer prompt
# Create a .lib file from the .def file
lib.exe /def:msvcrt.def /out:msvcrt.lib /machine:x64
@nooriro
Copy link

nooriro commented Oct 6, 2025

Without sed and/or awk, it can be done using a Windows batch file.

Save the following as "exports.cmd" (with CRLF line endings & "OEM code page" encoding.)

@setlocal enabledelayedexpansion
@echo EXPORTS
@for /f "usebackq skip=19 delims=" %%L in ("%~1") do @(
    set "LINE=%%L"
    for /f %%a in ("!LINE:~26!") do @echo %%a
)

Then, in a Visual Studio Developer Command Prompt, run the following commands:

dumpbin /exports C:\Windows\System32\msvcrt.dll > msvcrt.txt
exports msvcrt.txt > msvcrt.def
lib /def:msvcrt.def /out:msvcrt.lib /machine:x64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment