c++ - LibPrivoxy : unresolved external symbol __declspec(dllimport) int __stdcall StartPrivoxy(char *)

标签 c++ c qt5

我正在尝试从那里使用 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.0Visual Studio 2017 EnterpriseWindows 10 18363.592

最佳答案

根据https://doc.qt.io/qtcreator/creator-project-qmake-libraries.htmlhttps://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/

相关文章:

c++ - 作为 char* 传递后获取数组的长度

没有调用 C++ 函数

c - 需要帮助删除 C 中的空字符

c++ - MySQL C++ 连接器是否比 MySQL C API 慢?

linux - 可执行文件不是用 Qt 制作的

qml - Qt Quick 2 场景图是否同步到 EGLFS 上的垂直同步?

c++ - RAII 和虚拟析构函数

c++ - 用Visual Studio 11编译出来的可执行文件有什么特别之处导致无法在Windows XP上执行?

c - 解释C代码指令

c++ - Qt5 中 QX11EmbedWidget 的对应物是什么?