Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiling C in Linux 1

Status
Not open for further replies.

drimades

IS-IT--Management
Nov 8, 2004
221
MK
If I want to compile the source code for a command (say cp.c) do I have to copy all the included files in the same directory of the source code? It would be a problem because the source code contains too many #include-s!!
 
Code:
gcc -o cp cp.c

will give you an executable "cp."

But there are lots of options that you may want to use, like -Wall.

The headers should be in the development library directories, or local to the executable. For instance stdio.h is a standard I/O library header that should already be in a development library on your system. The -Wall switch will display warnings and errors to the console while it attempts to compile the binary.


pansophic
 
> do I have to copy all the included files in the same directory of the source code?
That depends on what the include files are.

If it's things like
[tt]#include <stdio.h>[/tt]
then you don't have to do anything special. You can see all the standard include files in the /usr/include directory.

If it's things like
[tt]#include "cp.h"[/tt]
then that usually means it's a file local to the module being compiled. Typically, these are in either the same directory or a relative directory close by (say [tt]../inc/cp.h[/tt] )

If you have a lot of files close by, then you can do this on the command line
[tt]gcc -I../inc cp.c[/tt]
The -I option tells the compiler where else to find include files.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top