2013-12-05 2 views
0

Я попытался скомпилировать простую программу на языке C с заголовком, основным и другим исходным файлом в Netbeans, но это не сработало. Я всегда получаю огромное сообщение об ошибке.Использование заголовка в netbeans C

У меня нет абсолютно никакой идеи, что я могу сделать, чтобы заставить его работать. Надеюсь, ты, парень, может мне помочь.

консоль:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/home/***/***/***/***/***/headertest' 
nbproject/Makefile-Debug.mk:73: warning: overriding commands for target `build/Debug/GNU-Linux-x86/header.o' 
nbproject/Makefile-Debug.mk:68: warning: ignoring old commands for target `build/Debug/GNU-Linux-x86/header.o' 
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/headertest 
make[2]: Entering directory `//home/***/***/***/***/***/headertest' 
nbproject/Makefile-Debug.mk:73: warning: overriding commands for target `build/Debug/GNU-Linux-x86/header.o' 
nbproject/Makefile-Debug.mk:68: warning: ignoring old commands for target `build/Debug/GNU-Linux-x86/header.o' 
mkdir -p build/Debug/GNU-Linux-x86 
rm -f "build/Debug/GNU-Linux-x86/header.o.d" 
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/header.o.d" -o build/Debug/GNU-Linux-x86/header.o header.h 
mkdir -p build/Debug/GNU-Linux-x86 
rm -f "build/Debug/GNU-Linux-x86/main.o.d" 
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.c 
mkdir -p dist/Debug/GNU-Linux-x86 
gcc  -o dist/Debug/GNU-Linux-x86/headertest build/Debug/GNU-Linux-x86/header.o build/Debug/GNU-Linux-x86/header.o build/Debug/GNU-Linux-x86/main.o 
/usr/bin/ld:build/Debug/GNU-Linux-x86/header.o: file format not recognized; treating as linker script 
/usr/bin/ld:build/Debug/GNU-Linux-x86/header.o:1: syntax error 
collect2: error: ld returned 1 exit status 
make[2]: *** [dist/Debug/GNU-Linux-x86/headertest] Error 1 
make[2]: Leaving directory `/home/***/***/***/***/***/headertest' 
make[1]: *** [.build-conf] Error 2 
make[1]: Leaving directory `/home/***/***/***/***/***/headertest' 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 283ms) 

Вот остальная часть моего кода: main.c

#include <stdio.h> 
#include <stdlib.h> 
#include "header.h" 

int main(int argc, char** argv) { 

    lol(); 

    return (EXIT_SUCCESS); 
} 

header.c

#include "header.h" 

void lol(){ 
    printf("lol"); 
} 

header.h

#ifndef HEADER_H 
#define HEADER_H 
#ifdef __cplusplus 
extern "C" { 
#endif 

void lol(); 

#ifdef __cplusplus 
} 
#endif 
#endif /* HEADER_H */ 
+0

Почему вы компилируете файл заголовка? –

+0

Согласно журналу вы компилируете header.h, в то время как вы должны компилировать header.c – JimiDini

+0

ОК спасибо. И как я могу изменить, какие файлы будут скомпилированы в netbeans? –

ответ

0

Вы не включили stdio.h. Ваша функция lol() не знает printf().

Поместить #include <stdio.h> либо в header.c, либо header.h.

+0

ОК спасибо, теперь он работает :) –

Смежные вопросы