首先,工程要是win32项目,生成dll
其次,要在函数的h文件前面增加一些内容
然后,定义def文件,其中myDLL就是你以后要调用时刻,dll文件的名字(可以没有)
然后点击重新生成,得到lib和dll,之后的调用方法和之前的一样,主要包括三块,lib, dll, 以及头文件。
问题描述:
1、vs生成dll时,无法解析的外部符号
需要确保.cpp文件和.h文件相互关联
2、extern “C”,对于原始文件是Cpp时候,才会有效。
3、预编译头的问题,在C和C++文件都有的时候,容易出现。你可以把工程和文件都选成不使用预编译头。
参考传送门
4、对于接口,只选你需要的文件,生成一个接口。你可以新建一个interface.cpp和interface.h文件。为了不调用多个头文件,产生问题,你最好把其余头文件放入cpp中。
.h文件
#pragma once
#include <map>
#include <vector>
using namespace std;
#ifdef __cplusplus
extern "C"
{
#endif
_declspec(dllexport) void Extract_and_Get_result_by_svm_for_one_wavfile(char *file_name, double timeStep, map<double, vector<double>>& result);
#ifdef __cplusplus
}
#endif
.cpp文件
#include "speech_interface.h"
#include "SPTK.h"
#include "FeatureExtractor.h"
#include "directory.h"
//for randomForest
#include"RandomForest.h"
#include"MnistPreProcess.h"
函数具体实现。