我正在尝试从那里使用 Qt5 构建中的库:Link
我添加了 .lib
和 .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 并将其放在您指定的路径中? (Compile a DLL in C/C++, then call it from another program)
据我了解,您想使用 libprivoxy 作为源代码。然后你不需要导入一个不存在的.dll,因为你没有编译它。
请注意,静态链接和动态链接之间存在差异,据我了解,您希望静态链接(.dll
是动态链接库的缩写)
关于c++ - LibPrivoxy : unresolved external symbol __declspec(dllimport) int __stdcall StartPrivoxy(char *),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60135307/