按如下方式编译C代码:
#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;
}
我得到以下信息:
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
myLibrary.h
文件如下:
#ifndef MYLIBRARY_H_
#define MYLIBRARY_H_
void function1(void);
void function2(void);
#endif /* MYLIBRARY_H_ */
和myLibrary.c
如下:
void function1(void){
puts("It works :)");
}
void function2(void){
//This function does nothing as well
}
关于我为什么得到错误响应的任何原因都会有所帮助。另外,任何指向可能修复程序的指针都将很棒。