在 C++ 应用程序中使用 id3lib 库时出现未定义的引用链接器错误 [英] Undefined reference linker error while using id3lib library in a C++ application

查看:33
本文介绍了在 C++ 应用程序中使用 id3lib 库时出现未定义的引用链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是 Windows 7 Ultimate x64.我正在使用 Qt 4.8 编写一个将使用 id3lib 的程序.我已经下载了 windows 二进制文件.以下是显示如何使用 id3lib 库的 *.pro 文件的一部分:

My OS is Windows 7 Ultimate x64. I'm using Qt 4.8 to write a program that will use id3lib. I've downloaded the windows binaries. Here is part of the *.pro file that shows how id3lib library is used:

HEADERS  += MainWindow.h \
    id3lib/id3/sized_types.h \
    id3lib/id3/globals.h \
    id3lib/id3/tag.h \
    id3lib/id3/utils.h \
    id3lib/id3/id3lib_frame.h \
    id3lib/id3/field.h \
    id3lib/id3/id3lib_strings.h \
    id3lib/id3/id3lib_streams.h

win32: LIBS += -L$$PWD/id3lib/ -lid3lib

INCLUDEPATH += $$PWD/id3lib
DEPENDPATH += $$PWD/id3lib

如您所料,库文件(id3lib.dll 和 id3lib.lib)位于 id3lib 目录中,所有必需的头文件都位于 id3lib/id3 目录中.

As you can guess, the library files (id3lib.dll and id3lib.lib) are in id3lib directory and all required headers are in id3lib/id3 directory.

在 globals.h 中,我定义了以下内容:

In the globals.h, I defined the follwing:

#define ID3LIB_LINKOPTION LINKOPTION_CREATE_DYNAMIC

并在同一个文件中修改了以下部分:

And modified the following section in the same file:

#    if (ID3LIB_LINKOPTION == LINKOPTION_CREATE_DYNAMIC)
       //used for creating a dynamic dll
#      define ID3_C_EXPORT extern _declspec(dllexport)
#      define ID3_CPP_EXPORT __declspec(dllexport)
#      define CCONV __stdcall // Added for VB & Delphi Compatibility - By FrogPrince Advised By Lothar
#    endif

如下:

#    if (ID3LIB_LINKOPTION == LINKOPTION_CREATE_DYNAMIC)
       //used for creating a dynamic dll
#      define ID3_C_EXPORT Q_DECL_IMPORT
#      define ID3_CPP_EXPORT Q_DECL_IMPORT
#      define CCONV __stdcall // Added for VB & Delphi Compatibility - By FrogPrince Advised By Lothar
#    endif

以便它与 Qt 一起使用.

so that it works with Qt.

接下来,我包含了 id3/tag.h 并编写了以下代码:

Next, I've included id3/tag.h and written the following code:

ID3_Tag tag("test.wma");
qDebug() << tag.size();

编译后出现如下错误:

undefined reference to `_imp___ZN7ID3_TagC1EPKc'
undefined reference to `_imp___ZNK7ID3_Tag4SizeEv'
undefined reference to `_imp___ZN7ID3_TagD1Ev'
undefined reference to `_imp___ZN7ID3_TagD1Ev'
(several few, same format: `_imp___xxxxx_Tagxxxx')

我知道导致未定义引用的原因,但就我而言,为什么链接器找不到实现?它现在在 id3lib.dll 中吗?有没有人知道是否有任何解决方法?

I know what causes undefined reference, but in my case, why the linker couldn't find the implementation? Is it now there in the id3lib.dll? Does anyone know if there is any workaround?

推荐答案

问题不在于工具链,而在于 ABI.

The problem lies not in tool chains, but ABI.

确实存在标准plain C ABI,因此您可以通过<链接libacode>MinGw,如果它们只包含 plain C 符号.

It does exist standard plain C ABI, so you can link against both lib and a by MinGw, if they contain only plain C symbols.

但在您的情况下并非如此(因为存在诸如 ID3_CPP_EXPORT 之类的定义).

But it is not true in you case (since such define as ID3_CPP_EXPORT exist).

你应该尝试自己制作图书馆.首先,安装 msys,打开 msys shell,进入项目文件夹并尝试

You should try to make library by youserlf. To begin with, install msys, open msys shell, go to project folder and try

./configure && make

这篇关于在 C++ 应用程序中使用 id3lib 库时出现未定义的引用链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆