1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>Introduction to CUPS Programming
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8">
8 <meta name=
"creator" content=
"Mini-XML v2.7">
9 <style type=
"text/css"><!--
11 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
14 H1, H2, H3, H4, H5, H6, P, TD, TH {
15 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
19 font-family: monaco, courier, monospace;
24 font-family: monaco, courier, monospace;
28 border: dotted thin #7f7f7f;
56 border: dotted thin #999999;
61 PRE.command EM, PRE.example EM {
62 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
66 font-family: monaco, courier, monospace;
77 border: solid thin #999999;
88 -moz-border-radius: 10px;
93 text-decoration: none;
96 A:link:hover, A:visited:hover, A:active {
97 text-decoration: underline;
104 TR.data, TD.data, TR.data TD {
107 border-bottom: solid 1pt #999999;
111 border-bottom: solid 1pt #999999;
118 border: solid thin #999999;
119 border-collapse: collapse;
135 border: solid thin #cccccc;
142 border-bottom: solid thin #999999;
151 caption-side: bottom;
175 border: thin solid black;
183 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
192 border-bottom: solid 2pt #000000;
195 DIV.indent, TABLE.indent {
203 border-collapse: collapse;
206 TABLE.indent TD, TABLE.indent TH {
211 border-collapse: collapse;
219 border-bottom: solid thin #cccccc;
224 vertical-align: bottom;
233 border-bottom: solid thin #eeeeee;
238 TABLE.list TR:nth-child(even) {
242 TABLE.list TR:nth-child(odd) {
261 font-family: monaco, courier, monospace;
265 border: solid thin #999999;
266 border-collapse: collapse;
271 DIV.summary TABLE TD, DIV.summary TABLE TH {
272 border: solid thin #999999;
278 DIV.summary TABLE THEAD TH {
282 /* API documentation styles... */
289 div.body h3, div.body h4, div.body h5 {
290 margin-bottom: 0.5em;
293 .class, .enumeration, .function, .struct, .typedef, .union {
294 border-bottom: solid thin #999999;
301 code, p.code, pre, ul.code li {
302 font-family: monaco, courier, monospace;
305 ul.code, ul.contents, ul.subcontents {
306 list-style-type: none;
316 ul.contents li ul.code, ul.contents li ul.subcontents {
329 margin-bottom: 0.5em;
332 /* This is just for the HTML files generated with the framedhelp target */
335 border: solid thin black;
344 div.contents ul.contents {
347 div.contents ul.subcontents li {
356 Introduction to CUPS programming header for CUPS.
358 Copyright 2008-2016 by Apple Inc.
360 These coded instructions, statements, and computer programs are the
361 property of Apple Inc. and are protected by Federal copyright
362 law. Distribution and use rights are outlined in the file "LICENSE.txt"
363 which should have been included with this file. If this file is
364 file is missing or damaged, see the license at "http://www.cups.org/".
367 <h1 class='title'
>Introduction to CUPS Programming
</h1>
369 <div class='summary'
><table summary='General Information'
>
393 <td>Programming:
<a href='raster-driver.html' target='_top'
>Developing Raster Printer Drivers
</a><br>
394 Programming:
<a href='postscript-driver.html' target='_top'
>Developing PostScript Printer Drivers
</a><br>
395 Programming:
<a href='api-filter.html' target='_top'
>Filter and Backend Programming
</a><br>
396 Programming:
<a href='ppd-compiler.html' target='_top'
>Introduction to the PPD Compiler
</a><br>
397 Programming:
<a href='api-admin.html' target='_top'
>Administrative APIs
</a><br>
398 Programming:
<a href='api-array.html' target='_top'
>Array API
</a><br>
399 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
400 Programming:
<a href='api-filedir.html' target='_top'
>File and Directory APIs
</a><br>
401 Programming:
<a href='api-httpipp.html' target='_top'
>HTTP and IPP APIs
</a><br>
402 Programming:
<a href='api-ppd.html' target='_top'
>PPD API (DEPRECATED)
</a><br>
403 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
404 References:
<a href='ref-ppdcfile.html' target='_top'
>PPD Compiler Driver Information File Reference
</a><br>
405 Specifications:
<a href='spec-ppd.html' target='_top'
>CUPS PPD Extensions
</a></td>
409 <h2 class=
"title">Contents
</h2>
410 <ul class=
"contents">
411 <li><a href=
"#OVERVIEW">Overview
</a></li>
412 <li><a href=
"#COMPILING">Compiling Programs
</a><ul class=
"subcontents">
413 <li><a href=
"#XCODE">Compiling with Xcode
</a></li>
414 <li><a href=
"#COMMANDLINE">Compiling with GCC
</a></li>
416 <li><a href=
"#WHERETOGO">Where to Go Next
</a></li>
419 Introduction to CUPS programming content for CUPS.
421 Copyright 2008-2011 by Apple Inc.
423 These coded instructions, statements, and computer programs are the
424 property of Apple Inc. and are protected by Federal copyright
425 law. Distribution and use rights are outlined in the file "LICENSE.txt"
426 which should have been included with this file. If this file is
427 file is missing or damaged, see the license at "http://www.cups.org/".
430 <h2 class=
"title"><a name=
"OVERVIEW">Overview
</a></h2>
432 <p>CUPS provides two libraries that interface with the different parts of the
433 printing system. The
"cups" library provides all of the common application and
434 filter functions while the
"cupsimage" library provides all of the imaging
435 functions used in raster printer drivers. The
"cups" library functions are
436 accessed by including the
<var><cups/cups.h
></var> header, while
437 "cupsimage" functions are found in the
<var><cups/raster.h
></var>
440 <h2 class=
"title"><a name=
"COMPILING">Compiling Programs
</a></h2>
442 <p>The CUPS libraries can be used from any C, C++, or Objective C program.
443 The method of compiling against the libraries varies depending on the
444 operating system and installation of CUPS. The following sections show how
445 to compile a simple program (shown below) in two common environments.
</p>
447 <p>The following simple program lists the available printers on the system:
</p>
449 <pre class=
"example">
450 #include
<stdio.h
>
451 #include
<cups/cups.h
>
456 cups_dest_t *dests, *dest;
457 int num_dests = cupsGetDests(
&dests);
459 for (i = num_dests, dest = dests; i
> 0; i --, dest ++)
462 printf(
"%s/%s\n", dest-
>name, dest-
>instance);
471 <h3><a name=
"XCODE">Compiling with Xcode
</a></h3>
473 <p>In Xcode, choose
<var>New Project...
</var> from the
<var>File
</var> menu,
474 then select the
<var>Standard Tool
</var> project type under
<var>Command Line
475 Utility
</var>. Click
<var>Next
</var> and choose a project directory. Click
476 <var>Next
</var> to create the project.
</p>
478 <p>In the project window, double-click on the
<var>Targets
</var> group and
479 control-click on the simple target to show the context menu. Choose
480 <var>Existing Framework...
</var> from the
<var>Add
</var> submenu. When the file
481 chooser sheet appears, press the
<kbd>/
</kbd> key and enter
"/usr/lib". Scroll
482 down the file list and select the
<var>libcups.dylib
</var> file. Click the
483 <var>Add
</var> button in the file chooser and attributes sheets.
</p>
485 <p>In the project window, double-click on the
<var>main.c
</var> source file.
486 Replace the template source code with the listing above and save it. Click the
487 <var>Build and Go
</var> button to build the sample program and run it.
</p>
489 <h3><a name=
"COMMANDLINE">Compiling with GCC
</a></h3>
491 <p>From the command-line, create a file called
<var>sample.c
</var> using your
492 favorite editor and then run the following command to compile it with GCC and
495 <pre class=
"command">
496 gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
500 <p>The
<code>cups-config
</code> command provides the compiler flags
501 (
"cups-config --cflags") and libraries (
"cups-config --libs") needed for the
504 <h2 class=
"title"><a name=
"WHERETOGO">Where to Go Next
</a></h2>
506 <p>If you are developing a print filter, driver, or backend, see the
507 <a href=
"api-filter.html" target=
"_top">Filter and Backend Programming
</a>
508 guide. Raster printer driver developers should also read the
509 <a href=
"api-raster.html" target=
"_top">Raster API
</a> reference.
</p>