首页 > 解决方案 > LibPrivoxy:未解析的外部符号 __declspec(dllimport) int __stdcall StartPrivoxy(char *)

问题描述

我正在尝试从那里使用 Qt5 构建中的库:链接

我已将.liband.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 Enterprise开启Windows 10 18363.592

标签: c++cqt5

解决方案


根据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 并将其放在您指定的路径中?(用 C/C++ 编译一个 DLL,然后从另一个程序调用它

据我了解,您想使用 libprivoxy 作为源代码。然后你不需要导入一个不存在的 .dll,因为你没有编译它。

请注意,静态链接和动态链接之间存在差异,据我了解,您希望静态链接(.dll动态链接库的缩写)


推荐阅读