我正在學習C,因爲VC++ 2008不支持C99功能我剛剛安裝了NetBeans並將其配置爲與MinGW配合使用。我可以編譯單個文件項目(main.c)並使用調試器,但是當我將新文件添加到項目時,出現錯誤「未定義的引用...該函數(代碼)在該文件中..」。很明顯,MinGW沒有鏈接我的文件,或者我不知道如何正確地將它們添加到我的項目中(c標準庫文件工作正常)。在Windows上使用MinGW編譯NetBeans 6.8中的C/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)
的main.c
#include "header.h"
int main(int argc, char** argv)
{
X();
return (EXIT_SUCCESS);
}
header.h
#ifndef _HEADER_H
#define _HEADER_H
#include <stdio.h>
#include <stdlib.h>
void X(void);
#endif
由source.c
#include "header.h"
void X(void)
{
printf("dsfdas");
}
我們需要確切的錯誤信息和編譯器在我們提供幫助之前抱怨的代碼。應該指出的是,MinGW缺少對幾個大型Windows API的支持。也許這就是你遇到的問題。 – 2010-04-14 14:23:19