c++ - LibPrivoxy:未解析的外部符号 __declspec(dllimport) int __stdcall StartPrivoxy(char *)
问题描述
我正在尝试从那里使用 Qt5 构建中的库:链接
我已将.lib
and.h
文件添加到我的 qmake 文件中,如下所示:
INCLUDEPATH += C:\xxxxxx\Privoxy\include
LIBS += -LC:\xxxxxx\Privoxy\lib -lLibPrivoxy
并尝试在我的文件中调用StartPrivoxy
函数:.cpp
#include <QCoreApplication>
#include "WinPrivoxy/libprivoxy.h"
QString file = QCoreApplication::applicationDirPath() + "/privoxy.conf";
StartPrivoxy(file.toLocal8Bit().data());
当我点击编译时,编译器给了我这个错误:
error LNK2019: unresolved external symbol "__declspec(dllimport) int __stdcall StartPrivoxy(char *)" (__imp_?StartPrivoxy@@YGHPAD@Z)
该.lib
文件的.h
和.c
文件是:
// libprivoxy.h
#ifndef _LIBPRIVOXY_EXPORT_H
#define _LIBPRIVOXY_EXPORT_H
#ifdef LIBPRIVOXY_EXPORTS
#define LIBPRIVOXY_API __declspec(dllexport)
#else
#define LIBPRIVOXY_API __declspec(dllimport)
#endif
LIBPRIVOXY_API int __stdcall StartPrivoxy(char *config_full_path);
LIBPRIVOXY_API void __stdcall StopPrivoxy();
LIBPRIVOXY_API int __stdcall IsRunning();
#endif
// libprivoxy.c
#include "libprivoxy.h"
#include "miscutil.h"
#include <assert.h>
char g_privoxy_config_full_path[1024] = { 0 };
extern HMODULE g_hLibPrivoxyModule = NULL;
extern int g_terminate;
extern void close_privoxy_listening_socket();
LIBPRIVOXY_API int __stdcall StartPrivoxy(char *config_full_path)
{
g_terminate = 0;
strcpy_s(g_privoxy_config_full_path, 1024, config_full_path);
// start privoxy
WinMain( NULL,NULL,NULL, 0);
return 0;
}
LIBPRIVOXY_API void __stdcall StopPrivoxy()
{
g_terminate = 1;
close_privoxy_listening_socket();
}
LIBPRIVOXY_API int __stdcall IsRunning()
{
return 1 == g_terminate ? 0 : 1;
}
我正在使用Qt 14.0.0
并Visual Studio 2017 Enterprise
开启Windows 10 18363.592
解决方案
根据https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html和https://doc.qt.io/qt-5/third-party-libraries.html您的 qmake 设置是准确的(也许添加DEPENDPATH += ...
)。
问题似乎是.dll
导入,因为通常当链接的 dll 出现问题时会引发此外部符号未解析错误( https://social.msdn.microsoft.com/Forums/vstudio/en-US/d94f6af3-e330-4962- a150-078da57ee5d0/error-lnk2019-unresolved-external-symbol-quotdeclspecdllimport-public-thiscall?forum=vcgeneral )
通过 privoxy git 搜索时,我找不到.dll
. 您是否为 privoxy 编译了一个 .dll 并将其放在您指定的路径中?(用 C/C++ 编译一个 DLL,然后从另一个程序调用它)
据我了解,您想使用 libprivoxy 作为源代码。然后你不需要导入一个不存在的 .dll,因为你没有编译它。
请注意,静态链接和动态链接之间存在差异,据我了解,您希望静态链接(.dll
是动态链接库的缩写)
推荐阅读
- javascript - 我无法理解一件事
- python - 如何使用驱动程序对象将python selenium中的所有页面
- tensorflow - 如何使用嵌入式 tensorflow 方法来组合多个特征列操作和窗口化,以用于 RNN?
- gitlab - GitLab 是否显示以 base64 给出的图像?
- android - Android 自动备份 - 如何知道上次备份的时间?
- c++ - 指针数组,在 C++ 中删除并分配给它的指针
- apache-spark - Databricks REST API 节流和容量限制/限制
- javascript - 在一个组件中反应清除 LocalStorage 和 Asyncstorage
- elasticsearch - Elasticsearch 索引中嵌套字段的 Cube.js 架构
- python - 在python中增量加载大数据