Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nettle picker

macrumors newbie
Original poster
May 11, 2014
15
2
Hi all,

I study C++ and use Xcode. Can't boast much of a progress so far but that's irrelevant :). Naturally I have to write plenty of short programs and this is where my question stems from: how to organize this rapidly growing library of short programs? To create a separate project for every dozen-row program? To add a new file? I tried adding "C++ class" file, didn't work for me - the program compiled OK but there was no output.

Anyone had the same problem?
 
Xcode is overkill for such short programs - don't bother with it. Write your programs in a text editor and compile them through the command line.
 
Another possible solution ( particularly if all the "short" programs share some common code ), is to put several ( or all depending how you want to manage ) of the short programs in one Xcode project with multiple targets. This works well if the short programs are all command line ( i.e. based on Foundation only with no AppKit/UIKit ) without a nib. YMMV.
 
1. Is each program a single self-contained file? Or does a single program ever encompass multiple files?

2. Are there any common or utility classes or functions that will be used in multiple programs? That is, in addition to the "multiple file" criterion, are some of those multiple files reused?

If the answers to either of the above are "Yes", then you can make an Xcode Target for each program.

What is a Target:
https://developer.apple.com/library/mac/featuredarticles/XcodeConcepts/Concept-Targets.html

Making Targets in a Project:
https://developer.apple.com/library...ect_editor/articles/EditingBasicSettings.html

You should also consult Xcode's builtin Help on understanding, making, and managing Targets. For example, I'm pretty sure you can still duplicate an existing target and modify it, rather than always making a new one from scratch.
 
Thank you very much for your comments. Looks like I'm gonna have to use text editor and run gcc(g++) in command line.

chown33, so far every program is a single file. Haven't gotten to classes yet. But thank you for the URLs.
 
Thank you very much for your comments. Looks like I'm gonna have to use text editor and run gcc(g++) in command line.

Check to see if you have the 'make' cmd. If so, then it has some builtin rules for making programs from single source files. For example, if you have a file /foo.cpp' in the current directory, and you enter this command line:
Code:
make foo
then make will know how to make 'foo' by compiling with the correct compiler.
 
chown33, it didn't work:

Code:
$ make test1.cpp
make: Nothing to be done for `test1.cpp'.

So I always run:
Code:
$ g++ ./test1.cpp -o ./test1
$
$ ls ./ | grep test | grep -v .cpp
test1
 
chown33, it didn't work:

Code:
$ make test1.cpp
make: Nothing to be done for `test1.cpp'.

So I always run:
Code:
$ g++ ./test1.cpp -o ./test1
$
$ ls ./ | grep test | grep -v .cpp
test1
If the file was foo.cpp, the command would be:
Code:
make foo
That's pretty much what I wrote before.

So if you have test1.cpp, use this command:
Code:
make test1
The make command doesn't know how to "make" a cpp file. It DOES know how to make an executable (test1) FROM a cpp file.

The cpp file is a source file, not a target. Make can apply actions TO sources that PRODUCE targets. It can't PRODUCE sources.
 
chown33, it didn't work:

Code:
$ make test1.cpp
make: Nothing to be done for `test1.cpp'.

So I always run:
Code:
$ g++ ./test1.cpp -o ./test1
$
$ ls ./ | grep test | grep -v .cpp
test1

Make makes the most sense if you have multiple files. Although you'll write less in this case, it'll also give you less options than just typing out what to do with g++ imo.
 
Xcode is overkill for such short programs - don't bother with it. Write your programs in a text editor and compile them through the command line.

I disagree with Art. I love Xcode because of the integration with the debugger, etc. I have a special project set up just to test small code examples. I keep them in the project and call them from main() to test them. The finder is a great way to organize files in folders.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.