Can you statically link a specific library using visual-c++ on the command line?

491 views Asked by At

To be more specific, I'm using visual-c++ in a MingW environment. I've got a makefile that is defining LDFLAGS as such:

LDFLAGS="-MACHINE:X64 -OPT:REF,ICF -FORCE libtcmalloc_minimal.lib -INCLUDE:__tcmalloc"

If I build my program this way, I'm required to distribute libtcmalloc_minimal.dll along with the program.

I'm assuming if this was GCC or the likes I'd use -static but that flag isn't recognized by visual-c++. Is there a way to force this lib to be implemented statically?

1

There are 1 answers

2
Rudolfs Bundulis On BEST ANSWER

The issue here is that a .lib can be either a static library or a import library for a DLL. In the first case it is linked in the binary the same way an .a file would be on Linux, resolving the addresses, removing unneeded code etc. In the second case the .lib file works as a stub for a DLL and cannot function without it. You need yo acquire the correct version (if it exists) for your library and then link with that, you cannot make an import library behave like a static library.