gcc 6.4.0 Netbeans 8.2 cygwin64
I don't know how to fix a multiply defined symbol problem. My include file has guards and there are no other symbols with the same name. The linker shows that the symbol, testoutput, is multiply defined. Whatever name I use in the declaration 'ofstream ' comes back multiply defined. I can avoid the issue by creating a stringstream variable and passing to to a output function but that seems like a really poor idea. Can I pass an i/o variable around?
Test code and linker output included:
#ifndef COMMON_H
#define COMMON_H
# include <fstream>
using namespace std;
ofstream testout;
#endif /* COMMON_H */
#ifndef FILE_H
#define FILE_H
# include "Common.h"
class myClass {
public:
void outStuff();
};
#endif /* FILE_H */
# include "File.h"
# include "Common.h"
void myClass::outStuff() {
testout << "another thing" << endl;
};
# include "Common.h"
using namespace std;
int main(int argc, char** argv) {
testout.open("test.out");
testout << "out" << endl;
}
======================== UUILD ============================== CLEAN SUCCESSFUL (total time: 255ms) cd 'C:\home\skidmarks\Projects\Test\Test' c:\cygwin64\bin\make.exe -f Makefile CONF=Debug "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Entering directory '/c/home/skidmarks/Projects/Test/Test' "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin64-Windows/test.exe make[2]: Entering directory '/c/home/skidmarks/Projects/Test/Test' mkdir -p build/Debug/Cygwin64-Windows rm -f "build/Debug/Cygwin64-Windows/File.o.d" g++ -Wall -Wunused-variable -c -g -MMD -MP -MF "build/Debug/Cygwin64-Windows/File.o.d" -o build/Debug/Cygwin64-Windows/File.o File.cpp mkdir -p build/Debug/Cygwin64-Windows rm -f "build/Debug/Cygwin64-Windows/main.o.d" g++ -Wall -Wunused-variable -c -g -MMD -MP -MF "build/Debug/Cygwin64-Windows/main.o.d" -o build/Debug/Cygwin64-Windows/main.o main.cpp mkdir -p dist/Debug/Cygwin64-Windows g++ -o dist/Debug/Cygwin64-Windows/test build/Debug/Cygwin64-Windows/File.o build/Debug/Cygwin64-Windows/main.o ../../../../../cygwin64/usr/local/lib/libgslip.a build/Debug/Cygwin64-Windows/main.o:/c/home/skidmarks/Projects/Test/Test/Common.h:8: multiple definition of `testout' build/Debug/Cygwin64-Windows/File.o:/c/home/skidmarks/Projects/Test/Test/Common.h:8: first defined here collect2: error: ld returned 1 exit status