Self-written Applications don't work

Greetings :raising_hand_woman:

I wrote a simple Hello World Programm and compiled it. There was no Errors or Warnings and all seems to be ok. But when I’m startted it, it ended immediately with no Output and Error Level set <> 0. This Behavior is the same for Programs written with C++, Free Pascal and Nim :weary:

Maybe someone can help me with that and tell me what I do wrong?

Hope you can understand this poor english :worried:

IIRC 0 is success and negative return codes are errors.

I had no trouble compiling apps in C, C++, Nim and Vala, both my own and 3rd party. Can you show us your code and the commands you used? Also, what version of Haiku are you on, and is it on 32 or 64 bits?

The Code was this:

#include <iostream>
 
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

For Pascal and Nim it was the equivalent Code.

I compiled it with g++ -o test test.cpp and my Version of Haiku is Beeta 4 x64. Yes, my Brother also sayed it worked for him. It seems a bit wired for me because this is the first Time something like this happens for me. :face_with_spiral_eyes:

The exact Version of my Haiku is hrev56578+96

Seems to me that you missed something after the #include .

I see it :sweat_smile: It is lost while copying the Code at the Forum :weary:

#include <iostream.h>

int main()
{
std::cout << “Hello World!” << std::endl;
return 0;
}

Try with
<iostream>
instead of
<iostream.h>

Oh another Mistake by me. Sorry, I had not so much Sleep this Days and also sort some Stuff at this Moment :yawning_face: Sadly this isn’t the Reason for the Reason for this strange Behavior. Otherwise I simply could not compile this I think.

Well, seems as has no one an Idea what it could be. I think then I will reinstall the OS this days and show if this solves this Behavior. If it is done I will post the Results :exploding_head: Thank you very much for the Help and wish you a wonderfull Night (or Day) :sleeping:

I hope you won’t do that. If you’re interested in writing computer programs, one of the very most important skills is figuring out what has gone wrong.

Part of that is working with others, if they’re available and willing. To do that, you need to share the exact problem with them. You typed in code that won’t compile, for more than one reason. When we fix it, it works, but it isn’t your program concept that’s wrong - “Hello world” is a time honored algorithm - it’s some detail. Don’t tell them what a “Hello world” program looks like, tell them what your program looks like. Copy and Paste.

Part of that is learning the diagnostics. C++ won’t blow up with an informative error message, you have to explicitly code that. If you are headed for a non-zero exit, you should be able to get an informative diagnostic from the “perror” function.

6 Likes

How do you run your program? If you double-click the generated file in tracker, I don’t think it will show the terminal output at all.
On the other hand, if you run the program from the terminal (by typing ./test after compiling) you should see “Hello World!” as expected.

Also note that the code you’ve posted here is using as quotation marks instead of ", which would cause a compilation error, but it sounds like your original program compiles correctly.

1 Like

To post code, you should use markdown code blocks.
You need to enclose the code in triple backticks.
For example:

```
#include <iostream>

int main()
{
    std::cout << “Hello World!” << std::endl;
    return 0;
}
```

Which would produce:

#include <iostream>
 
int main()
{
    std::cout << “Hello World!” << std::endl;
    return 0;
}
1 Like

This is also just due to missing escaping to prevent the forum from reformatting it. The code itself is fine. I have edited the original message to add the missing escaping but it seems I was a bit late and we now have 5 replies pointing out mistakes that don’t really exist :frowning:

Sorry for the late reply, I was asleep. Can’t see anything wrong with what you did. Often when this happens it’s because of a little detail that’s hard to notice, or else an external cause. Don’t give up!

Thank you for the Hint.

I’m so sorry for the Confusion but my Comunication and Explantation Skills are not the best… I excuse me so much for the Lack of Information.

But I finally know what was the Issue. Every Time I was running the Program, at the Commandline I wrote <Programname> instead of ./<Programname>. Oh, this is such a Shame… :exploding_head::dizzy: :dizzy_face:

5 Likes