I’m trying to include a custom library in MASM32. The library in question is stb_vorbis, it’s written in a single .c file and I compile it using the following:
gcc -c stb_vorbis.c -o stb_vorbis.obj
ar rcs stb_vorbis.lib stb_vorbis.o
g++ -shared -o stb_vorbis.dll stb_vorbis.o -W
I include it in MASM32 using the following:
include stb_vorbis.inc
includelib stb_vorbis.lib
Where stb_vorbis.inc is only one line (testing purposes):
stb_vorbis_decode_filename PROTO STDCALL :DWORD,:DWORD,:DWORD,:DWORD
The makeit.bat for the project looks like this:
ml /c /coff /I "E:masm32" project.asm
rc res.rc
link /subsystem:CONSOLE project.obj res.res /libpath:"E:masm32lib" /entry:start /out:project.exe
, compiles and runs fine if stb_vorbis_decode_filename
isn’t referenced.
When trying to invoke stb_vorbis_decode_filename
, the Microsoft Incremental Linker spits out errors:
project.obj : error LNK2001: unresolved external symbol _stb_vorbis_decode_filename@16
project.exe : fatal error LNK1120: 1 unresolved externals
If I use _stb_vorbis_decode_filename
in both .inc and project files instead, the linker will just complain about __stb_vorbis_decode_filename
being unresolved.
Note: I tried making .def and .lib files with Erol’s tools (def2lib, dll2inc), but they resulted in the same outcome. The .def file contained definitions in the following convention (attempted both with and without underscore):
LIBRARY stb_vorbis
EXPORTS
"_stb_vorbis_close"
"_stb_vorbis_decode_filename"
(...)
Whatever dll2inc spits out (argumentless PROTO SYSCALL
) isn’t usable either. And I can’t use dynamic DLL loading, because the lib loader API (LoadLibrary) isn’t supported by the target platform.
2