The reasoning in your comment chain with Yu Hao is completely correct.
You need to import libmsvcr120.a
with -lmsvcr120
to get the atexit
symbol.
You may also need some of these, depending on what symbols you reference, but this is speculation based on very briefly grepping through the source code in clang/lib/Driver/ToolChains
for the string OPT_nostdlib
:
lgcc_eh
lgcc_s
lgcc
lgomp
liomp5md
lmingw32
lmingwex
lmingwthrd
lmoldname
lmsvcr100
lmsvcr110
lmsvcr80
lmsvcr90
lmsvcrt-os
lomp
lssp_nonshared
lssp
In general, you can find which libraries contain the symbols you're looking for by calling MinGW's nm.exe
(or GNU nm
on Linux) on all of the libraries you have (in x86_64-w64-mingw32\lib
for example), and piping the output to a text file. You'll get a few hundred thousand lines of text like this that you can search through:
libmsvcr120_defs01591.o:
0000000000000000 b .bss
0000000000000000 d .data
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_atexit
U _head_lib64_libmsvcr120_def_a
0000000000000000 T atexit
The T atexit
(uppercase T
) denotes the symbol being exported, with its definition in the .text
section.
If you see U atexit
, that means "I don't know where atexit
is, but it's needed here". If an import library only contains lines with U atexit
, then the definition is not in that import library.
You'll notice atexit
also defined by libmsvcr120d.a
, which is the debug version of libmsvcr120.a
, and defined by libmsvcr120_app.a
, which is (from what I gather) the version you would link against when distributing an executable on the Windows App Store.