Currently using Microsoft Visual Studio Community 2019 Version 16.4.4 and compiling a C project.
I want to be able to output assembly from VS, make modifications to the assembly, and then compile the modified assembly into an executable file. Below I talk about my attempts following instructions from a previous SO question, but if there is an alternative (even not using VS) I would appreciate those suggestions.
As a test, I have been using a simple "hello world" program:
#include <stdio.h>
int main(int argc, char* argv) {
printf("Hello world\n");
return 0;
}
I have tried compiling this program following the instructions given by this answer but I get the following errors:
LNK2005 ___local_stdio_printf_options already defined in helloworld.obj
LNK1169 one or more multiply defined symbols found
It looks like VS is actually compiling the assembly to object files, but the linker says that the "___local_stdio_printf_options" symbol is already defined at link-time. When I look back at the assembly code output from VS, this seems to be true:
___local_stdio_printf_options PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_stdio_config.h
; Line 86
push ebp
mov ebp, esp
; Line 88
mov eax, OFFSET ?_OptionsStorage@?1??__local_stdio_printf_options@@9@9 ; `__local_stdio_printf_options'::`2'::_OptionsStorage
; Line 89
pop ebp
ret 0
___local_stdio_printf_options ENDP
So it looks like the a solution for this may be to prevent the VS compiler from defining ___local_stdio_printf_options or change the linker setting to accept this style of coding somehow. I don't know why VS would produce code that defines external symbols like this. I would really appreciate any help.