Mac GCC and ifstream command line fix? [SOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
jmcintyretech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu Mar 28, 2013 1:02 pm

Mac GCC and ifstream command line fix? [SOLVED]

Post by jmcintyretech »

Hey guys,

I'm trying to compile my code on OSX Snow Leopard (Virtual Machine). I'm using the GCC compiler WITHOUT XCode (http://kennethreitz.org/xcode-gcc-and-homebrew/). My code is all ISO C++ with no external libraries and compiles fine. However, when I run the program, ifstream does not read anything from the file. (I get blank lines where there should be stats for the game characters).

After DuckDuckGo-ing the problem I found a solution that has worked for developers using Xcode: Delete the preprocessor macros _GLIBCXX_DEBUG=1 and _GLIBCXX_DEBUG_PEDANTIC=1 from the project settings.

However, I am only using the GCC compiler derived from the one packaged with XCode, not the actual IDE. Does anyone know how to remove these options while compiling from the terminal?
Last edited by jmcintyretech on Tue Aug 13, 2013 9:40 am, edited 1 time in total.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Mac GCC and ifstream command line fix?

Post by Falco Girgis »

Code: Select all

 -D_GLIBCXX_DEBUG=0 -D_GLIBCXX_DEBUG_PEDANTIC=0
Although I highly, highly doubt that is your actual problem. I have used GCC from the command-line many times before, and that is what IDE's like QtCreator are doing behind the scenes. Are you positive that your file is actually in your application's working directory? Are you checking to see if the stream is valid or if the file has been opened properly before reading from it?

edit: Actually, this isn't necessary. Those aren't defined by default... which means this can't be your problem.
jmcintyretech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu Mar 28, 2013 1:02 pm

Re: Mac GCC and ifstream command line fix?

Post by jmcintyretech »

Hmm. I'll add some code to check and see if the file is being opened and read, etc. Like I said this code is working properly in Linux and Windows, and the file is in the same directory as the executable. I'll see if I can further pinpoint where the problem lies. Thanks for the reply Falco!
jmcintyretech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu Mar 28, 2013 1:02 pm

Re: Mac GCC and ifstream command line fix?

Post by jmcintyretech »

Looked into this further tonight and found an odd solution. If I navigate to the program directory in the terminal and execute it from there, it works fine. I only have this issue when clicking on the executable to run it. Huh. Maybe when you execute an application by double clicking it runs from a different location? I'll do some research and see why that is :) Thanks again for the help.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Mac GCC and ifstream command line fix?

Post by Falco Girgis »

Interesting.

Try this at the command-line to display the working directory of your processes:

Code: Select all

lsof -d cwd
jmcintyretech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu Mar 28, 2013 1:02 pm

Re: Mac GCC and ifstream command line fix?

Post by jmcintyretech »

Tried that handy command.

Turns out that when I double click the executable, it starts it in the home directory /Users/josh

No shit! There's the source of my problem :lol:

Thanks again :lol:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Mac GCC and ifstream command line fix?

Post by Falco Girgis »

Why the fuck... I wonder if there's some OSX-specific flags you can pass to GCC on OSX to make it disable retardism...
jmcintyretech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu Mar 28, 2013 1:02 pm

Re: Mac GCC and ifstream command line fix?

Post by jmcintyretech »

g++ main.cpp -o main_osx -quit_being_a_dumb_os

:lol: :lol: :lol:
Post Reply