PDA

View Full Version : New to C++ Compiling




S1owJam
Sep 14, 2010, 09:22 PM
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"

/*
* 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,

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!



lee1210
Sep 14, 2010, 09:58 PM
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

S1owJam
Sep 14, 2010, 10:28 PM
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

those two macros weren't there, I didn't see any macros there.

lee1210
Sep 14, 2010, 10:46 PM
How did you get there? I am sure that this is the problem. Try get info on the build target.

-Lee

willieva
Sep 15, 2010, 09:26 AM
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.

S1owJam
Sep 15, 2010, 05:08 PM
How did you get there? I am sure that this is the problem. Try get info on the build target.

-Lee

I go to the Project toolbar, and click on Edit Project Settings
http://i577.photobucket.com/albums/ss213/swimmer160/Screenshot2010-09-16at10139AM.png

When I get there this is what I see after I search for preprocessor
http://i577.photobucket.com/albums/ss213/swimmer160/Screenshot2010-09-16at10244AM.png

Is that not the right place?

lee1210
Sep 15, 2010, 07:06 PM
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

S1owJam
Sep 15, 2010, 08:04 PM
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

Went into the Edit Active Target "test", same thing. I'm not seeing the GLIBCXX_DEBUG macro anywhere.

lee1210
Sep 15, 2010, 08:46 PM
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

mac2x
Sep 15, 2010, 11:40 PM
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.

robvas
Sep 16, 2010, 09:24 AM
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.

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.

mac2x
Sep 16, 2010, 01:37 PM
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]

S1owJam
Sep 16, 2010, 05:01 PM
Looks like for "Configuration" you have "All Configurations" selected. Try to change to "Debug".


That worked, thanks for your help.

Lightenbulb
Aug 12, 2012, 02:08 PM
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!