Writing your own code that uses EPICS channel access

Set up

Make sure you have EPICS set up properly. For Mu2e, see setup instructions on EPICS and related tools on Mu2e DAQ computers.

Then use either of the two methods below.

Using the EPICS build system

This is probably the best way, unless it conflicts with your own build system.

EPICS provides a Perl script to set up the directory structure EPICS build expects and populate it with working starter code. The script is It will be on your command path after EPICS is set up correctly (see above). The script should be run in an empty directory in which you want it to create the starter files and subdirectories.


  • To show basic options: -h

  • To show the types of applications that can be set up: -l

  • Example of how to set up to start writing a new IOC, to which you could add custom device support. "Test" will be the name of the IOC binary, and an iocTest sub-directory will have your starter source code and EPICS db files: -t ioc Test

  • Example of how to start making one or more new channel access client application programs. Here "myExample" will be the name of a source code sub-directory containing starter code with two examples: -t caClient myExample

Note that will make bin and configure directories and a Makefile in the directory in which you run it, as well as the subdirectory with your code, and possibly other things depending on the application type.

Compile using make in the directory in which you ran The starter templates should compile without modification. Then modify away!

See EPICS R3.14 Channel Access Reference Manual for extensive documentation on the channel access library, including an explanation of the two example clients made by -t caClient.

See the references on the Adding a new device to EPICS page in this wiki for information about writing and extending IOCs.

Compiling the example clients without the EPICS build system

This may not be a good idea, but you can get away with it using this Makefile:

CFLAGS+=-I ${EPICS_INC} -I ${EPICS_INC}/os/Linux -I ${EPICS_INC}/compiler/gcc
LDFLAGS+=-L ${EPICS_LIB} -lca -lCom

all: caExample caMonitor

Copy caExample.c and caMonitor.c from $EPICS_DIR/source/base-3.15.2/src/template/base/top/caClientApp/ to the same directory as the above short Makefile and try make. This works for me for those client applications, but probably would not for compiling an IOC or new device support.