Xcode question....

Hi, so I have a quick question.

I’m starting an into to CS class, and I need to use Xcode in the most simple way possible. I have tried the “New File” but for some reason I can’t get it to “compile and run” from the normal menu. However, when I manage to do it from within a project, I can.

What I’m asking is, does anyone know of a certain way I can add code to a single file, and simply have it work like a basic complier? I need to edit source, and once it is compiled, create object code. That’s it.

Anyone have any ideas?

I’m writing C++ btw.

That’s the problem – XCode doesn’t know what you’re writing. Your text file could be anything, so it needs to know which compiler to use, which system libraries to build against, build location, object file locations, and all sorts of stuff. That’s generally a royal pain in the butt.

If you want to write normal command line C++ applications for something that a CS class would have, do File–>New Project, and then look in the category for “Command Line Utility” and select the C++ Tool. Walk through the Assistant, and you’ll be all set. As much as I hate every progression of the Windows operating system due to their damned wizards getting in my way, at least the XCode project assistant really is the fastest way to get set up in a hurry.

Thanks, that’s what I had been doing, but why couldn’t I do File => New File… Then select BSD C++ File. I did that before and I couldn’t compile it…

PS, should I not be using a windows-based compiler? Could I run into troubles with this later on?

Are you naming your new file with a standard C++ extension (".cpp" or “.c++”)? This is the easiest way to tell XCode how to compile it.

If you’re already made a “Command Line Utility” project like Balthisar suggests, and you’re trying to add a new source file to the project, try adding an “Empty” file (it’s at the top of the selection dialog), and name the file with a “.cpp” extension. Then type in C++ code as desired.

. . . assuming you desire such a thing.

Your development environment is up to you, and maybe your teachers’. In the end, you’re just compiling with gcc, which is the same on Windows and Unix as well. Assuming you don’t use Apple libraries, I’m pretty sure you can cross-compile for these other OS’s as well (well, for Windows using cygwin).

Speaking of which, as much as I like XCode, do you really need to use it? Could you just do everything from the command line?

Xcode just passes a bunch of arguments to the compiler and linker. I use it to do Microcontroller development, and it’s just much nicer than having to use a separate editor.

Thanks, I guess that sounded like I was asking the question for myself. I was trying to point out to the OP that if he just wanted to compile a some code, it could be done from the command line, without the need for XCode.