首页 > 解决方案 > 获取错误代码:collect2.exe: error: ld returned 1 exit status

问题描述

编译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
}

关于我收到错误响应的任何原因都会有所帮助。此外,任何指向可能修复的指针都会很棒。

标签: clinker-errorsatom-editorldmingw-w64

解决方案


可能是您在链接以构建可执行文件时没有包括“myLibrary”。


推荐阅读