编译错误:在C ++中包含ODBC头MinGW-w64

时间:2016-08-07 07:57:16

标签: c++ odbc cross-compiling mingw-w64

我正在尝试交叉编译我使用MinGW-w64交叉编译器和CMake在Arch for Linux上编写的c ++程序。该程序使用g ++ for linux进行编译。使用MinGW-w64(x86_64-w64-mingw32)我收到很多编译错误。

问题在于包含sqlext.h或sql.h头文件。这是device.h头文件,其中包含ODBC头:

#ifndef DEVICE_H
#define DEVICE_H

#include "setup.h"

#if defined(_WIN32)
    #include <windows.h>
#endif
#include <string>
#include <vector>
#include <ctime>
#include <sqlext.h>

// file attributes
struct file_t {
    int id;                 // current file number, one
    std::string name;       // file name
    std::string ext;        // file extension
    std::string device;     // device type
    std::string plot;       // plot type
    size_t size;            // file size
    time_t secs;            // sec since epoch
    std::string date;       // local time string
    std::string comment;    // comment in file header
    size_t recs;            // data records per file
    double testTime;        // test time in secs
};

// data record
struct rec_t {
    int fileId;             // file ID
    size_t dataPoint;       // zero based data point
    int halfCycle;          // zero based half cycle index
    int fullCycle;          // zero based full cycle index
    int stepIndex;          // step index, 0: rest, 1: charge, -1 discharge
    double testTime;        // test time
    double stepTime;        // step time
    std::string localTime;  // local time string
    time_t secSinceEpoch;   // data point, sec since epoch
    double current;         // current
    double voltage;         // potential of working electrode
    double voltage2;        // potential of counter electrode
    double capacity;        // capacity
    double energy;          // energy
    double dQdV;            // dQdV
    double auxiliary;       // auxiliary channel, e.g. temperature

    // overload less functor for sort
    bool operator < (const rec_t& a) const {
        return dataPoint < a.dataPoint;
    }
};

// half cycles
struct half_t {
    int halfCycle;          // zero based half cycle index
    size_t begin;           // data point, zero based cycle start
    size_t end;             // data point, zero based cycle end
    double stepTime;        // step time
    double capacity;        // capacity
    double energy;          // energy
    double averageVoltage;  // average voltage
};

// full cycles
struct full_t {
    int fullCycle;              // zero based full cycle index
    size_t begin;               // zero based cycle start
    size_t end;                 // zero based cycle end
    double chargeTime;          // charge time
    double dischargeTime;       // discharge time
    double chargeCapacity;      // charge capacity
    double dischargeCapacity;   // discharge capacity
    double chargeEnergy;        // charge energy
    double dischargeEnergy;     // discharge energy
    double chargeVoltage;       // average charge voltage
    double dischargeVoltage;    // average discharge voltage 
    double hysteresis;          // voltage hysteresis
    double efficiency;          // coulombic efficiency
};

struct col_t {
    int index;
    std::string name;
};

// instrument classes
class Device : public Setup
{
    private:
        std::ifstream* reader;
        file_t* file;
        std::vector<col_t> columns;

        // read
        void readDataFiles();
        void readDataPoints();

        // calculations
        void calculateCycles();

        // print on screen
        void printFileDetails();
        void printDataPoints();
        void printHalfCycles();
        void printCalcRecords();
        void printFullCycles();

        // methods for Gamry
        void gamryParseFileType();
        void gamryParseStartTime();
        void gamryReadColumns();

        // methods for Arbin
        void showError(SQLSMALLINT, const SQLHANDLE&);
        void arbinReadDataPoints();

        // methods for Biologic
        void biologicParseFileType();
        void biologicParseStartTime();
        void biologicReadColumns();
        void biologicConvertCurrent();
        void biologicReadMprFile();

        // methods for Ivium
        void iviumParseFileType();
        void iviumParseStartTime();
        void iviumReadDataPoints();

        // methods for Zahner
        void zahnerParseFileType();
        void zahnerParseStartTime();
        void zahnerReadColumns();

    protected:
        std::vector<file_t> details;
        std::vector<rec_t> recs;
        std::vector<half_t> halfCycles;
        std::vector<full_t> fullCycles;

    public:
        Device(int, char**);
        ~Device();

        // get methods
        const std::vector<file_t>& getFileDetails() const;
        const std::vector<rec_t>& getDataPoints() const;
        const std::vector<half_t>& getHalfCycles() const;
        const std::vector<full_t>& getFullCycles() const;
};

#endif // DEVICE_H

和sql.h头文件:

#ifndef SQL_H
#define SQL_H

#include "device.h"
#include <sqlite3.h>

class Sql : public Device
{
    private:
        sqlite3* db;
        sqlite3_stmt* stmt = NULL;
        const char* tail = NULL;
        char* errMsg = NULL;
        std::string sqlQuery;

        // sql manager methods
        void execQuery(std::string);
        void execPrepare(std::string);

        // save tables
        void writeGlobalTable();
        void writeFileTable();
        void writeNormalTable();
        void writeHalfCycleTable();
        void writeFullCycleTable();

        // read tables
        void readGlobalTable();
        void readFileTable();
        void readNormalTable();
        void readHalfCycleTable();
        void readFullCycleTable();

    public:
        Sql(int, char**);
        ~Sql();

        // public methods
        void readSqlite();
        void writeSqlite();
};

#endif // SQL_H

和arbin.cpp实现:

#include "main.h"
#include "device.h"
#include "math.h"

#include <iostream>
#include <algorithm>
using namespace std;

// error handler for odbc sql queries
void Device::showError(SQLSMALLINT handleType, const SQLHANDLE& handle)
{
    SQLCHAR sqlState[1024];
    SQLCHAR messageText[1024];
    SQLRETURN retCode;
    SQLINTEGER i = 0;
    SQLSMALLINT len;
    SQLINTEGER native;
    do {
        retCode = SQLGetDiagRec(handleType, handle, ++i, sqlState, &native, messageText, 1024, &len);
        if (SQL_SUCCEEDED(retCode)) {
            cout << "Message " << i << ": " << messageText << endl <<
                    "SQLSTATE: " << sqlState <<
                    "; Native: " << native << endl;
        }
    } while (retCode == SQL_SUCCESS);
}

......

以下是编译错误:

[  8%] Building CXX object CMakeFiles/convpot.dir/src/arbin.cpp.obj
In file included from /usr/x86_64-w64-mingw32/include/sqlext.h:9:0,
                 from /home/alex/git/plotpot/convpot/include/device.h:14,
                 from /home/alex/git/plotpot/convpot/src/arbin.cpp:2:
/home/alex/git/plotpot/convpot/include/sql.h:8:1: error: expected class-name before ‘{’ token
 {
 ^
In file included from /home/alex/git/plotpot/convpot/include/device.h:14:0,
                 from /home/alex/git/plotpot/convpot/src/arbin.cpp:2:
/usr/x86_64-w64-mingw32/include/sqlext.h:1366:3: error: ‘SQLRETURN’ does not name a type
   SQLRETURN SQL_API SQLDriverConnect(SQLHDBC hdbc,SQLHWND hwnd,SQLCHAR *szConnStrIn,SQLSMALLINT cbConnStrIn,SQLCHAR *szConnStrOut,SQLSMALLINT cbConnStrOutMax,SQLSMALLINT *pcbConnStrOut,SQLUSMALLINT fDriverCompletion);
   ^~~~~~~~~
In file included from /home/alex/git/plotpot/convpot/include/device.h:14:0,
                 from /home/alex/git/plotpot/convpot/src/arbin.cpp:2:
/usr/x86_64-w64-mingw32/include/sqlext.h:1423:3: error: ‘SQLRETURN’ does not name a type
   SQLRETURN SQL_API SQLBrowseConnect(SQLHDBC hdbc,SQLCHAR *szConnStrIn,SQLSMALLINT cbConnStrIn,SQLCHAR *szConnStrOut,SQLSMALLINT cbConnStrOutMax,SQLSMALLINT *pcbConnStrOut);
   ^~~~~~~~~
.........

.........
make[2]: *** [CMakeFiles/convpot.dir/build.make:64: CMakeFiles/convpot.dir/src/arbin.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/convpot.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

我不明白错误&#34;在'{'令牌&#34;之前预期的类名。 c ++继承似乎没什么问题,因为代码用g ++编译得很好。无法找到&#34; SQLRETURN类型的定义&#34;,这似乎没有正确包含sql头。我尝试了sql.h,sqlext.h和sqltypes.h的变种,但没有成功。

有什么想法吗?

0 个答案:

没有答案