#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    16
    Rep Power
    0

    including functions from other package


    Hi,
    I have 2 different packages. One to control the detector (Synchrotron beamline) and other to control the hardware components (EPICS - contro lsystem software). Now I need to include one of the function (caget) from hardware control software in the detector software. This function in turn include many headers specific to hardware controil software. How do I include this function in detector software? and how do I compile? Or can I just include the file containing caget () in the detector makefile and compile? I have lost in touch with programming in C and most of the things I don't remember. If this is a stupid question, please don't mind explaining me.
    My requirement is to include a function from package1 in package2 and compile it .
    Thanks in advance
    Any help will be appreaciated
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,114
    Rep Power
    1803
    In the detector code #include the header that declares the function(s) in the hardware code. If there is no header, create one or simply declare the required function(s) extern within the detector code.

    The source files are compiled separately, and then linked with the linker.

    How you do this will depend on your tool chain. In an IDE you probably simply add both files/packages to your project. If you are using command line tools, then you need to modify the makefile so that both object code files are linked.

    Clifford.
  4. #3
  5. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    You will need the appropriate header file to compile (you can even copy the appropriate elements from the header file and put it in your own code), but you will need the libraries to link. As for where the libraries are and what their names are, I don't think anyone here can help (not too much call for Synchrotron beamline programming). Once you know the names and locations of the libraries, you can tell us along with what compiler/OS you are using and we can probably give what you need.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    16
    Rep Power
    0
    Hi,
    Actrually theser 2 different packages are provided by respective company who gave us the detector and hardware components. We now need to modify the code according to our needs. So, this is but complicated to understand their code. Moreover, being not an expert in C or C++ for me it's more hard to uinderstand the complicated programs to control the hardware components. But I should do the required changes. So, I am sorting help from experts like you.
    I can explain the scenario bit more detail.

    I have detector package which has a GUI (written using Tcl/Tk). There is a place to show up the wavelength value on the screen. Now in ot\rder to get the wavelength value, I have another package (EPICS) which basically using the socket reads the wavelength value from the hardware components and puts it in a file. In order to get this wavelength value, I need to call a sub routine wirtten in the EPICS(modified by me for our needs). Main function calling this function with required parameter will be in detector software. Can I write only the function caget in a seperate file and compile that with detector software (including this in Makefile)?
    To give the background, initially the caget was the main function where it used to get the parameters at the command line. Now I have changed this to a function.

    The software uses GCC compiler.
  8. #5
  9. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Do you know what is written in the file and what its format is? If all you need to do is see that data, just write a simple program to read from the file and display it. If that will work it will probably be much easier than tracking down libraries and getting the makefile written properly.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    16
    Rep Power
    0
    Unfortunately, since the caget itselfwasthe main program earlier and through command line, we used to get the wavelength value, I can't take the value from the file.
    As I told you, I have modified this caget to a subroutine wherein it gets the input values from the called program. This subroutine must be compiled with many header files and libraries in order to work (as it uses socket to communicate to the hardware component and get the wavelength value ). I have a makefile which compiled this caget along with the needed headers and libraries. In caget.c , I just had the dummy main function which just calls this caget subroutine with the required parameter. If I have the dummy main function in caget.c, it works fine. Now, I need to knock this main program as detector software will be calling the caget subroutine. I tried inlcuing the EPICS makefile in the detector makefile. But I get lot of errors. My only problem is linking to this subroutine. I know the libraries to be included as the modified caget works fine in detector software.
  12. #7
  13. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    You don't want to include the entire other makefile, you just need to include a couple of libraries and maybe some include paths. I am no great shakes at *nix programming, so take this advice with a grain of salt, but you can try adding one library at a time to your new makefile making sure it will find each one before you add the next. I don't remember if make will check for the actual presence of the given library if it doesn't need it, so this may not work unless your program actually uses something from the library. There are *nix experts floating around here, hopefully one of them can offer better advice.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    16
    Rep Power
    0
    If I try to merge the make files of both detecotr software and the EPICs software I get lot of errors. Being novice to these make files, I don't know where I am going wrong.
    Detector make file:
    Code:
    CC = cc
    CFLAGS = $(CFLAGS_OS) -D$(OSTYPE)
    IOFLAGS =
    OEXTS = ccd_bl.o ccd_bl_input.o ccd_bl_x6a.o ccd_bl_stat.o ccd_bl_glob.o util_misc.o cm_module.o  get_htotheta.o
    OBS  =
    OBJS = $(OEXTS) $(OBS) ../../lib/$(OSTYPE)/auxlib.a
    DD = ../../bin/$(OSTYPE)
    
    PRCMD = pr
    
    $(DD)/ccd_bl_x6a_test : $(OBJS)
            $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(IOFLAGS) -o $(DD)/ccd_bl_x6a_test
    
    $(OEXTS) :
    
    clean : $(OEXTS) $(OBS)
            rm $?
    
    print : *.c *.h Makefile
            $(PRCMD) $?
            touch print
    and the Epics makefile is:

    Code:
    #Makefile.Host
    TOP=/usr/local/epics3.13.5/extensions
    include $(TOP)/config/CONFIG_EXTENSIONS
    LIBDIRS= /usr/local/epics3.13.5/extensions/src/EzcaScan/O.Linux
    CMPLR = STRICT
    
    SHARED_LIBRARIES=YES
    
    # install header file
    INC = EzcaScan.h
    
    #
    #       Contents of library: generic, special and for all systems
    #
    
    # on generic system
    LIBOBJS := $(LIBDIRS)/EzcaFunc.o $(LIBDIRS)/EzcaHash.o $(LIBDIRS)/EzcaArray.o $(LIBDIRS)/EzcaUtil.o \
               $(LIBDIRS)/EzcaMonitor.o  $(LIBDIRS)/EzcaScan.o $(LIBDIRS)/EzcaQueue.o
    
    
    #       Library to build:
    #       lib$(LIBRARY).a  or   ..dll/..exp/..lib
    #
    LIBRARY := ezcaScan
    
    #       need additional libs to build
    PROD_LIBS += ezca ca Com
    
    caget_LIBS += ezcaScan
    caput_LIBS += ezcaScan
    ezca_DIR=$(INSTALL_LIB)
    ezcaScan_DIR=.
    
    USR_CFLAGS = -DACCESS_SECURITY
    caget_SRCS = caget.c
    caput_SRCS = $(TOP)/src/EzcaScan/caput.c $(TOP)/src/EzcaScan/getopt.c
    PROD = caget
    
    include /usr/local/epics3.13.5/extensions/config/RULES.Host
    
    #       EOF Makefile.Host

    The compiler is cc and gcc respectively. So, how do I go about compiling the Epics code before compiling the detecotr code?

    2. Where should I put the caget sub routine? It will be called by the detector code.

    This is very important. If somebody could help me I will be very thankful to them

IMN logo majestic logo threadwatch logo seochat tools logo