-1

While compiling the C code as follows:

#include <stdio.h>          // Notice the library included in the header of this file
#include <stdlib.h>

#include "myLibrary.h"      // Notice that myLibrary.h uses different include syntax

#define MAX_LENGTH 21.8
#define WORK_WEEK  5

int main(void) {
    function1();
    return EXIT_SUCCESS;
}

I am getting the following:

d:/programs/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\svtte\AppData\Local\Temp\ccyHWfzC.o:02_01.c:(.text+0xc): undefined reference to `function1' 
collect2.exe: error: ld returned 1 exit status

The myLibrary.h file is as follows:

#ifndef MYLIBRARY_H_
#define MYLIBRARY_H_

void function1(void);
void function2(void);

#endif /* MYLIBRARY_H_ */

and myLibrary.c is as follows:

void function1(void){
    puts("It works :)");
}

void function2(void){
    //This function does nothing as well
}

Any reasons as to why I am getting the error response would be helpful. Also, any pointers to the possible fixes would be great.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
  • 2
    Please include the command you’re using to compile – Sami Kuhmonen Mar 09 '19 at 06:39
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Mar 10 '19 at 12:23

1 Answers1

0

The likelihood is that you’re not including 'myLibrary' when you link to build the executable.

Gwyn Evans
  • 1,361
  • 7
  • 17