c++ - 在 Windows 上使用 MinGW 在 NetBeans 6.8 中编译 C/C++ 项目时遇到问题

标签 c++ c netbeans linker

我正在学习 C,因为 VC++ 2008 不支持 C99 功能,所以我刚刚安装了 NetBeans 并将其配置为与 MinGW 一起使用。我可以编译单个文件项目 (main.c) 并使用调试器,但是当我向项目添加新文件时,出现错误“未定义对该文件中...函数(代码)的引用...”。显然 MinGW 没有链接我的文件,或者我不知道如何正确地将它们添加到我的项目中(c 标准库文件工作正常)。

/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/don/Documents/NetBeansProjects/CppApplication_7'
/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_7.exe
make[2]: Entering directory `/c/Users/don/Documents/NetBeansProjects/CppApplication_7'
mkdir -p dist/Debug/MinGW-Windows
gcc.exe     -o dist/Debug/MinGW-Windows/cppapplication_7 build/Debug/MinGW-Windows/main.o  
build/Debug/MinGW-Windows/main.o: In function `main':
C:/Users/don/Documents/NetBeansProjects/CppApplication_7/main.c:5: undefined reference to `X'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/cppapplication_7.exe] Error 1
make[2]: Leaving directory `/c/Users/don/Documents/NetBeansProjects/CppApplication_7'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/Users/don/Documents/NetBeansProjects/CppApplication_7'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

主.c

#include "header.h"

int main(int argc, char** argv)
{
    X();
    return (EXIT_SUCCESS);
}

标题.h

#ifndef _HEADER_H
#define _HEADER_H
#include <stdio.h>
#include <stdlib.h>

void X(void);

#endif

来源.c

#include "header.h"
void X(void)
{
    printf("dsfdas");
}

最佳答案

尝试更改包含守卫的名称

#ifndef _HEADER_H //These
#define _HEADER_H
#include <stdio.h>
#include <stdlib.h>

void X(void);

#endif

以下划线 (_) 开头的名称保留供 C 和 C++ 标准库使用。完全有可能 _HEADER_H 已经在某处定义,这会使 main.c 无法编译。

关于c++ - 在 Windows 上使用 MinGW 在 NetBeans 6.8 中编译 C/C++ 项目时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638095/

相关文章:

c++ - 在 C++ 中分离流

c++ - 将函数模板特化传递给可变参数模板函数

c++ - 为什么在调用 glDrawArrays 之前不需要绑定(bind)顶点缓冲区对象?

c++ - 如果在 Intel CPU 上关闭 "SpeedStep Technology",RDTSC() 是否准确?

css - 开始使用 LESS

c++ - 圆刚采集卡 C985 不适用于 C++ 和 openCV

c - Printf 的变体及其原型(prototype)理解

c - 具有 2D 数组的 MPI_Allgather

java - 如何在我的应用程序中使用 Scene Builder Dark Theme

netbeans - 在NetBeans中将单词添加到拼写检查器词典中吗?