Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gojaromeiginla

macrumors member
Original poster
Hi there, I'm just starting out with C++, and I'm trying it out with XCode. By just starting, I mean I literally just began today. Same with XCode. Basically, I've been trying all day to get XCode to run my code, and nothing is working🙁. I'm looking for any advice at all. Thanks in advance.
 
What is it erroring out on?

Also, C++ sucks badly as a programming language. Do you need to use it?
 
Well, that's the whole thing. It isn't erroring out on anything, because I can't figure out how to run anything at all. For the record, the code I'm trying to run is just a simple "Hello World." And I've heard that C++ may not be the easiest language to learn, but I've also heard that it gives you a good base and it can do more than some other languages. I might try Java if all else fails.
 
Assuming you're up to date with XCode 3, I can get you started in 30 seconds:

1. Open XCode.
2. File/New Project...
3. In the "New Project" Assistant, expand the "Command Line Utility" group.
4. Select "C++ Tool"
5. Click "Next"
6. Give a project name and directory, then click "Finish".
7. Press Cmd-Shift-R to open the Console window. Output will appear there.
8. Click the "Build and Go" toolbar button.

That's it. Hello World done. From there you'll probably want to edit main.cpp to do other things.
 
OK, I'm at least getting new results at this point. I tried something like this before, and all it came up with was the build dialogue. It's at least opening a window for me now. I'm still not getting the text to appear at all. I don't really think this program likes me. It might be the code, but I've double checked it. Thanks for your help. Any more advice would be appreciated.

Edit: I think I've gotten it working. Thanks again!
 
Thanks So Much!

Thanks Gelfin! I am also a noob (+ 1 day), and I have had trouble navigating to the correct debugger console in Xcode 3. All tutorials I had found until this point were based upon Xcode 2. Thanks a bunch!
 
Hi,

I've been trying to do the same thing also but even after following Gelfin's directions I keep getting 2 errors.....could'nt excute /usr/bin/gcc-3.3: No such file or Directory.

What am I doing wrong?
 
Also, C++ sucks badly as a programming language. Do you need to use it?

If you had written "C++ may not be the perfect programming language for beginners", then I might have agreed somewhat. But your statement simply makes no sense. It's like saying "A power drills sucks badly as a tool. Do you need to use it?"

Or are you trying to pick a fight? 🙂
 
Also, C++ sucks badly as a programming language.

Sucks badly for Mac, or sucks badly in general? Care to explain? I ask because it's one of the most complete and powerful languages in existence and looks hella good on a resumé.

To the OP:

I personally skipped Xcode (and other IDEs available on Mac) and took all of my development straight to the command line, for C, C++, Perl, Java, etc. If you're learning C++ from a book it's your best bet, at least in the beginning. After you learn & understand a little more about C++, start looking for an IDE.

If you want to give the command line a try; then try compiling with the following command:

g++ application_name.cpp -o application_name

If you're using a book, can I ask which one? If i've read it, I might be able to tell you how to make it work in Xcode.
 
To Speak For Myself

Well, I am not the original poster, but I have had the same complaint. Anyways, the book I am trying to learn with is SAM'S TEACH YOURSELF C++ IN 24 HOURS. Help would be greatly appreciated.

Also, I have attempted to work with Terminal to compile, but it doesn't ever work, claiming that there is nothing to compile, I'm not really sure.
 
noob trying hello world

gelfin, thanks a ton for showing how to start. my prob is i did so many hello worlds that to start clean i erased some files, likely files that i shudnt have. now when i control shift r, i get a debugger console that is blank inside, and when i hit the build and go button, i get an error:
No launchable executable present at path, then gives me the path.

any idea how to fix this?

thanks a ton!
 
To view the output of a command line program in XCode, you have to open the console. The quickest way to do this is to have the main source code file open, and click the console button that appears towards the top after you click "Build-And-Go." If the button disappears too quickly, you can use this line to delay the program until you press enter:

Code:
getc(stdin);

If you want to give the command line a try; then try compiling with the following command:

I might call gcc instead of g++, but I guess that comes down to preference.
 
C++ programming in xcode?

Assuming you're up to date with XCode 3, I can get you started in 30 seconds:

1. Open XCode.
2. File/New Project...
3. In the "New Project" Assistant, expand the "Command Line Utility" group.
4. Select "C++ Tool"
5. Click "Next"
6. Give a project name and directory, then click "Finish".
7. Press Cmd-Shift-R to open the Console window. Output will appear there.
8. Click the "Build and Go" toolbar button.

That's it. Hello World done. From there you'll probably want to edit main.cpp to do other things.



Hey brother, I have the same problem as the guy who posted this thread, but I cannot find there is no option for "Command Line Utility" after I select new project. It just goes straight to different template options.

Also, I haven't been able to "Build and Run" a Hello World! program yet because the "Build and Run" button is not active. PLEASE help, I'm a student and would really like to be able to program at home on my imac instead of at school all the time.
 
Hey brother, I have the same problem as the guy who posted this thread, but I cannot find there is no option for "Command Line Utility" after I select new project. It just goes straight to different template options.

Also, I haven't been able to "Build and Run" a Hello World! program yet because the "Build and Run" button is not active. PLEASE help, I'm a student and would really like to be able to program at home on my imac instead of at school all the time.

maybe u can post a screen shot of your Xcode program?
 
Hey brother, I have the same problem as the guy who posted this thread, but I cannot find there is no option for "Command Line Utility" after I select new project. It just goes straight to different template options.

Also, I haven't been able to "Build and Run" a Hello World! program yet because the "Build and Run" button is not active. PLEASE help, I'm a student and would really like to be able to program at home on my imac instead of at school all the time.

Look for C++ tool.

Alternatively, you can compile your files without needing to create a project.
As said above, you use g++ and compile from Terminal.

Navigate to the directory of your file: (eg. located on the Desktop)

cd ~/Desktop

Then to compile using g++:

g++ myFile.cpp -o myApp

Run your program:

./myApp
 
I assume that you are running xcode version 3.2.

In that case you have to choose "command line tool" and "c++stdc++" as type in the mac osx template section when you open a new project!
 
hi, i got a mac os x and i got the same problem, i installed netbeans and configured it to compile c/c++ and did all the steps necessaries and explained, but when im supposed to be able to do a project, under c application i add a source item and it doesnt seems to find any library at all, not can even compile hello world, or even return 0 only to by main. could u guess whats wrong? i even did add the libraries at the sdk sub folders previously explained but that just eliminate the errors for the editors, nothing more.

my error says:

"/Developer/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
main.c:1:19: error: stdio.h: No such file or directory
"/Developer/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/ctest
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.c
main.c:2:18: error: math.h: No such file or directory
main.c:4:20: error: stdlib.h: No such file or directory
main.c:5:18: error: time.h: No such file or directory
main.c:6:19: error: ctype.h: No such file or directory
main.c:7:20: error: string.h: No such file or directory
main.c: In function 'main':
main.c:26: warning: incompatible implicit declaration of built-in function 'printf'
main.c:48: warning: incompatible implicit declaration of built-in function 'scanf'
main.c:73: warning: incompatible implicit declaration of built-in function 'scanf'
main.c: In function 'verifyPin':
main.c:139: warning: incompatible implicit declaration of built-in function 'printf'
main.c:140: warning: incompatible implicit declaration of built-in function 'scanf'
main.c:163: warning: incompatible implicit declaration of built-in function 'exit'
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 162ms)
 
could u guess whats wrong?

This is a guess, but here it goes:

It looks like there is something wrong with your build environment. I'm guessing that you need to install XCode even though you are using Netbeans.
 
error

Hi,
I'm trying to learn C/C++. I've been succesfully installed xcode and I've been wrote a simple file:
#include <stdio.h>
void main(void)
{
printf("Totul despre C/C++");
}

and I have some error messages:

Building target “c++” of project “c++” with configuration “Release” — (2 errors)
cd /Users/scaier/c/c
/Developer/usr/bin/g++-4.0 -o /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/c++ -L/Users/scaier/c/c/build/Release -F/Users/scaier/c/c/build/Release -filelist /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/c++.LinkFileList -arch ppc -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
ld: duplicate symbol _main in /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/primul.o and /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/main.o

collect2: ld returned 1 exit status
ld: duplicate symbol _main in /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/primul.o and /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/ppc/main.o
collect2: ld returned 1 exit status
cd /Users/scaier/c/c
/Developer/usr/bin/g++-4.0 -o /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/c++ -L/Users/scaier/c/c/build/Release -F/Users/scaier/c/c/build/Release -filelist /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/c++.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
ld: duplicate symbol _main in /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/primul.o and /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/main.o

collect2: ld returned 1 exit status
ld: duplicate symbol _main in /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/primul.o and /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/main.o
collect2: ld returned 1 exit status
Build failed (2 errors)


I've been tryied this with eclipse and also i had errors at #include <stdio.h>

Can somebody tell me what is wrong or if I have to install something?
I use a book for learning (Jamsa's Programmer's Bible) which use Turbo C++ Lite.
Thank you
 
Hi,
I'm trying to learn C/C++. I've been succesfully installed xcode and I've been wrote a simple file:
#include <stdio.h>
void main(void)
{
printf("Totul despre C/C++");
}

and I have some error messages:

Go back to the very first reply by Gelfin.

Also, one part of the learning process, and a very important one, is making sense of error messages. Look at this error message:

ld: duplicate symbol _main in /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/primul.o and /Users/scaier/c/c/build/c++.build/Release/c++.build/Objects-normal/i386/main.o

There is a symbol _main in two places, one that ends in "primul.o" and one that ends in "main.o". Why might that be?
 
Hey brother, I have the same problem as the guy who posted this thread, but I cannot find there is no option for "Command Line Utility" after I select new project. It just goes straight to different template options.

Also, I haven't been able to "Build and Run" a Hello World! program yet because the "Build and Run" button is not active. PLEASE help, I'm a student and would really like to be able to program at home on my imac instead of at school all the time.

"Command Line Utility" is the exact same thing as "Command Line Tool", then from there proceed to click C++ in the dropdown box.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.