加载dll失败
原创
©著作权归作者所有:来自51CTO博客作者妙为的原创作品,请联系作者获取转载授权,否则将追究法律责任
Qt系列文章目录
文章目录
前言
加载dll失败,使用Dependencies.exe查看,感觉也没有缺失相关dll
在使用Qt中调用别人写的dll,一直加载失败。使用windeployqt.exe命令打包也总是失败
PS E:\osg\work\CARTDLL_demo_20220520\CallCartDll> D:\Qt\Qt5.12.9\5.12.9\msvc2017_64\bin\windeployqt.exe CallCartDll.exe
“CallCartDll.exe” does not exist.
PS E:\osg\work\CARTDLL_demo_20220520\CallCartDll> cd E:\osg\work\CARTDLL_demo_20220520\CallCartDll\debug
PS E:\osg\work\CARTDLL_demo_20220520\CallCartDll\debug> D:\Qt\Qt5.12.9\5.12.9\msvc2017_64\bin\windeployqt.exe CallCartDll.exe
E:\osg\work\CARTDLL_demo_20220520\CallCartDll\debug\CallCartDll.exe 64 bit, debug executable
E:\osg\work\CARTDLL_demo_20220520\CallCartDll\debug\CallCartDll.exe does not seem to be a Qt executable.
PS E:\osg\work\CARTDLL_demo_20220520\CallCartDll\debug>
二、解决办法
1.安装Anaconda3 版本-2021.05-Windows-x86_64
2.设置Anaconda3的环境变量
#include <QCoreApplication>
#include <iostream>
#include "windows.h"
using namespace std;
#pragma comment(lib,"CartDll.lib")
typedef double (*cartfun)(int *itype,int *katmod,int *ikaerosol,int *ikheight,float *iseah,float *ivis,float *irh,
float *wmintemp,float *wmaxtemp,float *avertrans,float *pathradiance, float *totalradiance);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HINSTANCE hlib=LoadLibrary(TEXT("CartDll.dll"));
if(!hlib)
{
cout<<"open dll error!"<<endl;
}
else
{
cout<<"open dll sucess!"<<endl;
}
cartfun cart1=(cartfun)GetProcAddress(hlib,"cart");
if(!cart1)
{
cout<<"load CART FUN add error!"<<endl;
}
else
{
cout<<"load CART FUN add sucess!"<<endl;
}
int iType = 3; //计算模式
int iKatmod = 22; //大气模式
int iKaerosol = 1; //气溶胶类型
int iKheight = 0; //气溶胶高度模式
float fSeah = 0.0; //地表海拔高度
float fVis = 34.0; //能见度
float fRh = 65.0; //相对湿度
float fWmintemp = 400.0; //计算起始波数
float fWmaxtemp = 40000.0; //计算截止波数
float fAvertrans;
float fTotalradiance;
float pathradiance;
cart1(&iType,&iKatmod,&iKaerosol,&iKheight,&fSeah,&fVis,&fRh,&fWmintemp,&fWmaxtemp,&fAvertrans,&pathradiance,&fTotalradiance);
cout<<" fAvertrans = "<<fAvertrans<<endl;
cout<<" fTotalradiance = "<<fTotalradiance<<endl;
cout<<" pathradiance = "<<pathradiance<<endl;
cout << "Hello World!" << endl;
std::system("pause");
return a.exec();
}
总结
原来别人写的dll中有用到python相关依赖包,所以要把Anaconda3的路径配置到环境变量中