Thread: Quick questions with linking?

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    Quick questions with linking?

    I was just wondering if you were compiling to get a header? like

    /home/Desktop main.c
    and the header for that was in
    /home/Desktop/h

    i would probably have to

    gcc -I./h main.c main

    Something like that but I was wondering if i just added in the path

    export PATH=$PATH:/home/Desktop/h

    Would that be the same thing as linking in the compile line so i would only have to

    gcc -o main.c main

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I do not think that the compiler will check the system path for include locations, but it depends on the compiler implementation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Not the system path, but gcc does follow $C_INCLUDE_PATH, which is undefined by default.

    C_INCLUDE_PATH=$HOME/C/include

    The g++ equivalent is CPLUS_INCLUDE_PATH.
    Also, gcc/g++ or ld (the GNU linker) follows this one:

    LIBRARY_PATH=$HOME/lib

    You can export those from your .bashrc. Then you can compile yer libraries, put them ~/lib, put the headers in ~/C/include, and use:

    Code:
    #include <myheader.h>
    gcc whatever.c -lmylib
    Last edited by MK27; 04-16-2010 at 01:03 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A few quick questions
    By Brodie337 in forum C Programming
    Replies: 12
    Last Post: 04-06-2009, 01:00 AM
  2. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  3. two quick questions
    By procyon4476 in forum Tech Board
    Replies: 6
    Last Post: 03-24-2003, 10:24 AM
  4. 2 quick questions
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 03-02-2002, 10:37 AM
  5. Couple Quick Questions.
    By Darkflame in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2001, 03:44 PM