欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

VC++生成动态库文件防止名字改编

程序员文章站 2022-07-01 16:15:24
testdll.cpp文件#include #include using namespace std;extern "C" __declspec(dllexport) void testfunc(){string s1 = "test string";cout << s1 << endl;}这样在命令行下通过下面的命令dumpbin /exports testdll.dll就可以看到导出的函数了...

testdll.h文件

#ifndef TESTDLL_H
#define TESTDLL_H

#ifdef DLL_EXPORT
#define TEST_API extern "C" __declspec(dllexport)
#else
#define TEST_API extern "C" __declspec(dllimport)
#endif

TEST_API void testfunc();

#endif

testdll.cpp文件

#define DLL_EXPORT
#include "testdll.h"
#include <iostream>
#include <string>
using namespace std;

void testfunc()
{
	string s1 = "test string";
	cout << s1 << endl;
}

这样在命令行下通过下面的命令
dumpbin /exports testdll.dll
就可以看到导出的函数了。
上面的__declspec(dllexport)用于生成lib文件,extern "C"是防止C++编译器名字改编。
注意.c文件中不能使用extern “C”

本文地址:https://blog.csdn.net/csdn_gddf102384398/article/details/107375775

相关标签: VC++