当前位置: 移动技术网 > 移动技术>移动开发>IOS > VC++生成动态库文件防止名字改编

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

2020年07月17日  | 移动技术网移动技术  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网