User forums > Using Code::Blocks
compiles fine in command prompt, but code blocks complains
darkwalk:
I am having this strange problem. I have the following files: main.cpp printStuff.cpp printStuff.h. The printStuff contains a single method that prints to cout. Everything looks correct, because I can compile it using the command prompt by executing:
g++ main.cpp printStuff.cpp -o output.exe
However, CodeBlocks complains because main contains an undefined reference to a function defined in printStuff.cpp. I cannot find a solution anywhere... I even installed a new nightly build because I was desperate. The only thing I can think of is due to some setting problems. Can anyone help? Thank you very much!
killerbot:
so it's the linking step that seems to fail
Which function is it complaining about, that is to be used in main, and as such where is it in the other file ??
darkwalk:
Here is the code: It is the simplest kind, but doesn't work properly in CodeBlocks:
--------- Main.cpp ------------
--- Code: ---#include <iostream>
#include "printStuff.h"
using namespace std;
int main(){
print_hello();
return 0;
}
--- End code ---
--------- PrintStuff.h -----------
--- Code: ---void print_hello();
--- End code ---
--------- PrintStuff.cpp ----------
--- Code: ---#include <iostream>
using namespace std;
void print_hello(void){
cout<<"hello?"<<endl;
}
--- End code ---
Thanks!
MortenMacFly:
--- Quote from: darkwalk on May 23, 2007, 03:59:28 pm ---Here is the code: It is the simplest kind, but doesn't work properly in CodeBlocks:
--- End quote ---
Come on... don't you think if this wouldn't work C::B would exist?! ;-)
Please: Create a project, add all 3 files to the project, press compile. Works fine for me. Notice: The command line you stated is not the way C::B works. Within the command line you do compiling/linking in "1 step" by providing both source files. Whereas C::B will first create all object files from the sources and link them afterwards. If you try to only compile main.cpp within C::B without a project then the error message is right: C::B was not told to include the object file for PrintStuff.cpp, too - and (in fact) it wasn't even compiled!
With regards, Morten.
Auria:
Also if you get more errors can you post the exact error message and not some reformulation of your own?
thanks
Navigation
[0] Message Index
[#] Next page
Go to full version