Newbie needs help with Xcode

Discussion in 'Mac Apps and Mac App Store' started by usrg, Feb 18, 2004.

  1. usrg macrumors newbie

    Joined:
    Oct 8, 2003
    Location:
    Austin, TX
    #1
    Hey y'all, I'm pretty new to Xcode and I'm having trouble with some basic programs (like "Hello World!").

    Basically, I can't get this following snippet of code to work:

    #include <iostream.h>
    // or alternately, using #include <iostream> and then <using namespace std;> but without the angle brackets

    void main () {
    cout << "Hello World!" << endl;
    }

    The error I am getting is that iostream.h isn't found. I've done a search and it's in

    /usr/include/gcc/darwin/2.95.2/g++/iostream.h
    /usr/include/gcc/darwin/3.1/g++-v3/backward/iostream.h
    /usr/include/gcc/darwin/3.3/c++/backward/iostream.h
    /usr/include/php/Zend/zend_istdiostream.h

    so why isn't it finding it? Is there some framework I need to include for it to work? What kind of target should I be making for such a simple bit of code? I've done some googling on this, and the only thing I've found was a thread on this forum saying that using namespace std was needed, though I've tried that, too. Any suggestions/tips would be helpful. Thanks!
     
  2. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #2
    This is the code I get when I create a C++ tool using Xcode:

    #include <iostream>

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

    and that works just fine.
     
  3. usrg thread starter macrumors newbie

    Joined:
    Oct 8, 2003
    Location:
    Austin, TX
    #3
    Thanks for the help! It worked! I was using an Empty Project and didn't know I needed libstdc++.a as a resource. But now I'm getting into the more complicated part of my problem. I'm trying to get a simple OpenGL program working, and I got it working using a Carbon Application Target, but that doesn't work with the C++ Tool Project type. ('cuz I needed to include a dirt.ppm texture file, which works when I put it in Bundled Resources, but the default target type doesn't have that option with the C++ Tool Project.

    ....So after all that, I guess my basic question is... what is the default target type for a C++ Tool Project?

    I guess also I should be asking... how can I get my code to compile with libstdc++.a when I make a Carbon Application Target?


    Thanks! :)
     
  4. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #4
    Well, any of the tool projects should work properly in a shell environment, but not in a GUI environment. Consider that there is no notion of stdout in Carbon. You must output to a window. If you want, there is text output through the standard OpenGL APIs. Also, if you're proficient with C++, you could create a class similar to cout which would:

    create a window, if one wasn't available

    output text and formatting in similar fashion to the scrolling text version

    and remove/destroy the window on destruction of the class

    (I would go with the OpenGL APIs, since you should learn to use them anyway.)
     
  5. usrg thread starter macrumors newbie

    Joined:
    Oct 8, 2003
    Location:
    Austin, TX
    #5
    Ah, so there is no stdout in Carbon. I did not know that. Is there nothing that will let me work in a GUI environment that will still let me do simple "cout" 's to the console? I'm not in a pure Apple GUI environment anyhow (I'm using GLUT). Basically, I'm trying to get my _very_ basic OpenGL program to work in Xcode (it works in linux with X & GLUT, but it could still output basic cout to the console).
     
  6. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #6
    I'd suggest looking at the Apple developer site as they recently posted a new OpenGL sample and they have others. I've done some pure OpenGL and Carbon-only, but never tried to mix the two.

    If I think of anything else, I'll let you know.
     
  7. usrg thread starter macrumors newbie

    Joined:
    Oct 8, 2003
    Location:
    Austin, TX
    #7
    Thanks for all your help. I may just end up doing the project in the CS Linux lab at school for this first project (time is a factor). In the meantime, I think I'll pick up an Xcode book/tutorial/whatever and try to figure out what I'm doing wrong for my next project. :)
     
  8. ingenious macrumors 65832

    ingenious

    Joined:
    Jan 13, 2004
    Location:
    Virginia, United States (Kansan in exile)
    #8
    book? ebook? pdf?

    What language does XCode use? I want to learn to use it so that i can write software (simple stuff). I have some programming knowledge (HTML and some Javascript) but know nothing about OpenGL or C++. Any good book, ebook, link, or PDF that would teach me the basics?
     
  9. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #9
    The Xcode editor knows how to handle pretty much any language that's on the system from Objective-C, C, C++, and Java to shell scripting to Ruby and perl.

    Projects are based on C, C++, Objective-C, or Java, though.

    Go to Apple's developer site and take a look. There are also many example projects that are installed with the developer tools with which you can experiment.
     
  10. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #10
    Re: book? ebook? pdf?

    technically HTML isnt a programming language...
    JavaScript is though.
    And Xcode should support all languages you can compile using gcc.
    For a beginner language DONT LEARN C!!!!!! egads, it's horrible. Learn Java or something, and if you wanna go further on the Mac platform learn Objective-C.
    I've heard that Ruby is an excellent language too...
    Don't forget C# too :)
     
  11. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    I don't know about Carbon (it's so OS9!) but in Cocoa you can use NSLog to print statements to the system log. When you run your code from XCode these appear (timestamped and so in) in the run window. There is probably a similar debug system for Carbon...
     
  12. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #12
    Re: Re: book? ebook? pdf?

    Everyone interested in programming should be proficient in C. You can be good at something you don't like. If everything is easy, why bother?

    JavaScript is moreso considered a scripting language than a programming language.
     
  13. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #13
    Pretty much if you don't compile it people won't count it as a programming language. If it uses < & > predominantly then it's considered a markup language. Anything in between is a scripting language (it types like a programming language but is never compiled).
     
  14. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #14
    Re: Re: Re: book? ebook? pdf?

    If you want to learn everything the wrong way, then by all means, learn C. :rolleyes:

    C++ is okay, though. But I would recommend Java for beginners. (To keep them away from the error prone pointers). C and C++ in combination with slightly inexperienced programmers is also the best way of ensuring there'll always be some buffer overflows for hackers and virus writers to exploit.
     
  15. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #15
    Re: Re: Re: Re: book? ebook? pdf?

    Obviously, it's not the inexperienced programmers who are causing most of the buffer overflows, it's merely undisciplined programmers, who come in all levels. Since C++ is more prevalent on Windows, buffer overflows happen much more often there. It's as easy to create them in Objective-C on Mac OS X.

    Still, there are plenty of pointers in Objective-C and Java is all about pointers but doesn't call them that at all. (Ask me about the NullPointerException message in Java!) :D
     
  16. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #16
    Re: Re: Re: Re: Re: book? ebook? pdf?

    Well, even if a reference and a pointer share one basic thing, they both point to some data or object, there are some fundamental differences that make java-style references easier for most programmers.

    C-Pointers can be assigned to point anywere, you can do pointer arithmetic and you have special operators to reference, dereference and pass by this-and-that. These features can be very powerful, but are also very difficult to get right. If something is wrong with your pointers, lot's of things can happen.

    1: Everything works despite the bug. It may show up years later maybe when some other feature is added to the program or it may make the program vulnerable to hacker-exploits.

    2: Everything seems to work, but the result of some calculation is wrong. Sometimes it's very difficult to track the error down to the specific wrong pointer.

    3: The program runs out of memory after some time. Because of a memory leak caused by pointers that are pointed to some other objects without deleting the old unused ones.

    4: The program terminates with no useful error message.

    With java-references, the program terminates if there's a reference bug, you get a NullPointerException (or ClassCastException), and you get told where in the program this happened.

    Also ...
    If you design a program with I/O without security in mind in C or C++, chances are very good that you'll create a program that can be used by a hacker to run arbitrary code, and help him break into the computer.

    If you design a program with I/O without security in mind in Java, chances are that a hacker may be able to crash the program, but at least he'll not be able to run arbitrary code.
     
  17. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #17
    Please understand that all my work lately has been in Java. I strongly believe in it over any other language for interactive work that doesn't deal with money.

    I still stress that understanding how to code well in C, and building those disciplines will help immensely in any coding to follow. (This is not to say that most instructors have any clue as to how to teach disciplined C.)
     
  18. urchinsub macrumors newbie

    Joined:
    Nov 23, 2009
    #18
    Java vs C++

    The problem with everyone telling people to learn Java first because it is easier is that they learn to use Java style variables the java way (they are actually pointers with asterisk(*) syntax) and then when they learn serious programming with the so-called "unsafe" languages like C++ (the most successful useful language ever) they are even more confused than if they just started with it to begin with. The supposedly confusing unsafe pointer syntax of C++ gives it an advantage that Java can't emulate.
     
  19. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #19
    Worse than that they confuse their IDE with the code they are writing. This post has nothing to do with help with XCode (the IDE) and everything to do with a fundamental lack of basic C.
     

Share This Page