MeshLab调试时加载的dll版本不对
从MeshLab
2023.12下载安装的2023.12
版本,我在本地clone了一份源码编译,发现在C:\Users\Administrator\AppData\Roaming\VCG\MeshLab_64bit_fp\MeshLabExtraPlugins\2023.12
位置存放了一套插件的dll文件,也就是这一套dll文件影响了源码的调试,也即调试时加载的这个目录下的dll文件,不是生成路径下的dll文件。
根据调用栈加载dll的路径就是这个路径:
MeshLabApplication::extraPluginsLocation看出,appVer
也出了力。但是核心路径还是来自于QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).first()
。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18const QString MeshLabApplication::extraPluginsLocation()
{
QDir appDir(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).first());
appDir.mkpath(appDir.absolutePath());
appDir.mkdir("MeshLabExtraPlugins");
appDir.cd("MeshLabExtraPlugins");
//QString major = appVer().left(4);
//appDir.mkdir(major);
//appDir.cd(major);
//just for first versions, compatibility of plugins is fixed for same version of meshlab
appDir.mkdir(appVer());
appDir.cd(appVer());
return appDir.absolutePath();
}
可以看一下QStandardPaths::standardLocations
的内容,可以添加上:
1
2
3
4
5
6
7
8
9
10
11
12
QStringList allAppDataLocations =
QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
// QString loc = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
foreach (QString path, allAppDataLocations) {
qInfo() << path;
}
auto s = appDir.absolutePath();
LPWSTR path;
SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_VERIFY, 0, &path);
QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)是个啥
QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)
返回的是QStringList
类型,本地测试如下,有5个路径,extraPluginsLocation
用的就是第一个路径。

路径来源
deepseek了解了一下,setOrganizationName
和setApplicationName
会影响到这个路径,细节就没有了,也没有chat到为啥多个路径。setOrganizationName
和setApplicationName
在meshlab/main.cpp中都调用到了。
1
2
3
4QCoreApplication::setOrganizationName(MeshLabApplication::organization());
QString tmp = MeshLabApplication::appArchitecturalName(MeshLabApplication::HW_ARCHITECTURE(QSysInfo::WordSize));
QCoreApplication::setApplicationName(MeshLabApplication::appArchitecturalName(MeshLabApplication::HW_ARCHITECTURE(QSysInfo::WordSize)));
具体原因只能看具体实现了,源码面前,了无秘密。来看一看QStandardPaths::standardLocations
的定义,在qstandardpaths_win.cpp中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36QStringList QStandardPaths::standardLocations(StandardLocation type)
{
QStringList dirs;
const QString localDir = writableLocation(type);
if (!localDir.isEmpty())
dirs.append(localDir);
// type-specific handling goes here
if (isConfigLocation(type)) {
QString programData = sHGetKnownFolderPath(FOLDERID_ProgramData);
if (!programData.isEmpty()) {
if (!isGenericConfigLocation(type))
appendOrganizationAndApp(programData);
dirs.append(programData);
}
// Note: QCoreApplication::applicationDirPath(), while static, requires
// an application instance. But we might need to resolve the standard
// locations earlier than that, so we fall back to qAppFileName().
QString applicationDirPath = qApp ? QCoreApplication::applicationDirPath()
: QFileInfo(qAppFileName()).path();
dirs.append(applicationDirPath);
const QString dataDir = applicationDirPath + "/data"_L1;
dirs.append(dataDir);
if (!isGenericConfigLocation(type)) {
QString appDataDir = dataDir;
appendOrganizationAndApp(appDataDir);
if (appDataDir != dataDir)
dirs.append(appDataDir);
}
} // isConfigLocation()
return dirs;
}
可以看到,QStandardPaths::standardLocations
正好有5个append
操作,正对着QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)
返回的5条路径,其中第一条来自于writableLocation
设置,并附加了appendOrganizationAndApp
名称。递归一下,writableLocation
的实现基本如下:
1 |
|
path结果,不出所料,正是:
调试方法
如果修改的dll恰巧也在C:\Users\Administrator\AppData\Roaming\VCG\MeshLab_64bit_fp\MeshLabExtraPlugins\2023.12
目录下,把生成结果copy到该目录下,就可以正常调试了。