Hello,
i compiled and linked an executable program using some ncurses++ libraries.
After adding quellcode with a main function and compiling, it still worked.
Though i dont have a problem with that, isnt it strange?
Ben
Hello,
i compiled and linked an executable program using some ncurses++ libraries.
After adding quellcode with a main function and compiling, it still worked.
Though i dont have a problem with that, isnt it strange?
Ben
edit:
I once climed mount everest barefoot. But I won't show you the pics :P
abk, lol! haha! // very funny.
and yeah, all suspects are guilty!
The ncurses libraries are very strange, i had quite often some problems with them. You cant trust them, i think the vast usage of makros is their problem, but i cant say what really happend there.
benshi ; paste the code ;p let me see?
The code is very simple:
withoutmain.cpp
To compile install the ncurses++ libraries and enter the following command:Code:
g++ withoutmain.cpp -lncurses++ -lpanel
->You'll get an executable a.out (which in fact does nothing besides being executable)
Success, you wrote the shortest Program the world has ever seen!
To proove, that i'm not kidding, add a main function now:
and compile again.Code:int main(){ }
Ben
I'm not sure why you think that's weird. libncurses++ contains a main() function which is only linked if you don't provide your own. This is normal linker behavior. main() is not special.
Read the ncurses++ documentation.
Ok,
i think its strange, but maybe there might be a reason for this behaviour. It's ok, shall it compile, i dont mind.
Ben
At least i can now understand why this worked. Its a kind of c++ easteregg
No, it's not a C easter egg. It's a ncurses++ easter egg.
The following is technically dependent on operating system, but is often true practically.
If you link a bunch of object files and libraries together to form an executable, any functions called that can't be found will be searched for in the libraries. If a function is found in the object files, it will not be searched for in the libraries. So, if you don't supply a main() function in your object files, the linker will find it in the ncurses++ library. If you do supply main() in your object files, the linker will find that, and not look for main() in the ncurses++ library.
Provide two object files that both have a main() function, then your linker will complain bitterly regardless of whether you link in ncurses++ or not, because it can't pick between the two available functions.
Sorry... its ncurses related, not c++...
So hopefully i will never link two object files containing a main function.
After all, i stick to it, ncurses programs are difficult to handle, especially, for those who dont have enough knowlege of C (like me). Yesterday I compiled a ncurses Program and used some functions from <time.h> (bzw. <ctime>). It compiled, but then crashed with a segfault.
I really dont know why, but after declaring a C++ string between the ctime functions and the use of ncurses(++) this problem was solved. I also once had another problem with ncurses - I used a STL list and misteriously the list didnt work (segfaults...).
Last edited by benshi; 05-15-2008 at 04:46 AM.