交叉编译器 raspberry pi 不完整类型,而本机编译器工作

cross compiler raspberry pi incomplete type while native compiler works

我已经为我的 raspberry pi 设置了一个交叉编译器,我在这里找到的那​​个:Installing Raspberry Pi Cross-Compiler

现在一切正常,直到我想使用 I2c 库 (i2c-dev.h)。

使用arm-linux-gnueabihf-g++编译器编译以下代码时出现错误:

In file included from src/I2c.cpp:8:0:
src/../Include/I2c.h:29:18: error: field ‘message’ has incomplete type
   struct i2c_msg message;
                  ^

同时,当我在 raspi 上编译代码时,它只是运行。

#ifndef I2C_H_
#define I2C_H_

#include <linux/i2c-dev.h> // Defines i2c_msg
#include ...

using namespace std;


typedef struct {
    struct i2c_msg message;

    void (*callback)(int);
    int messageID;

} t_msgQueue;

关于可能的原因的任何想法,或者关于如何使交叉编译器正常工作的解决方案?

我的第一个怀疑是 RPi 和交叉编译器之间的 GCC 版本不同;众所周知,GCC 会随着时间的推移改变它处理#include 语句的方式。

除非存在版本差异,否则请检查以确保主机包含文件未在某处意外获取。

问题已通过添加

解决
#include <linux/i2c.h>

在 i2c-dev headers 之前。仍然不知道为什么两个编译器给出不同的结果...