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;
37 border: dotted thin #999999;
42 PRE.command EM, PRE.example EM {
43 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
47 font-family: monaco, courier, monospace;
58 border: solid thin #999999;
69 -moz-border-radius: 10px;
74 text-decoration: none;
77 A:link:hover, A:visited:hover, A:active {
78 text-decoration: underline;
85 TR.data, TD.data, TR.data TD {
88 border-bottom: solid 1pt #999999;
92 border-bottom: solid 1pt #999999;
99 border: solid thin #999999;
100 border-collapse: collapse;
116 border: solid thin #cccccc;
123 border-bottom: solid thin #999999;
132 caption-side: bottom;
156 border: thin solid black;
164 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
170 border-bottom: solid 2pt #000000;
173 DIV.indent, TABLE.indent {
181 border-collapse: collapse;
184 TABLE.indent TD, TABLE.indent TH {
189 border-collapse: collapse;
197 border-bottom: solid thin #cccccc;
202 vertical-align: bottom;
211 border-bottom: solid thin #eeeeee;
216 TABLE.list TR:nth-child(even) {
220 TABLE.list TR:nth-child(odd) {
239 font-family: monaco, courier, monospace;
243 border: solid thin #999999;
244 border-collapse: collapse;
249 DIV.summary TABLE TD, DIV.summary TABLE TH {
250 border: solid thin #999999;
256 DIV.summary TABLE THEAD TH {
260 /* API documentation styles... */
267 div.body h3, div.body h4, div.body h5 {
268 margin-bottom: 0.5em;
271 .class, .enumeration, .function, .struct, .typedef, .union {
272 border-bottom: solid thin #999999;
279 code, p.code, pre, ul.code li {
280 font-family: monaco, courier, monospace;
283 ul.code, ul.contents, ul.subcontents {
284 list-style-type: none;
294 ul.contents li ul.code, ul.contents li ul.subcontents {
307 margin-bottom: 0.5em;
310 /* This is just for the HTML files generated with the framedhelp target */
313 border: solid thin black;
322 div.contents ul.contents {
325 div.contents ul.subcontents li {
334 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
336 Introduction to CUPS programming header for the Common UNIX Printing System
339 Copyright 2008 by Apple Inc.
341 These coded instructions, statements, and computer programs are the
342 property of Apple Inc. and are protected by Federal copyright
343 law. Distribution and use rights are outlined in the file "LICENSE.txt"
344 which should have been included with this file. If this file is
345 file is missing or damaged, see the license at "http://www.cups.org/".
348 <div class='summary'
><table summary='General Information'
>
359 cups/sidechannel.h
</th>
370 <td>Programming:
<a href='raster-driver.html' target='_top'
>Developing Raster Printer Drivers
</a><br>
371 Programming:
<a href='postscript-driver.html' target='_top'
>Developing PostScript Printer Drivers
</a><br>
372 Programming:
<a href='api-filter.html' target='_top'
>Filter and Backend Programming
</a><br>
373 Programming:
<a href='ppd-compiler.html' target='_top'
>Introduction to the PPD Compiler
</a><br>
374 Programming:
<a href='api-array.html' target='_top'
>Array API
</a><br>
375 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
376 Programming:
<a href='api-filedir.html' target='_top'
>File and Directory APIs
</a><br>
377 Programming:
<a href='api-httpipp.html' target='_top'
>HTTP and IPP APIs
</a><br>
378 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
379 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
380 References:
<a href='ref-ppdcfile.html' target='_top'
>PPD Compiler Driver Information File Reference
</a><br>
381 Specifications:
<a href='spec-ppd.html' target='_top'
>CUPS PPD Extensions
</a></td>
385 <h2 class=
"title">Contents
</h2>
386 <ul class=
"contents">
387 <ul class=
"subcontents">
388 <li><a href=
"#OVERVIEW">Overview
</a></li>
389 <li><a href=
"#COMPILING">Compiling Programs
</a><ul class=
"subcontents">
390 <li><a href=
"#XCODE">Compiling with Xcode
</a></li>
391 <li><a href=
"#COMMANDLINE">Compiling with GCC
</a></li>
393 <li><a href=
"#WHERETOGO">Where to Go Next
</a></li>
395 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
397 Introduction to CUPS programming content for the Common UNIX Printing System
400 Copyright 2008 by Apple Inc.
402 These coded instructions, statements, and computer programs are the
403 property of Apple Inc. and are protected by Federal copyright
404 law. Distribution and use rights are outlined in the file "LICENSE.txt"
405 which should have been included with this file. If this file is
406 file is missing or damaged, see the license at "http://www.cups.org/".
409 <h2 class=
"title"><a name=
"OVERVIEW">Overview
</a></h2>
411 <p>CUPS provides two libraries that interface with the different parts of the
412 printing system. The
"cups" library provides all of the common application and
413 filter functions while the
"cupsimage" library provides all of the imaging
414 functions used in raster printer drivers. The
"cups" library functions are
415 accessed by including the
<var><cups/cups.h
></var> header, while
416 "cupsimage" functions are found in the
<var><cups/raster.h
></var>
419 <h2 class=
"title"><a name=
"COMPILING">Compiling Programs
</a></h2>
421 <p>The CUPS libraries can be used from any C, C++, or Objective C program.
422 The method of compiling against the libraries varies depending on the
423 operating system and installation of CUPS. The following sections show how
424 to compile a simple program (shown below) in two common environments.
</p>
426 <p>The following simple program lists the available printers on the system:
</p>
428 <pre class=
"example">
429 #include
<stdio.h
>
430 #include
<cups/cups.h
>
435 cups_dest_t *dests, *dest;
436 int num_dests = cupsGetDests(
&dests);
438 for (i = num_dests, dest = dests; i
> 0; i --, dest ++)
441 printf(
"%s/%s\n", dest-
>name, dest-
>instance);
450 <h3><a name=
"XCODE">Compiling with Xcode
</a></h3>
452 <p>In Xcode, choose
<var>New Project...
</var> from the
<var>File
</var> menu,
453 then select the
<var>Standard Tool
</var> project type under
<var>Command Line
454 Utility
</var>. Click
<var>Next
</var> and choose a project directory. Click
455 <var>Next
</var> to create the project.
</p>
457 <p>In the project window, double-click on the
<var>Targets
</var> group and
458 control-click on the simple target to show the context menu. Choose
459 <var>Existing Framework...
</var> from the
<var>Add
</var> submenu. When the file
460 chooser sheet appears, press the
<kbd>/
</kbd> key and enter
"/usr/lib". Scroll
461 down the file list and select the
<var>libcups.dylib
</var> file. Click the
462 <var>Add
</var> button in the file chooser and attributes sheets.
</p>
464 <p>In the project window, double-click on the
<var>main.c
</var> source file.
465 Replace the template source code with the listing above and save it. Click the
466 <var>Build and Go
</var> button to build the sample program and run it.
</p>
468 <h3><a name=
"COMMANDLINE">Compiling with GCC
</a></h3>
470 <p>From the command-line, create a file called
<var>sample.c
</var> using your
471 favorite editor and then run the following command to compile it with GCC and
474 <pre class=
"command">
475 gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
479 <p>The
<code>cups-config
</code> command provides the compiler flags
480 (
"cups-config --cflags") and libraries (
"cups-config --libs") needed for the
483 <h2 class=
"title"><a name=
"WHERETOGO">Where to Go Next
</a></h2>
485 <p>If you are developing a print filter, driver, or backend, see the
486 <a href=
"api-filter.html" target=
"_top">Filter and Backend Programming
</a>
487 guide. Raster printer driver developers should also read the
488 <a href=
"api-raster.html" target=
"_top">Raster API
</a> reference.
</p>