I'm constructing an u-boot bootloader for my embedded system (cyclone V) using Buildroot and I get the following error :
error: 'dm_mmc_ops' undeclared (first use in this function)
After several unsuccessful attempts to understand/solve the error, I've manage to isolate the problem which looks like the simple code hereafter and generates the same error :
#ifndef FILE1
#define FILE1
struct dm_mmc_ops {
int (*send_cmd)(int data);
int (*set_ios)(char* dev);
};
struct dev {
struct dm_mmc_ops* ops;
} *dev;
#define mmc_get_ops(dev) ((dm_mmc_ops *)(dev)->ops)
#endif
#ifndef FILE2
#define FILE2
#include "file1.h"
extern const struct dm_mmc_ops dm_dwmci_ops;
#endif
#include <stdio.h>
#include "file1.h"
#include "file2.h"
int return_int (int data)
{
return data;
}
int return_ptr (char* data)
{
return (int) data;
}
const struct dm_mmc_ops dm_dwmci_ops = {
.send_cmd = return_int,
.set_ios = return_ptr
};
void main (void)
{
struct dev my_dev = {.ops = &dm_dwmci_ops};
dev = &my_dev;
char text[] = "abcd";
struct dm_mmc_ops *test_mmc = mmc_get_ops(dev); // Error is here !!!
printf("%d\n",test_mmc->send_cmd(50));
printf("%d\n",text);
printf("%d\n",test_mmc->set_ios(text));
return;
}
Then the error generated is :
error: 'dm_mmc_ops' undeclared (first use in this function)
What is wrong in my code and what should I do to get rid of this error ?
Your problem is here
#define mmc_get_ops(dev) ((dm_mmc_ops *)(dev)->ops)
^^^^^^^^^^
You probably want
#define mmc_get_ops(dev) ((struct dm_mmc_ops *)(dev)->ops)
Besides that you have a number of other problems. Set you compiler to a high warning level (e.g. gcc -Wall ...) and then fix all warnings.