I am trying to use an external library in my Qt Creator project. I am building it with Visual C++ on Windows.
I added this to my qmake file:
# Include libspotify
INCLUDEPATH += C:\\libspotify\\include
LIBS += -LC:\\libspotify\\lib -llibspotify
Then I went to use some typedef’d structs from the library:
#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
Now in the IDE editor, the syntax highlight marks sp_session_config and sp_session in purple indicating the editor can find those typedefs fine (if it doesn’t find a definition it leaves the text black).
But when I build I get this:
mainwindow.h:32: error: C2079: 'MainWindow::spSession' uses undefined struct 'sp_session'
Now I know the compiler is finding the api.h file, because if I change it to a bogus filename it spits out a file not found error.
What am I doing wrong?
EDIT:
The header file defines the struct like this:
extern "C" {
typedef struct sp_session sp_session; ///< Representation of a session
}
You have a declaration for a typedef to
struct sp_sessionbutstruct sp_sessionis an incomplete type. In order for theQMainWindowclass to have asp_sessionmember, the type must be complete (ie., you need a declaration that also defines what membersstruct sp_sessionhas).If that’s not possible, you might be able to restructure things so that
class QMainWindowhas ansp_struct*orsp_struct&as a member instead.