Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm having trouble getting a small source code compiled in the terminal. I'm completely new at this (just started taking an introductory course)... I'm going to try to describe the situation as best I can, so bear with me.

This is what I've done:

I opened Aquamacs and started working on a new file I called "CerealBox". I noticed the words were not in colors, so I started poking around until I found a setting to change the buffer to C++ mode. Then, I had the colors..

So I wrote the source code and I'm pretty sure I have everything done right (my professor wrote this out step by step on the board and I only copied it onto the editor).

I go to the terminal and type in

g++ -Wall -c CerealBox.cpp

as instructed to me by my professor, and the thing answers back saying

"No such file or directory"

"No input files".

I have no idea what to do! Nobody in my class uses Mac OS, so they're no help! Please, help if you can!

PS: When I save the CerealBox file, it turns up in finder as a blank page icon with the name CerealBox under it. When I click on it, I get a small window with the source code in black text. Shouldn't this be opening up with Aquamacs when I click on it? Is that my mistake?

Another thing, why is Aquamacs not running on C++ from the start, I mean, why don't I get the colorful words right when I start it up? I don't think I had that problem last time I used it.

share|improve this question
    
#include <iostream> using namespace std; int main() { int weight_in_oz, boxes_per_ton; double oz_per_ton = 35273.92, weight_in_tons; cout << "What is the weight in ounces per box of cereal?\n"; cin >> weight_in_oz; weight_in_tons = weight_in_oz / oz_per_ton; boxes_per_ton = oz_per_ton / weight_in_oz; cout << "If you have a box of cereal that weighs " cout << weight_in_oz << " ounces, then in weighs " cout << weight_in_tons << " metric tons and you need " cout << boxes_per_ton << " boxes to complete one metric ton.\n"; return 0; } –  Andrea Sep 15 '11 at 20:43
    
That is the source code I'm trying to compile... I wrote ".cpp" at the end of the name and it keeps telling me I have a mistake. It says: 167-206-54-24-dynamic:~ andreagarcia$ g++ -Wall -c CerealBox.cpp CerealBox.cpp: In function ‘int main()’: CerealBox.cpp:17: error: expected `;' before ‘cout’ –  Andrea Sep 15 '11 at 20:45

1 Answer 1

If your file is called CerealBox (and not CerealBox.cpp), then you should rename the file to CerealBox.cpp first to make it clear that it's a C++ source file.

Then try again:

g++ -Wall -c CerealBox.cpp

For g++ it wouldn't really matter how the file's called, but …

why is aquamacs not running on C++ form the start, I mean, why don't I get the colorful words right when I start it up?

This is exactly because it doesn't know the file is a C++ source file. AFAIK, there's no language guessing or automatic syntax highlighting based on the contents alone. You need the extension for that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.