I'm having a linking issue with a basic C++ program. No, I'm not including .cpp
files!
This is what's happening.
main.cpp:
#include "header.h"
#include <iostream>
int main() {
std::cout << "Hello!";
}
header.h:
#ifndef _HEADER_H
#define _HEADER_H
class Something {
public:
printContents();
};
#endif
something.cpp:
#include "header.h"
#include <iostream>
Something::printContents() {
cout << "This class's Contents!!";
}
What's happening is that I get a compiler error going: multiple definitions of some standard C function, such as strtod
:
g++ -o ... main.o
build/....main.o: In function `strtod':../MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:318: multiple definition of `strtod'
build/..something.o:...something.cpp:(.text+0x0): first defined here collect2: ld returned 1 exit status
If I get rid of #include <iostream>
in one of the two occasions and get rid of the cout
s, it will compile. What's going on? I'm using g++ and NetBeans to compile.
I tried in the command line:
g++ *.h *.cpp -o program
and the same thing happened.
The problem was in a multi-installation of MinGW. I had one already installed, and when I got Qt on my computer, it had installed it's own MinGW. Bummer, I ported the code to my university's servers and it ran OK.
Bummer!!
Thanks everybody for the help, I will definitely follow your guidelines in the future.
Header names - no underscores Correct return type Real code in the forums!
Leo Bruzzaniti