New to C++ Compiling

Discussion in 'Mac Programming' started by S1owJam, Sep 14, 2010.

  1. macrumors newbie

    Joined:
    Sep 14, 2010
    #1
    I'm taking an algorithm design course for college and it requires a C++ Compiler. I downloaded Visual C++ Express 2008, but can't register it, so I decided to stick with the native Xcode 3.2. I am only having one problem that I can't understand between Visual C++ and Xcode, and that's something about breakpoints. When I run this program"

    Code:
    /*   
     * File: helloYou.cpp  
     * ---------------------  
     * This program prints a more personal greeting  
     * by reading in the name of the user.*/
    
    #include <iostream>  
    #include <string>  
    using namespace std;  
    int main()                                   
    
    { 
    	string name = "";   
    	cout << "What is your name?: ";  
    	cin >> name;     
    	cout << "Hello, " + name + "!" << endl;  
    	return 0;  
    }
    
    and build it I don't get any errors. I was able to run this same program with Visual, however whenever I run the program with Xcode and input a name, I get this,

    Code:
    test(2019) malloc: *** error for object 0x100006280: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    I just can't figure out how to resolve this. I tried messing around with the breakpoint button in the command window, but nothing seems to work. This is the only thing that seems to be blocking me from making a trouble-free move from Visual to Xcode, and any help would be greatly appreciated!
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    This comes up all the time. It is sad.

    You need to undefine the macros:
    _GLIBCXX_DEBUG=1 and _GLIBCXX_DEBUG_PEDANTIC=1

    Go into the settings for your build target, search for preprocessor, and remove these.

    Consider using getline, some names have spaces.

    -Lee
     
  3. thread starter macrumors newbie

    Joined:
    Sep 14, 2010
    #3
    those two macros weren't there, I didn't see any macros there.
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    How did you get there? I am sure that this is the problem. Try get info on the build target.

    -Lee
     
  5. macrumors 6502

    Joined:
    Mar 12, 2010
    #5
    If you compile on the command line with those macros set you get the same error. Probably somewhere in your xcode environment those are getting set. I'm not xcode expert, but perhaps they get set automagically when compiling debug? There must be someway to see the actual compile command that xcode is generating.

    BTW, I think it's just the GLIBCXX_DEBUG macro that is causing the problem. No mac in front of me so I can't test that.
     
  6. thread starter macrumors newbie

    Joined:
    Sep 14, 2010
    #6
    I go to the Project toolbar, and click on Edit Project Settings
    [​IMG]

    When I get there this is what I see after I search for preprocessor
    [​IMG]

    Is that not the right place?
     
  7. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    Try Edit Active Target "test" instead. As an aside, this is why I recommend using command-line tools until you really need an IDE.

    -Lee
     
  8. thread starter macrumors newbie

    Joined:
    Sep 14, 2010
    #8
    Went into the Edit Active Target "test", same thing. I'm not seeing the GLIBCXX_DEBUG macro anywhere.
     
  9. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #9
    Looks like for "Configuration" you have "All Configurations" selected. Try to change to "Debug".

    Also, from the terminal, with your code in a file called "helloYou.cpp" in the current directory:
    make helloYou
    ./helloYou

    That's about 1 minute, tops. This XCode issue has been plaguing you for nearly 24 hours. For a program with about a dozen lines, that's too much. Visual C++ and XCode are both too much. Not just for this project, but probably the whole course you're taking.

    -Lee
     
  10. macrumors 65816

    Joined:
    Sep 19, 2009
    #10
    Although I have made use of the full IDE part of Xcode, I usually just use the text editing part, which is very nice. Choose File > New File... or ⌘N. I use the command line tools to compile.
     
  11. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #11
    I use TextWrangler sometimes if I just need to edit some code. Any other suggestions for code editors? It'd be nice if there were buttons to run make/gcc.
     
  12. macrumors 65816

    Joined:
    Sep 19, 2009
    #12
    I'm not aware of any, but then again I'm not too experienced. :p I typically use vi or emacs to make fast adjustments. [edit: there is Xemacs, but that is pretty much a compile-it-yourself affair for Macs]
     
  13. thread starter macrumors newbie

    Joined:
    Sep 14, 2010
    #13
    That worked, thanks for your help.
     
  14. macrumors newbie

    Joined:
    Aug 12, 2012
    #14
    Issues with cin for characters in XCode 3.2

    I am having the exact same issue as the original post in this thread. Any time I use the command cin for a character or string (anything other than integers or doubles) I get an error message. Everything is declared properly and I have tried using getline commands.

    It seems as if the person with this problem was able to solve it by changing Configurations from "all" to just "debug" but that is not solving my issue. I've also looked to undefine the macros _GLIBCXX_DEBUG=1 and _GLIBCXX_DEBUG_PEDANTIC=1 but can't find them - and I don't even know what they are!

    I am VERY new to programming and I'm frustrated. Please help!
     

Share This Page