LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2006, 02:28 PM   #1
drimades
Member
 
Registered: Jun 2006
Posts: 60

Rep: Reputation: 15
Compiling C in Linux


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!!
 
Old 12-12-2006, 03:33 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,478

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
No.

There are two ways to include #include files:
Code:
#include <stdio.h>
#include "local.h"
Where "<stdio.h>" tells the compiler to look for the file in the /usr/include directory tree and "local.h" tells it to look in the current directory (using -Ipath-to-directory lets you tell the compiler to look for header files there).

Before you go too far down the C path, you may want to check Amazon.com or your local bookseller for a good introductory text.
 
Old 12-12-2006, 03:40 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
It depends on how you've configured your system. If you've used a default configuration, the include search paths should be defined, and "standard" system include files should not need to be copied to your "work" directory. If you've used your own configuration, you're -- of course -- "on your own."

If you're new to Linux and/or compilation on Linux distributions, you should try one of the IDEs available with most distributions. Or designed for specific "desktop" environments (e.g., GNOME or KDE or ...).
 
Old 12-12-2006, 06:41 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You may find this useful:
http://www.advancedlinuxprogramming.com/resources.html
 
Old 12-12-2006, 07:14 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
If you have an include file in a non-standard path, e.g. /opt/myincludes, you can include them with the -I option to gcc:
Code:
gcc -I/opt/myincludes -c cp.c -o cp.o
If you have includes from multiple directories, you can use more than one -I option:
Code:
gcc -I/opt/myincludes -I/opt/yourincludes ...
Note that when linking, you may need to link with libraries which are not in the default library path. You can include these library paths with the -L option. e.g. if you have a library file you need to link to: "/opt/mylibs/libmine.so", you would do it like this:
Code:
gcc -L/opt/mylibs -lmine cp.o -o cp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling c++ in linux deapee Programming 14 08-07-2012 12:05 PM
Compiling Linux 0.0.1? Vampirite Slackware 22 11-03-2008 04:28 AM
compiling linux FMAlchemist Linux - General 3 09-21-2006 07:06 AM
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 06:03 AM
Compiling in ACPI support on Compaq 2135CA (system crashes while compiling) Dag Linux - Laptop and Netbook 20 07-30-2004 08:56 PM


All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration