dll_02.h:
#ifndef DLL_02_H
# define DLL_02_H
#ifndef BUILD_DLL
# define DLLIMPORT __declspec (dllexport)
#else
# define DLLIMPORT __declspec (dllimport)
#endif //BUILD_DLL
#ifdef __cplusplus
extern "C"{
#endif //__cplusplus
DLLIMPORT void hello();
DLLIMPORT int addxy(int,int);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif // DLL_02_H
dll_02.cpp:
#include <stdio.h>
#include "dll_02.h"
#define BUILD_DLL 0x01
DLLIMPORT int addxy(int x,int y)
{
return x+y;
}
DLLIMPORT void hello()
{
printf("hello world.");
}
Makefile:
dllFiles=dll_02.h dll_02.cpp
build:
g++ --share -x c++ -o dll_02.dll $(dllFiles)
clean:
del dll_02.dll
编译:
make build