c++ - 对 wxLog::DoLog 的 undefined reference 针对 wxWidget 3.0 构建 wxHaskell 时出错

标签 c++ haskell wxwidgets vtable wxhaskell

我正在尝试为 wxWidgets 3.0 构建 wxHaskell。我使用了 https://github.com/wxHaskell/wxHaskell 中最新的 git 版本的 wxHaskell .

我尝试遵循wxHaskell-master.zip中的install.txt,到目前为止我所做的是:

cd wxdirect
cabal install
cd ../wxc
cabal install 

wxc 无法编译,因为它的 Setup.hs 需要 wxWidgets 2.9。我更换了

let wxRequiredVersion = "2.9"

let wxRequiredVersion = "3.0"

然后做了:

cabal install --extra-lib-dirs=/usr/local/lib

所有编译都很顺利,但最后我遇到了一些链接错误。最难解决的问题如下:

dist\build\src\cpp\eljlog.o:eljlog.cpp:(.rdata$_ZTV6ELJLog[vtable for ELJLog]+0x20): undefined reference to `wxLog::DoLog(unsigned long, char const*, long)'

对应的源码在wxc/src/cpp/eljlog.cpp中:

class ELJLog : public wxLog
{
    private:
        TLogFunc func;
        void*    EiffelObject;

    protected:
        virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t)
                  {
                    wxString s(szString);
                    func (EiffelObject, (int)level, (void*)&s , (int)t);
                  }
              ....

我无法弄清楚导致此错误的原因以及如何修复它。我对这个 vtable 问题进行了一些搜索,有些人认为这是由于在子类中声明虚拟函数而没有定义它造成的。其他人建议这是在 g++ 命令行上给出目标文件的顺序。但这里的情况似乎并非如此。 我尝试删除函数 ELJLog::DoLog 函数或注释掉 virtual 关键字。奇怪的是,总是有一个链接错误/错误说明有关 ELJLog 的 vtable 的内容,并引用 wxLog::DoLog,即使没有出现 DoLog。

此外,作为旁注,wxWidgets 3.0 文档中似乎缺少 wxLog::DoLog 。我不确定这个功能是否已被弃用。但是,它仍然以我无法理解的方式导致遗留派生类出现错误。

知道这里发生了什么吗?

--- 编辑2 ---

如果我注释掉有问题的函数

virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) ...

我遇到了不同的链接错误,如下所示:

dist\build\src\cpp\eljlog.o:eljlog.cpp:(.rdata$_ZTV6ELJLog[vtable for ELJLog]+0x
20): undefined reference to `wxLog::DoLog(unsigned long, char const*, long)'
dist\build\src\cpp\eljlog.o:eljlog.cpp:(.rdata$_ZTV6ELJLog[vtable for ELJLog]+0x
24): undefined reference to `wxLog::DoLog(unsigned long, wchar_t const*, long)'
collect2: ld returned 1 exit status

--- 编辑 ---

我在 mingw.org 的 mingw32 下完成了这个工作。我从源码构建了wxWidgets 3.0.0稳定版本,我所做的步骤如下:

per http://mingw.5.n7.nabble.com/win32api-version-4-td32288.html :
 edit line 2217 of /c/mingw/{,mingw32/}include/commctrl.h to read
 #define TV_DISPINFO NMTVDISPINFO
 instead of
 #define TV_DISPINFO __AW(NMTVDISPINFO) 
The above was needed to fix a MinGW32 4.8.1-4 issue. Then,

./configure --enable-stl --disable-shared
make
make install

./configure --enable-stl
make
make install 
mv /usr/local/lib/wx*.dll /c/mingw/bin/

最佳答案

这似乎是一个定义

virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
wxLog 的子类ELJLog 中缺少

。添加以下接口(interface)不同的 DoLog 拷贝只能解决问题:

virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
{
    wxString s(szString);
    func (EiffelObject, (int)level, (void*)&s , (int)t);
}

关于c++ - 对 wxLog::DoLog 的 undefined reference 针对 wxWidget 3.0 构建 wxHaskell 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22187103/

相关文章:

haskell - 不变仿函数的例子?

haskell - GHC的非懒惰分支

c++ - 3.1.3 上的 wxWidgets mac 剪贴板坏了?

c++ - wxMiniFrame 总是显示在顶部

wxpython - 需要 wxPython 的帮助(新手)

c++ - 什么时候 abort() 优于 exit()?

c++ - 为什么列表初始化会导致Seg错误?

haskell - 在 Haskell 中创建临时目录

C++ 模板 : no matching function for call

c++ - constexpr std::optional 可能的实现