I am creating a program in c that requires—like most—linking between header files using #include. When I run the main.c file through the terminal i get the following error message:
The command:
gcc main.c -o main.exe
The error message:
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccxC9Mr4.o:main.c:(.text+0xe): undefined reference to `SomeMethod'.
I have simplyfied the files to make it more readable, but the problem does still occur. The files reside in the same folder, so you'd think that they wouldn't have any problems. No noticable sytax errors either.
Main.c file:
#Include "SomeFile.h"
void main(void){
SomeMethod();
}
SomeFile header file:
#ifndef FOLDER_SOMEFILE_H_
#define FOLDER_SOMEFILE_H_
int SomeVar;
void SomeMethod(void);
#endif /* FOLDER_SOMEFILE_H_ */
SomeFile file:
#include "SomeFile.h"
void SomeMethod(){}
I expect it to not give the errors, that's about it. I've tried remaking the files and header files and recreating the project folder.
Follow-up question: I wrote the command below which fixed the initial problem presented in this question, but a new problem arose. Now apparently there are occurrences of multiple definitions of variables in the header file(added 'SomeVariable' to the code example to demonstrate this). I think it might be from the header file being called multiple times due to the SomeFile now being included in the gcc command. The command and error message can be seen below.
gcc command:
gcc main.c aaa.c simHandler.c gui.c -o main.exe
error message:
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccdrnxub.o:SomeFile.c:(.bss+0x0): multiple definition of `SomeVar'; /tmp/cc0y4cs4.o:main.c:(.b