多重定義的我有2個文件,即fun.cpp和main.cpp中問題在NetBeans
fun.cpp
#include <iostream>
using namespace std;
void sum()
{
cout << "hello";
}
Main.cpp的
#include <cstdlib>
#include <iostream>
#include "fun.cpp"
using namespace std;
int main(int argc, char** argv) {
sum();
return 0;
}
當我在netbeans上運行上面的代碼,我得到這個輸出
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/ravi/NetBeansProjects/ADBMS_v1.5'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/adbms_v1.5
make[2]: Entering directory `/home/ravi/NetBeansProjects/ADBMS_v1.5'
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/adbms_v1.5 build/Debug/GNU-Linux-x86/fun.o build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `sum()':
/home/ravi/NetBeansProjects/ADBMS_v1.5/fun.cpp:5: multiple definition of `sum()'
build/Debug/GNU-Linux-x86/fun.o:/home/ravi/NetBeansProjects/ADBMS_v1.5/fun.cpp:5: first defined here
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/adbms_v1.5] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/home/ravi/NetBeansProjects/ADBMS_v1.5'
make[1]: Leaving directory `/home/ravi/NetBeansProjects/ADBMS_v1.5'
BUILD FAILED (exit value 2, total time: 150ms)
任何人都可以解釋什麼問題?
在此先感謝..