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 name=
"creator" content=
"Mini-XML v2.6">
8 <style type=
"text/css"><!--
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
13 H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
18 font-family: monaco, courier, monospace;
23 font-family: monaco, courier, monospace;
41 border: dotted thin #999999;
46 PRE.command EM, PRE.example EM {
47 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
51 font-family: monaco, courier, monospace;
62 border: solid thin #999999;
73 -moz-border-radius: 10px;
78 text-decoration: none;
81 A:link:hover, A:visited:hover, A:active {
82 text-decoration: underline;
89 TR.data, TD.data, TR.data TD {
92 border-bottom: solid 1pt #999999;
96 border-bottom: solid 1pt #999999;
103 border: solid thin #999999;
104 border-collapse: collapse;
120 border: solid thin #cccccc;
127 border-bottom: solid thin #999999;
136 caption-side: bottom;
160 border: thin solid black;
168 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
177 border-bottom: solid 2pt #000000;
180 DIV.indent, TABLE.indent {
188 border-collapse: collapse;
191 TABLE.indent TD, TABLE.indent TH {
196 border-collapse: collapse;
204 border-bottom: solid thin #cccccc;
209 vertical-align: bottom;
218 border-bottom: solid thin #eeeeee;
223 TABLE.list TR:nth-child(even) {
227 TABLE.list TR:nth-child(odd) {
246 font-family: monaco, courier, monospace;
250 border: solid thin #999999;
251 border-collapse: collapse;
256 DIV.summary TABLE TD, DIV.summary TABLE TH {
257 border: solid thin #999999;
263 DIV.summary TABLE THEAD TH {
267 /* API documentation styles... */
274 div.body h3, div.body h4, div.body h5 {
275 margin-bottom: 0.5em;
278 .class, .enumeration, .function, .struct, .typedef, .union {
279 border-bottom: solid thin #999999;
286 code, p.code, pre, ul.code li {
287 font-family: monaco, courier, monospace;
290 ul.code, ul.contents, ul.subcontents {
291 list-style-type: none;
301 ul.contents li ul.code, ul.contents li ul.subcontents {
314 margin-bottom: 0.5em;
317 /* This is just for the HTML files generated with the framedhelp target */
320 border: solid thin black;
329 div.contents ul.contents {
332 div.contents ul.subcontents li {
341 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
343 Introduction to CUPS programming header for the Common UNIX Printing System
346 Copyright 2008-2009 by Apple Inc.
348 These coded instructions, statements, and computer programs are the
349 property of Apple Inc. and are protected by Federal copyright
350 law. Distribution and use rights are outlined in the file "LICENSE.txt"
351 which should have been included with this file. If this file is
352 file is missing or damaged, see the license at "http://www.cups.org/".
355 <h1 class='title'
>Introduction to CUPS Programming
</h1>
357 <div class='summary'
><table summary='General Information'
>
368 cups/sidechannel.h
</th>
379 <td>Programming:
<a href='raster-driver.html' target='_top'
>Developing Raster Printer Drivers
</a><br>
380 Programming:
<a href='postscript-driver.html' target='_top'
>Developing PostScript Printer Drivers
</a><br>
381 Programming:
<a href='api-filter.html' target='_top'
>Filter and Backend Programming
</a><br>
382 Programming:
<a href='ppd-compiler.html' target='_top'
>Introduction to the PPD Compiler
</a><br>
383 Programming:
<a href='api-array.html' target='_top'
>Array API
</a><br>
384 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
385 Programming:
<a href='api-filedir.html' target='_top'
>File and Directory APIs
</a><br>
386 Programming:
<a href='api-httpipp.html' target='_top'
>HTTP and IPP APIs
</a><br>
387 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
388 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
389 References:
<a href='ref-ppdcfile.html' target='_top'
>PPD Compiler Driver Information File Reference
</a><br>
390 Specifications:
<a href='spec-ppd.html' target='_top'
>CUPS PPD Extensions
</a></td>
394 <h2 class=
"title">Contents
</h2>
395 <ul class=
"contents">
396 <ul class=
"subcontents">
397 <li><a href=
"#OVERVIEW">Overview
</a></li>
398 <li><a href=
"#COMPILING">Compiling Programs
</a><ul class=
"subcontents">
399 <li><a href=
"#XCODE">Compiling with Xcode
</a></li>
400 <li><a href=
"#COMMANDLINE">Compiling with GCC
</a></li>
402 <li><a href=
"#WHERETOGO">Where to Go Next
</a></li>
404 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
406 Introduction to CUPS programming content for the Common UNIX Printing System
409 Copyright 2008 by Apple Inc.
411 These coded instructions, statements, and computer programs are the
412 property of Apple Inc. and are protected by Federal copyright
413 law. Distribution and use rights are outlined in the file "LICENSE.txt"
414 which should have been included with this file. If this file is
415 file is missing or damaged, see the license at "http://www.cups.org/".
418 <h2 class=
"title"><a name=
"OVERVIEW">Overview
</a></h2>
420 <p>CUPS provides two libraries that interface with the different parts of the
421 printing system. The
"cups" library provides all of the common application and
422 filter functions while the
"cupsimage" library provides all of the imaging
423 functions used in raster printer drivers. The
"cups" library functions are
424 accessed by including the
<var><cups/cups.h
></var> header, while
425 "cupsimage" functions are found in the
<var><cups/raster.h
></var>
428 <h2 class=
"title"><a name=
"COMPILING">Compiling Programs
</a></h2>
430 <p>The CUPS libraries can be used from any C, C++, or Objective C program.
431 The method of compiling against the libraries varies depending on the
432 operating system and installation of CUPS. The following sections show how
433 to compile a simple program (shown below) in two common environments.
</p>
435 <p>The following simple program lists the available printers on the system:
</p>
437 <pre class=
"example">
438 #include
<stdio.h
>
439 #include
<cups/cups.h
>
444 cups_dest_t *dests, *dest;
445 int num_dests = cupsGetDests(
&dests);
447 for (i = num_dests, dest = dests; i
> 0; i --, dest ++)
450 printf(
"%s/%s\n", dest-
>name, dest-
>instance);
459 <h3><a name=
"XCODE">Compiling with Xcode
</a></h3>
461 <p>In Xcode, choose
<var>New Project...
</var> from the
<var>File
</var> menu,
462 then select the
<var>Standard Tool
</var> project type under
<var>Command Line
463 Utility
</var>. Click
<var>Next
</var> and choose a project directory. Click
464 <var>Next
</var> to create the project.
</p>
466 <p>In the project window, double-click on the
<var>Targets
</var> group and
467 control-click on the simple target to show the context menu. Choose
468 <var>Existing Framework...
</var> from the
<var>Add
</var> submenu. When the file
469 chooser sheet appears, press the
<kbd>/
</kbd> key and enter
"/usr/lib". Scroll
470 down the file list and select the
<var>libcups.dylib
</var> file. Click the
471 <var>Add
</var> button in the file chooser and attributes sheets.
</p>
473 <p>In the project window, double-click on the
<var>main.c
</var> source file.
474 Replace the template source code with the listing above and save it. Click the
475 <var>Build and Go
</var> button to build the sample program and run it.
</p>
477 <h3><a name=
"COMMANDLINE">Compiling with GCC
</a></h3>
479 <p>From the command-line, create a file called
<var>sample.c
</var> using your
480 favorite editor and then run the following command to compile it with GCC and
483 <pre class=
"command">
484 gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
488 <p>The
<code>cups-config
</code> command provides the compiler flags
489 (
"cups-config --cflags") and libraries (
"cups-config --libs") needed for the
492 <h2 class=
"title"><a name=
"WHERETOGO">Where to Go Next
</a></h2>
494 <p>If you are developing a print filter, driver, or backend, see the
495 <a href=
"api-filter.html" target=
"_top">Filter and Backend Programming
</a>
496 guide. Raster printer driver developers should also read the
497 <a href=
"api-raster.html" target=
"_top">Raster API
</a> reference.
</p>