-5

I tried building an add function as a library with Microsoft's cl.exe, but none of the functions are able to be accessed externally. I also tried adding the Extern "C" in the header with this from another post:

#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif

EXTERNC int add(int a, int b);

Build script:

cl /LD add.c

Built binary in Dependency Walker

Shrimp33
  • 1
  • 2

1 Answers1

1

To export a function you need to use __declspec(dllexport) or a .def file.

__declspec(dllexport) int add(int a, int b) { return a + b; }
Anders
  • 97,548
  • 12
  • 110
  • 164