🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: where to put custom headers

#118
From: frank
Date: Fri, 22 Jan 2010 02:38
96 lines
4730 bytes
BJ wrote:
> On Wed, 20 Jan 2010 10:02:04 -0700, frank <frank@example.invalid> wrote:
> 
>> 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.  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.
>>
>> Question 1:  Where am I supposed to put home-rolled headers when I 
>> compile with gcc on ubuntu?
>>
>> Thanks for your comment.
> 
> The previous responses looked good to me, but there is information
> missing in your post.
> 
> We generally put our own headers in the same directory as the rest of
> the source code. The include statement should enclose the file name in
> quotes, which tells the compiler to look for the file in the source
> directory. System supplied headers are enclosed in <> (guillemets). This
> tells the compiler to look in the gcc include directory.
> 
> Is there a .cpp or .c file with the same name as the header? It should
> also be in the source directory. If it exists it should be compiled
> along with your other .cpp or .c files. If it doesn't exist, but there
> exists a file with the same name as the header file, but with a .o or
> .so extension, see the previous posts.
> 
> BJ
> Barry Jones

Thanks all for responses.  I was missing a source file with the 
definitions of the functions that the linker couldn't find.  Having the 
header right there next to the caller wasn't a problem for gcc.

So I was misunderstanding what gcc was telling me.  As long as I'm 
talking about messages I don't understand from gcc, what about:


> dan@dan-desktop:~/source$ gcc -std=c99 -Wall -Wextra rd2.c -o out; ./out
> rd2.c: In function �process_directory�:
> rd2.c:40: warning: implicit declaration of function �readdir_r�
> rd2.c:48: warning: implicit declaration of function �lstat�
> rd2.c:66: warning: implicit declaration of function �readlink�
> dan@dan-desktop:~/source$ 

( I can only paste as quotation.  What a pain.), when I have the right 
headers included:
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <string.h>
> #include <limits.h>
> 
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <dirent.h>
> #include <unistd.h>

It links and behaves fine.
-- 
frank
Technical Details
Message-ID: <7rshd7Fa3vU1@mid.individual.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
References: <7ror8bFjn6U1@mid.individual.net> <4b578c9a$0$18138$a9266ab1@news.buzzardnews.com>

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,CP1252
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: frank <frank@example.invalid>
Newsgroups: alt.os.linux.ubuntu,gnu.gcc.help
Subject: Re: where to put custom headers
Date: Thu, 21 Jan 2010 19:38:29 -0700
Lines: 97
Message-ID: <7rshd7Fa3vU1@mid.individual.net>
References: <7ror8bFjn6U1@mid.individual.net> <4b578c9a$0$18138$a9266ab1@news.buzzardnews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net W3FR48ukpM3/EoNzX/Q5CQLobRnBaDDEaPrXSnO5KSNsjDTP5Q
Cancel-Lock: sha1:0nAClduShsOkJJ3c9v4Ao70OWLU=
User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
In-Reply-To: <4b578c9a$0$18138$a9266ab1@news.buzzardnews.com>