September 29th, 2003, 11:10 AM
including functions from other package
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
September 29th, 2003, 11:27 AM
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.
September 29th, 2003, 11:29 AM
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.
September 29th, 2003, 11:45 AM
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.
September 29th, 2003, 11:52 AM
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.
September 29th, 2003, 12:04 PM
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.
September 29th, 2003, 12:10 PM
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.
September 30th, 2003, 10:19 AM
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:
and the Epics makefile is:
CC = cc
CFLAGS = $(CFLAGS_OS) -D$(OSTYPE)
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
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
clean : $(OEXTS) $(OBS)
print : *.c *.h Makefile
CMPLR = STRICT
# 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
USR_CFLAGS = -DACCESS_SECURITY
caget_SRCS = caget.c
caput_SRCS = $(TOP)/src/EzcaScan/caput.c $(TOP)/src/EzcaScan/getopt.c
PROD = caget
# 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