C++ - 为交叉编译的 Windows 可执行文件链接到 glog 失败

我正在尝试将我的代码编译为 dll 格式(而不是 .so 格式),并且我正在使用 MinGW 编译器(从 mxe 编译)的 Ubuntu 机器上执行此操作。

代码使用谷歌的glog库进行日志记录,并通过Makefile编译(不使用cmake)。该代码在 Linux 上编译得很好,但是当我将 Makefile 中使用的 g++ 切换到从 mxe 编译的 i686-w64-mingw32.static-g++ 时,链接器显示了许多错误,例如 -

undefined reference to `google::LogMessage::LogMessage(char const*,int,int)'
undefined reference to `google::LogMessage::stream()'
undefined reference to `google::LogMessage::~LogMessage()'

为了发布这个问题,我在一个小的(非 dll)可执行文件上重新创建了这个问题 -

#define GOOGLE_GLOG_DLL_Decl
#include "glog/logging.h"

int main() {
    LOG(ERROR) << "HELLO";
    return 0;
}

带有以下编译行 -

i686-w64-mingw32.static-g++ -L/path/to/library/directory -I/path/to/include/dir \
    -static-libstdc++ simple_main.cpp -lglog -o simple_main.exe

我将 glog 包含文件放在 include 目录中,将 libglog.a 放在 -L 给出的目录中。这样做时,我遇到了与真实图书馆相同的错误 -

/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x69): undefined reference to `google::LogMessage::LogMessage(char const*,int)'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x7d): undefined reference to `google::LogMessage::stream()'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x9e): undefined reference to `google::LogMessage::~LogMessage()'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0xc2): undefined reference to `google::LogMessage::~LogMessage()'
collect2: error: ld returned 1 exit status

值得一提的是,我的问题与 this 问题非常相似,我尝试在我的简单主程序上使用 CMake 来重现该问题,但是那里提供的答案对我不起作用(仍然得到同样的错误)。

我还确保 libglog.a 文件确实包含未定义的符号(通过 nm libglog.a | c++filt | grep ~LogMessage),并且我还尝试链接到我在 Windows 上编译的 Windows 构建的 glog.lib,这似乎也不起作用(链接器无法识别 .lib 文件)。

因此,我不确定是什么问题,希望得到帮助。

lcq3822987 回答:C++ - 为交叉编译的 Windows 可执行文件链接到 glog 失败

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1831.html

大家都在问