3

I was just trying to use Xcode for a very small C++ project, and wanted to see

some prints in the console, the thing is I did not see anything.

I tried to run a very simple code instead:

#include <iostream>

int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
printf("here");
return 0;
}

but still, nothing in Xcode console.

any idea why?

EDIT:

adding snapshot of the program:

xcode

EDIT 2:

found this,

and it's working:

How do I run a C++ program in Xcode 4?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Itzik984
  • 15,968
  • 28
  • 69
  • 107

5 Answers5

3

It sounds like when you created a new project (File > New > Project... ), you selected "C/C++ Library". Since libraries don't output to the console directly, that explains why Run was greyed out for you and running it doesn't output to the console.

Instead, you need to create a new project and select "Command Line Tool" template in the Application section, and build your program from there.

bejoux
  • 31
  • 3
3

That should work fine. Are you sure that you had the console displayed? Try command-shift-C or choose View->Debug Area->Activate Console.

If that doesn't help, try running your program from a Terminal window. Does the program display the expected output?

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 1
    i really dont know how to run it from terminal window, but activate console is exactly what i did and still nothing. – Itzik984 Mar 06 '12 at 00:42
  • 1
    @Itzik984 Does the console window have 'Debugger Output' selected in the little chooser thing? If so change it to 'All Output' – bames53 Mar 06 '12 at 00:46
  • @Itzik984 did you run the project? up at the top it only says 'Build one: Succeeded' not 'Finished running one' – bames53 Mar 06 '12 at 00:48
  • @bames53 i am pushing the PLAY button but it only say 'Build one: Succeeded' and i really cant see 'Finished running one'. im using Command+R. – Itzik984 Mar 06 '12 at 00:52
  • Use ⌘R or ⌃⌘R instead of ⇧⌘R. ⇧⌘R builds without running. – bames53 Mar 06 '12 at 00:56
  • @bames53 i am using ⌘R but it does nothing. it cannot run the program for some reason. (also product->run shows in grey 'disabled' button. – Itzik984 Mar 06 '12 at 01:00
  • @bames53 i really have no idea why this is happening... why im unable to run project... ill guess ill re-install xcode and hope for the best :( – Itzik984 Mar 06 '12 at 01:08
  • @Itzik984 did you try creating a new command line tool project? – bames53 Mar 06 '12 at 01:15
  • @Itzik984 let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8559/discussion-between-bames53-and-itzik984) – bames53 Mar 06 '12 at 01:21
2

Your image doesn't show that you ran the program, only that you built it. Look at the Log Navigator (the last one, ⌘7) and see if there are any logs for 'Debug one' after 'Build one'. To run the program use Product > Run or ⌘R.

bames53
  • 86,085
  • 15
  • 179
  • 244
  • for some reason i cant use ⌘R, or Product > Run. it is marked in grey color as in i cant push it. why is that? – Itzik984 Mar 06 '12 at 00:54
  • That's a good question. I don't know why that would be. Your screen shot also shows some .xcconfig files which I don't think is normal for a command line app. Maybe try creating a new project, Choose Mac OS X > Application > Command Line Tool. – bames53 Mar 06 '12 at 00:59
1

Try pressing Shift+Command+R. That should compile your program and open it in a terminal window.

  • ⇧⌘R will build it for running, but won't run it. – bames53 Mar 06 '12 at 00:55
  • That's what Command+R does, at least in my version of xCode. I don;t see why it would be different though in his version. –  Mar 06 '12 at 00:56
  • It sounds like your keyboard commands are customized. By default ⇧⌘R builds the project but won't run it. – bames53 Mar 06 '12 at 01:04
0

maybe you need to add "\n" after "here" I don't know why but it works for me. Hope someone can explain it for me.

Hance Wu
  • 1
  • 1