|
|
How Do I Make a Simple C++ Program?
|
|
|
|
Junior Member
Join Date: Oct 2001
Location: UCI
Status:
Offline
|
|
I cannot figure out how to make one through the project builder without having to use their interface. I just want to make a simple console program such as "hello world." Is there any way to do this with Apple's provided tools?
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Nov 2000
Status:
Offline
|
|
Sorry to disappoint you. This isn't an answer. Just a confirmation that someone else is having the same problem. But with me, it may just be my own ignorance.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Use the Standard Tool project template. By default that will have a .c file in it, delete it and add a file with the extension .cpp in order to make it compile as C++.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Nov 2001
Location: Seattle
Status:
Offline
|
|
Another question, along on the same line:
When I create the standard C++ tool "hello world" project using project maker, it won't compile. I get the linker error
<font face = "courier">/usr/bin/ld: /usr/lib/libSystem.dylib load command 6 unknown cmd field</font>
Any thoughts? I've never seen a linker error like this before. Same thing happened when I tried to compile the Vim source code, and the same thing if I just do "cc hellotest.cc" from the command line.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
That link problem is because cc doesn't seem to like actual c++ code. You have to explicitly invoke the c++ compiler like this:
c++ helloWorld.cpp -o helloWorld
That worked for me when compiling a simple:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#include <stdio.h>
#include <iostream.h>
int main(){
cout << <font color = red>"Hello World!\n"</font>;
}
</font>[/code]
Hope that helps,
Jeff.
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Nov 2001
Location: New Jersey, USA
Status:
Offline
|
|
Mr. E, I actually had a similar problem -- I got some error involving some remote file that seems to have something to do with Project Builder itself. I've been editing in it as normal, and compiling from the command prompt. I like it better that way, actually.
PS - If you are who I think you are: Great site, buddy; I'm a daily reader =/
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
Hey, the simplest way for "Hello world" is not to use the project builder at all:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[localhost:~] % cat > hello.c
#include <stdio.h>
int main(void)
{
printf(<font color = red>"Hello world!\n"</font>);
}
</font>[/code]
(press ctrl D here)
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[localhost:~] % cc hello.c -o hello
[localhost:~] % ./hello
Hello world!
[localhost:~] %
</font>[/code]
-
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Juggle5:
<STRONG>Another question, along on the same line:
When I create the standard C++ tool "hello world" project using project maker, it won't compile. I get the linker error
<font face = "courier">/usr/bin/ld: /usr/lib/libSystem.dylib load command 6 unknown cmd field</font>
Any thoughts? I've never seen a linker error like this before. Same thing happened when I tried to compile the Vim source code, and the same thing if I just do "cc hellotest.cc" from the command line.</STRONG>
You are on OS X 10.1 and you didn't upgrade your developer tools when you upgraded.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Oct 2001
Location: UCI
Status:
Offline
|
|
I've tried using the CC tool to compile from the command line...but it's giving me the following error:
cc: installation problem, cannot exec `cc1plus': No such file or directory
I'm typing in the command as specified:
[me211128:~/desktop] jamesgui% cc source.cpp -o Program
I have the 10.1 developer tools installed, and it gave me no errors when I ran the installer. Anyone know what to do here?
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Oct 2001
Location: UCI
Status:
Offline
|
|
The compiler does seem to work if I change the file name to source.c rather than source.cpp. However, it looks at the code as C instead of C++, and gives me a ton of errors. I definitely want to use C++, as that's the language I know inside and out.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Nov 2001
Location: Seattle
Status:
Offline
|
|
I'll bet it's the 10.0 dev tools on system 10.1. That might explain why I had to rename some files just to get project builder to run. When I installed 10.1, I looked, but I didn't remember seeing the new dev tools on the CD. I'll look again or download it. Thanks.
To Apocalypse: FYI, you shouldn't *need* to use c++ if you don't want to. From the compiler documentation (on my computer it's in Developer/Documentation/DeveloperTools/Compiler): "The C, C++, Objective-C, and Objective-C++ versions of the compiler are integrated; the GNU C compiler can compile programs written in C, C++, or Objective-C." You have an excellent point on many other systems, however.
To moonray: this was actually what I tried first. Since it didn't work, I figured there might be some weird compiler options and hoped the project builder would work.
Thanks again.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
The 10.1 Developer Tools are available from http://connect.apple.com and if you notice I suggested this earlier but everybody ignored me
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Oct 2001
Location: UCI
Status:
Offline
|
|
No, I'm 100% certain it's the 10.1 tools...I downloaded them from the ADC last week. The project builder works fine...just doesn't do simple console programs (rather, I haven't figured out how).
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Dec 1999
Location: Clovis' underwater chicken ranch
Status:
Offline
|
|
Originally posted by Mr.E:
<STRONG>
[me211128:~/desktop] jamesgui% cc source.cpp -o Program
</STRONG>
as was stated earlier you probably want
% c++ source.cpp -o Program
|
The empty can rattles the loudest
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2001
Location: Sad King Billy's Monument on Hyperion
Status:
Offline
|
|
Originally posted by Mr.E:
<STRONG>No, I'm 100% certain it's the 10.1 tools...I downloaded them from the ADC last week. The project builder works fine...just doesn't do simple console programs (rather, I haven't figured out how).</STRONG>
Make a new project and choose "C++ Tool". That's a "simple console program". It's what you want.
|
I abused my signature until she cried.
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
OS X is a unix OS, so you can use much of the tools that you can in UNIX to compile simple command line programs that can be run in the terminal. But learning how to do this is probably harder and more time consuming than finding an answer to your problem...
Off hand, (I am in OS 9 right now and don't feel like restarting) I believe VI can compile or is that emacs? Or perhaps it was another UNIX text editor that I downloaded. Anyways, there are many unix text editors that can compile programs for you in the terminal, that can be used in the terminal.
On thing for sure, Apple Developer Tools does not have any easy way or any way, that I know of, to make anything for the terminal...
Anyways good luck with this...
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Originally posted by 11011001:
<STRONG>OS X is a unix OS, so you can use much of the tools that you can in UNIX to compile simple command line programs that can be run in the terminal. But learning how to do this is probably harder and more time consuming than finding an answer to your problem...
Off hand, (I am in OS 9 right now and don't feel like restarting) I believe VI can compile or is that emacs? Or perhaps it was another UNIX text editor that I downloaded. Anyways, there are many unix text editors that can compile programs for you in the terminal, that can be used in the terminal.
On thing for sure, Apple Developer Tools does not have any easy way or any way, that I know of, to make anything for the terminal...
Anyways good luck with this... </STRONG>
This is not true. Any project type that is labeled as a tool, is mean't to be used in the terminal.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
Well I did not know developer could do that... so thx
But there is true stuff in there... One of those text editors can compile for the terminal. And one of the reasons why it is so easy to port unix programs and linux to OS X is cus OS X is unix, and though apple does not encourage it (they seem to be in love with aqua), you can port a text based program over from unix with only editing it a bit, to be used in the terminal... Examples are many and widespread...
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Oct 2000
Status:
Offline
|
|
Originally posted by 11011001:
<STRONG>Well I did not know developer could do that... so thx
But there is true stuff in there... One of those text editors can compile for the terminal. And one of the reasons why it is so easy to port unix programs and linux to OS X is cus OS X is unix, and though apple does not encourage it (they seem to be in love with aqua), you can port a text based program over from unix with only editing it a bit, to be used in the terminal... Examples are many and widespread...</STRONG>
Actually, at the WWDC this past May, Apple encouraged developers to use Interface Builder to develop interfaces on top of the existing source code of UNIX apps. That's one of the beauties of Apple's frameworks and interface builder architecture. You can take what used to be a command-line app and use Cocoa (or Carbon even, I think) and attach messages, mix and match Objective-C with C++, and create a stunning user interface.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
Originally posted by Mr.E:
<STRONG>The compiler does seem to work if I change the file name to source.c rather than source.cpp. However, it looks at the code as C instead of C++, and gives me a ton of errors. I definitely want to use C++, as that's the language I know inside and out.</STRONG>
Unixland is used to a .cc extension for C++ files. I think the .cpp extension was a Microsoftism, to hue to DOS's three-letters-only extension policy.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Apr 2000
Location: San Francisco, CA
Status:
Offline
|
|
Originally posted by 11011001:
<STRONG>OS X is a unix OS, so you can use much of the tools that you can in UNIX to compile simple command line programs that can be run in the terminal. But learning how to do this is probably harder and more time consuming than finding an answer to your problem...
Off hand, (I am in OS 9 right now and don't feel like restarting) I believe VI can compile or is that emacs? Or perhaps it was another UNIX text editor that I downloaded. Anyways, there are many unix text editors that can compile programs for you in the terminal, that can be used in the terminal.
On thing for sure, Apple Developer Tools does not have any easy way or any way, that I know of, to make anything for the terminal...
Anyways good luck with this... </STRONG>
Actually, the text editors (vi, emacs, etc) do not compile code, but you can use them to write code. You still need to issue the compile command on the command line (type out "cc ...", create a make file, or just use Project Builder which does it for you!).
What Project Builder calls a "tool" is really a standard C/C++ application in UNIX, which must be run from a shell environment. The easiest shell environment is the Terminal command line. So, Apple Developder Tools can write programs that run from the terminal's command line.
Michael Kamprath
|
--
Michael F. Kamprath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|