There are several types of problems you'll encounter, and each has a proven solving technique.
Solution: learn how to program in C++
No, I mean seriously, learn C++, thoroughly, until you are able to truly and fully understand every single bit of the cryptic message issued by the compiler, and why on earth it may have chosen to insult your intelligence with it. Because that cryptic message always contains the solution.
In particular, you need to really understand the difference between a const thingy and a non-const thingy, because to C++ they are often two totally different beasts (although to a decent human, they may look the same at first inspection).
So make sure you truly understand all the subtle differences
between for ex.:
const char* MyObj::mymethod(const char* &foo, const int& bar)
and
char* MyObj::mymethod(const char *const foo, int& bar) const
On rare occasions, you might occasionaly stumble upon a compiler bug (as in compiler internal error!!! ), in which case you may try the following: upgrade your dusty compiler to the newest less-buggy version; check on google to see if anybody else had the same problem and if they found a workaround; try to find a workaround yourself (split your call in several pieces, using intermediate variables, add a cout here, reorder the instructions there... and pray!); try posting an SOS on the appropriate newsgroups; write a bug report! Somebody somewhere, is responsible for it and might be interested in fixing the mess, or already has...
To save you some time, you may look up in the following list if somebody stumbled upon the same problem.
Problems reported by the linker can have several causes:
What I mean by clean runtime errors, is that the program displayed a nice error message and exited.
This most likely means that something in your program caused a call to the PLERROR macro, which called the errormsg function, which threw a PLearnException, which got caught in the very external try/catch of your main program, which printed it out (you main program does catch PLearn exceptions and report them, doesn't it???).
Tracing the problem is easy:
br 'PLearn::errormsg(
TAB
Hints for using gdb:
gdb is always at quite a lag behind, playing catch-up with the
latest compiler. Sot it has problems. Here are a few hints for
working with it, or in spite of it...
p (char *) my_string
, or call
p my_string.c_str()
cerr << ...
), recompile and
rerun gdb.
p my_var.ptr->value.length_
I also suggest you learn using a good integrated development environment (IDE) like Emacs. Emacs has multiple windows, a compilation mode (pressing return on an error will bring you directly to the problematic line of the problematic file), and a gdb mode (with which you can easily follow the step by step execution, as an arrow is always displayed before the next instruction to be executed, and you can rapidly put a breakpoint (Ctrl-X SPACE) anywhere).
With the proper key definitions (learn how to define your own keys for
maximum efficiency!), a complete recompile of your code, and reload in
gdb is just one key away. You won't have to touch the rat. And yes,
it even all works perfectly fine (multiple windows and all) inside
a single text terminal over a telnet connexion for ex. (invoke
it using emacs -nw
).
By this, I mean segmentation fault and the like.
valgrind --gdb-attach=yes your_prg_and_its_args