为什么Qt Creator找到typedef,而不是构建过程

Why does Qt Creator find the typedef, but not the build process?

本文关键字:构建 过程 Qt Creator 找到 typedef 为什么      更新时间:2023-10-16

我正在尝试在我的Qt Creator项目中使用外部库。我正在使用Windows上的Visual C++构建它。

我把它添加到我的qmake文件中:

# Include libspotify
INCLUDEPATH += C:\libspotify\include
LIBS     += -LC:\libspotify\lib -llibspotify

然后我去使用库中的一些 typedef'd 结构:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <libspotify/api.h>
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private:
    Ui::MainWindow *ui;
    sp_session_config spConfig;
    sp_session spSession;
};
#endif // MAINWINDOW_H

现在,在 IDE 编辑器中,语法突出显示将 sp_session_config 和 sp_session 标记为紫色,表示编辑器可以找到这些 typedef(如果找不到定义,则会将文本保留为黑色)。

但是当我构建时,我得到这个:

mainwindow.h:32: error: C2079: 'MainWindow::spSession' uses undefined struct 'sp_session'

现在我知道编译器正在查找 api.h 文件,因为如果我将其更改为虚假文件名,它会吐出一个找不到文件的错误。

我做错了什么?

编辑:头文件定义结构如下:

extern "C" {
typedef struct sp_session sp_session; ///< Representation of a session
}

您有一个要struct sp_session的 typedef 声明struct sp_session但它是一个不完整的类型。 为了使QMainWindow类具有sp_session成员,类型必须是完整的(即,您需要一个声明,该声明还定义了struct sp_session具有的成员)。

如果无法做到这一点,您可以重组内容,以便class QMainWindow拥有sp_struct*sp_struct&作为成员。

原来

我其实是想sp_session * spSession