I am using a structure that I defined in main.h and now using it in stack.c. In my main.h I have defined struct details and struct library. When I access them in stack.c I get the following error. When I am running a single main.c file then it's having no issues, so, I assume the issue lies in the stack.c or stack.h file.
Undefined symbols for architecture x86_64:
"_details", referenced from:
_main in main.o
_library_details in main.o
_push in stack.o
(maybe you meant: _library_details)
"_library", referenced from:
_main in main.o
_library_details in main.o
_push in stack.o
(maybe you meant: _library_details)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation
Here are my code snippets:
main.c
// write code below
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main.h"
void library_details(void);
FILE *fp;
int choice, indexer = 1;
//details_struct details[maxsize];
//library_struct library[maxsize];
int main(void)
{
// library = malloc(sizeof(library_struct) * 2);
fp = fopen("input.txt","r");
library_details();
for (int i = 1; i < indexer; i++)
{
if(library[i].type == is_book)
{
printf("Item %i is book: %s with %i pages\n", i, details[i].title, details[i].pages);
}
else if(library[i].type == is_article)
{
printf("Item %i is article: %s with %i pages\n", i, details[i].title, details[i].pages);
}
}
fclose(fp);
//free(library);
return 0;
}
main.h
#ifndef __MAIN_H_
#define __MAIN_H_
enum book_type {is_book, is_article};
typedef struct library_struct
{
enum book_type type;
void *item;
}library_struct;
typedef struct details_struct
{
char title[50];
int pages;
}details_struct;
// external variables
extern int choice, indexer;
extern details_struct details[100];
extern library_struct library[100];
// library details
void library_details(void);
#endif // __MAIN_H_
stack.c
// stack.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "stack.h"
#include "main.h"
//functions declarations
void push(void);
stack books_stack[100];
int top = 0;
int stack_main(void)
{
return 0;
}
void push()
{
if(top >= 99)
{
printf("Stack Overflow\n");
exit(-1);
}
else
{
if(library[top].type == is_book)
{
strcpy(books_stack[top].s_title, details[top].title);
books_stack[top].s_pages = details[top].pages;
}
}
}
stack.h
#ifndef __STACK_H_
#define __STACK_H_
typedef struct stack
{
char s_title[50];
int s_pages;
}stack;
// functions declaration
void push();
#endif // __STACK_H_
Is there any issue with struct declarations?