Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.misc > #3877
| From | Rod Pemberton <NoEmail@trraxvfeqa.prg> |
|---|---|
| Newsgroups | comp.lang.misc |
| Subject | Re: Compiling and linking code from different places in the file system |
| Date | 2018-03-07 06:57 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <p7ok0g$ev3$1@gioia.aioe.org> (permalink) |
| References | <p793c8$7d8$1@dont-email.me> <p7luil$2d5$1@gioia.aioe.org> <p7ofr0$jgu$1@dont-email.me> |
On Wed, 7 Mar 2018 10:44:47 +0000
James Harris <james.harris.1@gmail.com> wrote:
> On 06/03/2018 11:39, Rod Pemberton wrote:
> > On Thu, 1 Mar 2018 14:40:07 +0000
> > James Harris <james.harris.1@gmail.com> wrote:
> >
> > [c.l.c. dropped]
> >> And that leads to my first query. (Yes, there is
> >> one!) If a given source file SS.c includes many headers, and the
> >> headers could be scattered to the four winds - i.e. distributed
> >> around the file system - in a really big project what's a good way
> >> of specifying where the compiler should look for included
> >> headers?
> >
> > It shouldn't.
> >
> > When the compiler is allowed to decide where to look, it may look in
> > the wrong place.
> >
> > The programmer should duplicate the includes or exports locally.
> > While this requires more maintenance and could lead to coding
> > mistakes, i.e., syncing issues, it ensures that the correct
> > includes or exports are used, but if and only if, no mistakes are
> > made.
>
> In theory each import or #include could specify the full path for
> everything it was to include (assuming a language which supported
> such specification) but that could be very inconvenient if the files
> were to be copied elsewhere.
Full path? ...
If it's something related to the system or compiler, then maybe a full
path, but the system or compiler should "know" where it's own
directories, includes, and libraries are located.
If it's related to the project, then I'd think you'd want a relative
path, as the person decompressing the archive could unpack it anywhere.
> A programmer might prefer relative
> references and to get the compiler to search a list of folders for
> the name.
Ok.
> In what I have in mind it would be up to the programmer to specify
> what to look for and where. In fact, since it would not be known in
> advance where each project would be in the filesystem hierarchy then
> imports would have to be relative to some start point or points.
What if the programmer specifies a directory that is off-limits?
e.g., privileged ... i.e., to prevent malfeasance
Wouldn't it be better to restrict the programmer to a few locations?
a) system libraries
b) compiler directories
c) sub-directories of the project
...
> Additionally, there might be some imports from other projects. They
> could not be specified relative to the root of the project which does
> the importing because they are not part of it. The folder in which
> the compiler should search for such imports would have to be
> specified separately, outside the project itself.
Should the programmer be able to do this? E.g., it's acceptable if the
programmer is working on their own machine with their own projects.
But, what if they're working on a multi-user machine. Should they be
allowed to access other people's projects? ...
> For example, I use a string formatter called sformat which behaves
> like C's sprintf and which is useful in multiple projects. Rather
> than duplicating it in each project, it's better for a C source file
> which uses it to say
>
> #include "sformat/sformat.h"
>
> And that requires that the folder which contains the subfolder
> sformat to be passed to the compiler in a -I {folder} form.
If the OS supports links, then you could have sformat.h as a link in
the current directory. Then, the include is simply:
#include "sfortmat.h"
Someone or something would need to set the link correctly, per project.
The only real issue AISI is that some OSes don't support links.
> >> At the moment I normally take the easy route and keep all the
> >> source code for a given project in just one one folder or in a few
> >> folders. But as projects get larger that approach does not scale
> >> at all well, and I need to improve both how I lay out project
> >> code
> >
> > Many files in a single directory doesn't scale well? ...
> > (I'm quite not sure what to say to that. What is scaling here? file
> > size? file quantity? It's not directories.)
>
> Two things: number of files, and splitting the source into specific
> sub-sources. Here's an example of the latter.
>
> A project might start off having
>
> PP/SS.c
> PP/SS.h
>
> But then it's determined that there should be different versions of
> SS for different architectures.
Whoa! Why? ...
If the language has something like C's preprocessor #ifdef's, then SS
can contain everything for all platforms. The #ifdef's select the
platform appropriate code.
> That part of the tree then becomes
>
> PP/ibm_at/SS.nasm
> PP/ibm_at/SS.h
>
> PP/ibm_mca/SS.c
> PP/ibm_mca/SS.h
>
> PP/rpi_2/SS.c
> PP/rpi_2/SS.h
>
Ok.
From the C perspective, you'd need a master include which includes the
appropriate sub-includes based on a defined macro:
PP/SS.h
/* SS.h start*/
#ifdef __IBMAT__
#include "ibm_at/SS.h"
#endif
#ifdef __IBMMCA__
#include "ibm_mca/SS.h"
#endif
#ifdef __RPI2__
#include "rpi_2/SS.h"
#endif
/* SS.h end */
Then, you'd use a compiler option e.g., -D to define __IBMAT__ or
__IBMMCA__ or __RPI2__ etc. Or, the #ifdef's could use platform
specific pre-defined macros. For most C compilers, there usually are
host specific defines.
E.g., "Pre-defined Compiler Macros"
https://sourceforge.net/p/predef/wiki/Compilers/
> Or, perhaps it becomes
>
> PP/SS.h
> PP/ibm_at/SS.nasm
> PP/ibm_mca/SS.c
> PP/rpi_2/SS.c
Ditto.
> In either case, there are different source files for different
> machine architectures. In the first, each has its own SS.h header. In
> the second, the source files all use the same header, i.e. are
> written to all export compatible symbols.
For C, #define's and #ifdef's take care of selecting code, including
#include lines.
I'm not sure what you're wanting for non-C situation.
> > Obviously, you only need to copy or move the .o files together in a
> > clean way to be linked, after traversing the sub-directories to
> > compile the code. Isn't this what a makefile does?
>
> Sorry, I don't know what you mean about moving or copying the .o
> files together. Can you say a bit more?
PP/one/one.c
PP/one/one.h
PP/one/one.o
PP/two/two.c
PP/two/two.h
PP/two/two.o
Say we need to link one.c and two.c after being compiled. We only need
to find one.o and two.o, and/or move/copy them to where we can link them
together. Make programs do that for Linux. For DOS, you might use
a .bat file to copy them into the same directory, since compilers can
usually link files together that are in the same directory from the
command line. Sometimes compilers can also accept paths on the command
line to the .o files. So, you wouldn't need anything in that regard,
except the complete command line with paths.
> >> especially what I do when one project needs to import files from
> >> another.
> >
> > The first option is to use code duplication. It's much easier to
> > just copy the code from one project into another, than it is to
> > link to it, if licensing allows. Now, both projects separate and
> > have what they need to compile.
>
s/projects separate/projects are separated/
> The problem with such copying is that it requires updates to the code
> to also be propagated.
There is code management software.
> Or, worse, some of the copies end up being forks
If they're all your projects, hopefully not. ;-)
If they're a mix of various people's project, yup ... But, they're
still separated, and each project will have what it needs, i.e., the
version that works with it. What if there is a radical rewrite of the
file from the master project? Now, you've got to completely recode your
project to continue using the master project's file. (Linux is a
nightmare like this. The most recent version of some project will
require the most recent version of two dozens other projects.)
> and then a programmer ends up with different versions of the
> same code and begins to sow the seeds of a maintenance nightmare.
That can't be any worse than having to rebuild dozens or more software
packages which are dependent upon each other, in order to update just
one package, as is the norm for Linux now.
Rod Pemberton
--
feeback loop: Russian aggression -> World complains -> Russian
paranioa -> Russian threats -> repeat
Back to comp.lang.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-01 14:40 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-01 14:55 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-02 21:05 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-03 01:18 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-09 01:03 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-06 06:40 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-06 21:10 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-07 06:58 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-09 01:23 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-09 02:28 -0500
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-09 02:44 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-09 23:26 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-11 07:44 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-12 21:59 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-14 01:45 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-14 10:59 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-06 06:40 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-06 21:20 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-07 06:58 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-09 10:30 +0000
Re: Compiling and linking code from different places in the file system "James R. Kuyper" <jameskuyper@verizon.net> - 2018-03-01 11:11 -0500
Re: Compiling and linking code from different places in the file system "James R. Kuyper" <jameskuyper@verizon.net> - 2018-03-01 13:51 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-03 09:48 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-03 12:25 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-03 15:32 +0000
Re: Compiling and linking code from different places in the file system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-04 07:52 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-04 08:43 +0000
Re: Compiling and linking code from different places in the file system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-05 07:58 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-06 21:37 +0000
Re: Compiling and linking code from different places in the file system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-07 21:02 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-05 15:29 +0000
Re: Compiling and linking code from different places in the file system rugxulo@gmail.com - 2018-03-06 18:23 -0800
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-07 04:54 +0000
Re: Compiling and linking code from different places in the file system Robert Wessel <robertwessel2@yahoo.com> - 2018-03-07 00:33 -0600
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-07 09:55 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-07 17:29 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-06 06:39 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-07 10:44 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-07 06:57 -0500
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-09 10:28 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-11 07:44 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-12 22:44 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-14 01:47 -0400
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-14 10:23 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-14 11:30 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-14 11:30 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-14 13:30 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-14 14:32 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-14 16:01 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-14 19:28 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-15 08:59 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-15 19:21 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-16 08:08 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-16 11:12 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-16 16:45 +0100
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-16 16:09 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-16 18:42 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-17 18:32 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-17 21:37 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-17 21:00 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-18 11:39 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-18 12:29 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-19 13:38 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-20 05:40 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-20 11:05 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-21 06:03 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-21 18:51 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-21 19:55 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-23 18:03 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-23 20:13 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-24 01:30 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-24 16:48 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-26 19:42 +0100
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-26 22:35 +0100
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-24 12:01 +0100
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-23 20:58 +0100
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-23 20:49 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-20 18:37 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-21 19:33 +0000
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-21 20:35 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-23 21:10 +0100
Re: Compiling and linking code from different places in the file system Marco van de Voort <marcov@toad.stack.nl> - 2018-04-19 06:47 +0000
Re: Compiling and linking code from different places in the file system Andy Walker <anw@cuboid.co.uk> - 2018-03-27 00:58 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-30 19:55 +0100
Re: Compiling and linking code from different places in the file system Marco van de Voort <marcov@toad.stack.nl> - 2018-04-19 06:49 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-23 21:04 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-23 21:54 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-24 11:22 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-24 12:12 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-24 13:15 +0100
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-24 13:36 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-24 14:52 +0000
Re: Compiling and linking code from different places in the file system Marco van de Voort <marcov@toad.stack.nl> - 2018-04-19 11:06 +0000
Re: Compiling and linking code from different places in the file system David Brown <david.brown@hesbynett.no> - 2018-03-14 16:52 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-14 19:38 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-15 09:00 +0100
Re: Compiling and linking code from different places in the file system bartc <bc@freeuk.com> - 2018-03-15 12:54 +0000
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-14 11:18 +0000
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-14 13:52 +0100
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-15 06:29 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-15 20:37 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-17 11:51 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-20 06:31 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-20 17:14 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-21 07:10 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-24 01:38 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-24 16:10 +0000
Re: Compiling and linking code from different places in the file system Rod Pemberton <NoEmail@trraxvfeqa.prg> - 2018-03-24 20:05 -0400
Re: Compiling and linking code from different places in the file system James Harris <james.harris.1@gmail.com> - 2018-03-25 16:55 +0100
Re: Compiling and linking code from different places in the file system "Pascal J. Bourguignon" <pjb@informatimago.com> - 2018-03-14 13:39 +0100
csiph-web