UNIX C Compile Error

Z

Zach_C

Guest
Sorry to ask on such a simple question, I'm new to UNIX and Macs although I am enjoying my switch from Windows. Here is my problem. Whenever I right a program in C++ or C I can not get it to run. Here is everything I do. I write the code in pico and save it in the appropriate file format in this case pawn.c. I can see the file in Apple's finder and it has a big C on it so I am assuming I did not mess up here. I then run Terminal and change to the appropriate directory hit ls to make sure and finally compile by typing cc pawn.c -o pawn

It all seems to go well. I go right back to the terminal prompt Zach [], but when I type pawn I get a bad command. So I looked at it in finder and it is just the standard white piece of paper icon and does not have a file extension when I go to get info.

Excuse my ignorance or references to Windows machines but shouldn't it be a .exe? Am I messing up in compiling. I checked online tutorials and they say to do it the way I did but my attempt was in vain. Any help is greatly appreciated.
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Check the directory where you compiled the program. You should find a file call pawn, as you said. To execute the file just enter at the prompt the following: ./pawn. That is dot slash pawn
 
OP
P

plunger

Guest
congrats on your switch! I am not much of a c programmer but I do spend a good bit of time on the command line of unix/linux machines. A few things to keep in mind:

->neither unix nor OS X could care less about a .exe extension...you could call the file little.willie_is_evil and unix wouldn't care as long as you have execute permission over the file.

->from the command line: ls -al
->this will show you all of the files in your current directory and their respective permissions and ownership.

->from the command line: man chmod
-> this will tell you more about changing ownership and permissions
-> you will probably want to do something like: chmod u+x ./pawn or chmod 711 ./pawn


-> once you have execut permissions (-rwxr--r-- or something like it) then you can just follow rman's advice and enter from the command line: ./pawn

-good luck!

-P
 
Joined
Feb 25, 2003
Messages
5,279
Reaction score
138
Points
63
Location
Tropical Island, Jealous?
Your Mac's Specs
MacPro 3.0Ghz 16GB RAM, 4x256 Vid, 30''cinema display
:) try out apple developer tools, and write your program in there. I hvn't had a problem with it aside from me screwing up a path or other error caused by me.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top