获取错误代码:collect2.exe:错误:ld返回1退出状态

时间:2019-03-09 06:30:53

标签: c linker-errors atom-editor ld mingw-w64

按如下方式编译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
}

关于我为什么得到错误响应的任何原因都会有所帮助。另外,任何指向可能修复程序的指针都将很棒。

0 个答案:

没有答案