Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

c compiling using clang

0 views
Skip to first unread message

Arnab Bhowmick

unread,
Apr 26, 2016, 12:50:02 PM4/26/16
to
I am new to Freebsd. I want to practice c programming for my college
projects. I have wrote some program but when i am trying to compile the
program by using
% cc filename.c its showing % not found. I went through the handbook but
did not understand the process. Previously i have used clang compiler on
Ununtu but i think that it is a little bit tricky to compile c under
freebsd. Can anyone say how to resolve this?
_______________________________________________
freebsd-...@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questi...@freebsd.org"

John Howie

unread,
Apr 26, 2016, 12:57:58 PM4/26/16
to
Hi Arnab,

The ‘%’ is the UNIX (FreeBSD) prompt, shown in examples in text books. Do not type it in. Depending on your shell, and whether or not you are running as root, you might have $ or # as your prompt instead, or even something fancier depending on how your profile is setup.

Just type “cc filename.c” (not the quotes, they are there to highlight what to type). This will produce a file called a.out. You run that by typing “a.out” (again, do not type the quotes). If you want to compile your program to a named file you would type “cc -o myfile filename.c”, and to run the program just type “myfile”.

Regards,

John

Steve O'Hara-Smith

unread,
Apr 26, 2016, 1:23:07 PM4/26/16
to
On Tue, 26 Apr 2016 16:56:29 +0000
John Howie <jo...@thehowies.com> wrote:

> Hi Arnab,
>
> The ‘%’ is the UNIX (FreeBSD) prompt, shown in examples in text books. Do
> not type it in. Depending on your shell, and whether or not you are
> running as root, you might have $ or # as your prompt instead, or even
> something fancier depending on how your profile is setup.
>
> Just type “cc filename.c” (not the quotes, they are there to highlight
> what to type). This will produce a file called a.out. You run that by
> typing “a.out” (again, do not type the quotes). If you want to compile
> your program to a named file you would type “cc -o myfile filename.c”,
> and to run the program just type “myfile”.

Just one nit "./a.out" and "./myfile" the current directory is not
usually in the path searched for executables.

--
Steve O'Hara-Smith <st...@sohara.org>

John Howie

unread,
Apr 26, 2016, 1:30:11 PM4/26/16
to
Good point, Steve!

Polytropon

unread,
Apr 26, 2016, 6:20:40 PM4/26/16
to
On Tue, 26 Apr 2016 22:19:40 +0530, Arnab Bhowmick wrote:
> I am new to Freebsd. I want to practice c programming for my college
> projects. I have wrote some program but when i am trying to compile the
> program by using
> % cc filename.c its showing % not found.

That's the correct and expected behaviour, as the "%" character
is not part of the command you should enter. It's the shell's prompt
character shown to illustrate that the command should be entered from
a user account (in opposite to the root account where "#" is used).
You will see this way of "implicit documentation" in many places.



> I went through the handbook but
> did not understand the process. Previously i have used clang compiler on
> Ununtu but i think that it is a little bit tricky to compile c under
> freebsd.

It's the same, except on Ubuntu you'll probably see a "$" infront of
command line examples.



> Can anyone say how to resolve this?

Do not enter the "%" character, just the command. To illustrate:

% cc filename.c
% ./a.out

or

% cc -o myprog filename.c
% ./myprog

Note that the "./" is needed infront of the program name you just compiled
because the current working directory usually is not in $PATH, so the shell
will not execute programs from that location unless explicitely specified.



--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
0 new messages