I have a function bar() that I don't actually call, that calls unimplemented foo():
void foo();
void bar()
{
foo();
}
int main()
{
}
If I package each function in a separate section/COMDAT and ask the linker to remove unused sections/COMDAT, I can get gcc to compile the program
gcc -ffunction-sections -Xlinker --gc-sections LinkerFunctions.cpp
but the equivalent in Visual C++ 2019
cl /Gy LinkerFunctions.cpp /link /OPT:REF
barks that
error LNK2019: unresolved external symbol "void __cdecl foo(void)" (?foo@@YAXXZ) referenced in function "void __cdecl bar(void)" (?bar@@YAXXZ)
How can I get msvc to compile the program?