Hello again.
I have 3 files:
main.cpp:
def.h:Code:#include <iostream> #include "def.h" using namespace std; int main() { cout << server_name << endl; }
def.cpp:Code:#ifndef _def_h_ #define _def_h_ #include <iostream> extern const std::string server_name; #endif
Code:#ifndef _def_cpp_ #define _def_cpp_ #include <iostream> const std::string server_name = "www.google.com"; #endif
I tried to compile them like this:
g++ main.cpp -c
g++ def.cpp -c
g++ main.o def.o
And I get this error:
main.o(.text+0x12e):main.cpp: undefined reference to `server_name'
collect2: ld returned 1 exit status



LinkBack URL
About LinkBacks


