以下に概説するプログラムをコンパイルすると、次のエラーが返されます
[igor@localhost ~/I2C]$ make i2c_VIPER DEFINE=-DVIPER
gcc -g -Wall -D__USE_FIXED_PROTOTYPES__ -DVIPER -ansi -lusb -c -o i2c.o i2c.c
In file included from i2c.c:9:
viperboard.h:120: error: expected ‘)’ before ‘*’ token
i2c.c: In function ‘main’:
i2c.c:32: error: ‘usb_dev’ undeclared (first use in this function)
i2c.c:32: error: (Each undeclared identifier is reported only once
i2c.c:32: error: for each function it appears in.)
i2c.c:33: warning: implicit declaration of function ‘i2c_VIPER’
make: *** [i2c.o] Error 1
私はそれを機能させるために、多かれ少なかれ半盲目的に多くのことを試みました。struct parsed_CLI_I2C_t
私が定義したものは、問題なく動作します。コンパイル エラーはありません。しかし、同等の方法でstruct usb_device
fromを使用しようとする<usb.h>
と、コンパイラは満足しません。私が間違っていることは何ですか?
比較的詳細な説明が続きます。
標準からのコード スニペットから始めましょう#include
< usb.h > <- 完全なヘッダー ファイルへのリンク
/* Data types */
struct usb_device;
struct usb_bus;
struct usb_device {
struct usb_device *next, *prev;
char filename[PATH_MAX + 1];
struct usb_bus *bus;
struct usb_device_descriptor descriptor;
struct usb_config_descriptor *config;
void *dev; /* Darwin support */
u_int8_t devnum;
unsigned char num_children;
struct usb_device **children;
};
最初のローカル ヘッダー ファイル #include "viperboard.h" を次に示します。
struct parsed_CLI_I2C_t;
extern int i2c_VIPER (struct usb_device **usb_dev, struct parsed_CLI_I2C_t **CLI_I2C_options);
extern bool OpenDevice(void);
これは 2 番目のローカル ヘッダー ファイルです #include "I2C.h"
typedef struct
{
char *USB_board;
int query;
int write_type;
} parsed_CLI_I2C_t;
extern int parse_CLI_I2C_options (int argc, char *argv[], parsed_CLI_I2C_t **CLI_I2C_options);
メインプログラムはこんな感じ
/* all other standard include stuff skipped for brevity */
#include <usb.h>
#include "viperboard.h"
#include <stdbool.h>
#include "I2C.h"
int main(int argc, char *argv[])
{
parsed_CLI_I2C_t *CLI_I2C_options;
parse_CLI_I2C_options (argc, argv, &CLI_I2C_options);
struct usb_device *usb_dev;
i2c_VIPER (&usb_dev, &CLI_I2C_options);
}
最後に、これは外部モジュールです
i2c_VIPER.c
/* all other standard include stuff skipped for brevity */
#include <usb.h>
#include "viperboard.h"
#include <stdbool.h>
#include "I2C.h"
int i2c_VIPER (struct usb_device **usb_dev, struct parsed_CLI_I2C_t **CLI_I2C_options )
{
bool connected; /* True if the ViperBoard is connected */
connected = OpenDevice();
return(0);
}
これは
OpenDevice.c
#include <stdbool.h>
#include <usb.h>
bool OpenDevice() /* <---- this is line 11 */
{
usb_set_debug( 0 );
/* Initialize USB library */
usb_init( );
etc etc etc
return true;
}
================================================== ====== 30 分後: 提案されたすべての変更が実装されました 別のタイプのエラーが表示されました。
OpenDevice.c:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘OpenDevice’
make: *** [OpenDevice.o] Error 1