leileicats
November 1st, 2007, 03:11 PM
Just a simple, whilst unexpected compilation error:
I have three simple files:
1, main.cpp
#include <iostream>
using namespace std;
#include "helloworld.h"
int main(){
hello_world();
return 0;
}
2, helloworld.h
#ifndef _HELLOWORLD_H
#define _HELLOWORLD_H
#include <iostream>
using namespace std;
void hello_world();
#endif
3,helloworld.cpp
#include "helloworld.h"
void hello_world(){
cout << "Hello World!\n";
}
When I was trying to compile, I got this error:
lei@maverick:~/code/example/HelloWorld$ g++ -o main main.cpp helloworld.h
/tmp/ccixBBMs.o: In function `main':
main.cpp:(.text+0x84): undefined reference to `hello_world()'
collect2: ld returned 1 exit status
I guess there is something wrong with the function prototype, but I can't find it.:confused:
I have three simple files:
1, main.cpp
#include <iostream>
using namespace std;
#include "helloworld.h"
int main(){
hello_world();
return 0;
}
2, helloworld.h
#ifndef _HELLOWORLD_H
#define _HELLOWORLD_H
#include <iostream>
using namespace std;
void hello_world();
#endif
3,helloworld.cpp
#include "helloworld.h"
void hello_world(){
cout << "Hello World!\n";
}
When I was trying to compile, I got this error:
lei@maverick:~/code/example/HelloWorld$ g++ -o main main.cpp helloworld.h
/tmp/ccixBBMs.o: In function `main':
main.cpp:(.text+0x84): undefined reference to `hello_world()'
collect2: ld returned 1 exit status
I guess there is something wrong with the function prototype, but I can't find it.:confused: