Problems compiling a C / C ++ project in NetBeans 6.8 using MinGW on Windows
I'm learning C, and since VC ++ 2008 does not support C99 features, I just installed NetBeans and configured it to work with MinGW. I can compile a project with one file (main.c) and use the debugger, but when I add a new file to the project, I get the error "undefined reference to ... function (code) in this file ..". Obviously MinGW doesn’t link my files or I don’t know how to add them to my project correctly (with standard files the libraries work fine).
/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");
}
a source to share
Try to change the name of your included guards
#ifndef _HEADER_H //These
#define _HEADER_H
#include <stdio.h>
#include <stdlib.h>
void X(void);
#endif
Names beginning with the underscore character (_) are reserved for use by the C and C ++ standard libraries. It is entirely possible that _HEADER_H is already defined somewhere, which would make it main.c
not compile.
a source to share