🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.os.linux.ubuntu
Article #117

Re: where to put custom headers

#117
From: Jan Seiffert
Date: Wed, 20 Jan 2010 18:32
78 lines
4303 bytes
frank schrieb:
> I'm replicating a program provided by Richard Heathfield in _C
> Unleashed_.  The custom header for this project is in the same directory
> as the source:
> 
> dan@dan-desktop:~/source/unleashed/ch11$ ls -l
> 
> -rw-r--r-- 1 dan dan  1612 2000-06-08 16:13 strarr.h
> 
> dan@dan-desktop:~/source/unleashed/ch11$
> 
> When I compile with -v, this is what I see:
> 
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/local/include
>  /usr/lib/gcc/i486-linux-gnu/4.3.3/include
>  /usr/lib/gcc/i486-linux-gnu/4.3.3/include-fixed
>  /usr/include
> End of search list.
> 
> On compilation, I get errors that indicate that gcc is not finding the
> header:
> dan@dan-desktop:~/source/unleashed/ch11$  gcc -std=c99 -Wall -Wextra
> t1.c -o out/tmp/ccmpPiuM.o: In function `ReadFile':
> t1.c:(.text+0x7e): undefined reference to `AllocStrArray'
> t1.c:(.text+0x147): undefined reference to `AddRowsToStrArray'
> t1.c:(.text+0x187): undefined reference to `ResizeOneString'
> t1.c:(.text+0x203): undefined reference to `AddRowsToStrArray'
> t1.c:(.text+0x246): undefined reference to `FreeStrArray'
> t1.c:(.text+0x269): undefined reference to `ConsolidateStrArray'
> /tmp/ccmpPiuM.o: In function `main':
> t1.c:(.text+0x322): undefined reference to `FreeStrArray'
> collect2: ld returned 1 exit status
> dan@dan-desktop:~/source/unleashed/ch11$
> 
> So it doesn't find a header in the same directory.

These are not messages from gcc not finding a header, these are messages from
the linker ("ld returned 1 exit status"). When you header contains more than
just a bunch of defines and datatypes, you need the coresponding object files
where the compiled code of the defined functions reside. Either as object files
(.o), archive (.a) or shared library (.so).
You have to pass them on the link line. Please look at the Manual for the
options -L and -l (for .o's you need no options).

Look around in your Ubuntu System, you have /usr/include, a bunch of system
header files (text only), and /usr/lib, where the librarys for the system libs
reside (the binaries).
Where you put your project stuff, thats up to you. As long as your project is
not part of the installed System, it has no business in writing to the system paths.

Maybe before you "unleash" C, you want to read a tutorial on how building
software under Unix works (or more concrete the classic multipart C stack:
preprocessor, compiler, assembler, linker), because you just ran into the "what?
a header is not the complete lib"-FAQ

> So, I decide to put
> the header where gcc *is* looking, but ubuntu won't let me put a header
> in any of the directories that are included in the search.
> 

Because these are system directories, you need the right permission to do so.
Something with "sudo cp ..."

> Question 1:  Where am I supposed to put home-rolled headers when I
> compile with gcc on ubuntu?
> 

Right beside the rest of your project, no need to put them somewhere else.

> Thanks for your comment.
Greetings
	Jan

-- 
Fun things to slip into your budged:
Traffic shaping on the loopback interface
Technical Details
Message-ID: <hj7i8j$543$00$1@news.t-online.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
References: <7ror8bFjn6U1@mid.individual.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1200bcf240,4af9266eb6a90621
X-Google-Attributes: gid1200bcf240,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
From: Jan Seiffert <nomail@invalid>
Newsgroups: alt.os.linux.ubuntu,gnu.gcc.help
Subject: Re: where to put custom headers
Date: Wed, 20 Jan 2010 19:32:50 +0100
Organization: T-Online
Lines: 78
Message-ID: <hj7i8j$543$00$1@news.t-online.com>
References: <7ror8bFjn6U1@mid.individual.net>
Reply-To: kaffeemonster@googlemail.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1264012371 00 n5251 bEgjpJKlv65n+P 100120 18:32:51
X-Complaints-To: usenet-abuse@t-online.de
X-ID: ZBLfdGZZZeXZATsjaz2SkylaVnzh-7NE1mFfabXaaSGes4n79vY40L
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20100118 Gentoo/2.0.2 SeaMonkey/2.0.2
In-Reply-To: <7ror8bFjn6U1@mid.individual.net>
X-Enigmail-Version: 1.0