c - 获取错误代码: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
}
关于我收到错误响应的任何原因都会有所帮助。此外,任何指向可能修复的指针都会很棒。
解决方案
可能是您在链接以构建可执行文件时没有包括“myLibrary”。
推荐阅读
- python - 从短语中打印单词
- java - 如何使用 ORMLite 同时在表中写入多个项目
- amazon-quicksight - AWS Quick Sight - 查询和数据检索机制
- javascript - Discord.js :部分代码不起作用,但没有错误
- javascript - 我可以压缩由 40 个不同字符组成的 400 个字符多少?
- html - 在django模板中如何在提交后保留下拉选择的选项?
- qt - QGraphicsView additem() 越来越大
- azure - Azure 事件网格 Webhook 验证握手
- javascript - 根据另一个数组过滤一个数组。(使用反应)
- r - 根据不同日期变量的观测值的存在或缺失生成新的因子变量