2 ms·
Thanks for the detail! I did manage to see different values for &printf with DLLs on Windows. I was inspired by a long-ago port of a codebase to a newer Visual
by andrewf 5y ago
Thanks for the detail! I did manage to see different values for &printf with DLLs on Windows. I was inspired by a long-ago port of a codebase to a newer Visual C++; the third-party binary DLLs kept importing the old C runtime and using its malloc/free, which complicated things.
I put a __declspec(dllexport) on everything in my header file then (abridged):
C:\Users\andrew\Desktop\winlink>cl /LD first.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
/out:first.dll
/dll
/implib:first.lib
first.obj
Creating library first.lib and object first.exp
C:\Users\andrew\Desktop\winlink>cl /LD second.c
C:\Users\andrew\Desktop\winlink>cl third.c first.lib second.lib
C:\Users\andrew\Desktop\winlink>third.exe
00007FFE38411080 00007FFE38411080 00007FFE382F1080 00007FFE382F1080
hello world 1
hello world 2
If I statically link the three modules together on Windows, then I don't see the different pointers.