To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2507
2506  |  2508
Subject: 
Re: Multi Source Programs
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 28 Apr 2002 03:11:47 GMT
Viewed: 
2313 times
  
In lugnet.robotics.rcx.legos, Frank Carney writes:
I am developing some code and would like to compile
multiple sources in one program.  I cannot figure out
how to do this.  All the make targets seem to only
allow one source file.

What are my options?

Frank,

  This question has come up a number of times.  I spent
  some time on this answer so I'd understand the current
  state of this problem.  Part of the answer is found
  in an earlier post from Pat Welch:

    http://news.lugnet.com/robotics/rcx/legos/?n=1933

  Some changes in our makefiles have caused this solution
  to no longer work as intended, however.

  I am able to compile multiple sources with a few tweeks to the
  makefile.  My approach was to add code to the demo/Makefile
  just so I could focus on the problem-cause and solution.

  My 'hack' solution consists of changes only to demo/Makefile
  whereas the above email actually changes Makefile.user.  Our
  current Makefile.user appears to prevent the original solution
  from working.  So, here are the steps I took:

  - Define the final name of the .lx file
  - Define the list of source files (.c or .C/.cpp)
  - Declare the list of object files from the source file list
  - Add the name of the .lx file to the PROGRAMS symbol
  - Add the .ds1 dependency with a build rule (<- sad, but NOT
     adding the rule failed for me)
  - ditto for the .ds2 dependency (dep + build rule)
  - add dependency of .lx file on .ds1 and .ds2 files

  Now build your code!  You should be able to compile
  multiple sources into one .lx file with no intervening
  libraries.

My sample:

   I created a test case by splitting demo/linetrack.c into three files:
   lntrk_follow.h, lntrk_follow.c, lntrk_main.c and building lntrk.lx
   from them.

   Here are my Makefile additions:

MULTIPGM = lntrk
MULTIPGM_EXE = $(MULTIPGM).lx

MULTIPGM_SRCS = lntrk_follow.c \
                lntrk_main.c

MULTIPGM_OBJS = $(MULTIPGM_SRCS:.c=.o)

(I also added $(MULTIPGM_EXE) to the 'PROGRAMS = ' line, at
the end of the list)

the rest is below the all: target (or the all target doesn't work) <<<

$(MULTIPGM).ds1: $(MULTIPGM_OBJS)
    $(LD) $(DLDFLAGS) $^ $(DOBJECTS) $(LIBS) -o $@ -Ttext $(BASE1)

$(MULTIPGM).ds2: $(MULTIPGM_OBJS)
    $(LD) $(DLDFLAGS) $^ $(DOBJECTS) $(LIBS) -o $@ -Ttext $(BASE2)

$(MULTIPGM_EXE): $(MULTIPGM).ds1 $(MULTIPGM).ds2


Please understand, this is a 'hack'.  The build rules for .ds1 and .ds2
should not have had to be in your Makefile.  (I don't yet understand all
of why I had to do this.  But it does work, so I'm telling you this is
how I got it to work.)

I wouldn't have written this except that I couldn't get it to work
with only the dependency lines and no build rules.  (Maybe somebody else
can solve that part of this.  I'll post my actual findings under a separate
email so I don't confuse this answer more than I already have ;-))

For the upcoming release of legOS we will be simplifying this ability
and at the very least provide a working example of a multi-source
make so we, users of legOS, can modify it as needed.

My hope is that you can try this and then be able to replicate it
in your own makefiles (until we release the next version of legOS under
{newName} at which time you won't have to code all of this in your Makefiles.

Hope this helps.

Regards,
Stephen - member of legOS team.
--



Message is in Reply To:
  Multi Source Programs
 
I am developing some code and would like to compile multiple sources in one program. I cannot figure out how to do this. All the make targets seem to only allow one source file. What are my options? Can I compile my source as a library? If so how? (...) (23 years ago, 27-Apr-02, to lugnet.robotics.rcx.legos)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR