1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/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.5">
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;
32 border: dotted thin #999999;
37 PRE.command EM, PRE.example EM {
38 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
42 font-family: monaco, courier, monospace;
53 border: solid thin #999999;
58 text-decoration: none;
62 A:link:hover, A:visited:hover, A:active {
63 text-decoration: underline;
72 border: solid thin #999999;
73 border-collapse: collapse;
89 border: solid thin #cccccc;
96 border-bottom: solid thin #999999;
105 caption-side: bottom;
125 border: thin solid #000000;
133 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
139 border-bottom: solid 2pt #000000;
157 font-family: monaco, courier, monospace;
166 border: solid thin #999999;
167 border-collapse: collapse;
172 DIV.summary TABLE TD, DIV.summary TABLE TH {
173 border: solid thin #999999;
179 DIV.summary TABLE THEAD TH {
183 /* API documentation styles... */
190 div.body h3, div.body h4, div.body h5 {
191 margin-bottom: 0.5em;
194 .class, .enumeration, .function, .struct, .typedef, .union {
195 border-bottom: solid thin #999999;
202 code, p.code, pre, ul.code li {
203 font-family: monaco, courier, monospace;
206 ul.code, ul.contents, ul.subcontents {
207 list-style-type: none;
217 ul.contents li ul.code, ul.contents li ul.subcontents {
230 margin-bottom: 0.5em;
233 /* This is just for the HTML files generated with the framedhelp target */
236 border: solid thin black;
245 div.contents ul.contents {
248 div.contents ul.subcontents li {
257 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
259 Introduction to CUPS programming header for the Common UNIX Printing System
262 Copyright 2008 by Apple Inc.
264 These coded instructions, statements, and computer programs are the
265 property of Apple Inc. and are protected by Federal copyright
266 law. Distribution and use rights are outlined in the file "LICENSE.txt"
267 which should have been included with this file. If this file is
268 file is missing or damaged, see the license at "http://www.cups.org/".
271 <h1 class=
"title">Introduction to CUPS Programming
</h1>
273 <div class='summary'
><table summary='General Information'
>
284 cups/sidechannel.h
</th>
295 <td>Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
296 Programming:
<a href='api-array.html' target='_top'
>Array API
</a><br>
297 Programming:
<a href='api-filedir.html' target='_top'
>File and Directory APIs
</a><br>
298 Programming:
<a href='api-filter.html' target='_top'
>Filter and Backend Programming
</a><br>
299 Programming:
<a href='api-httpipp.html' target='_top'
>HTTP and IPP APIs
</a><br>
300 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
301 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a></td>
305 <h2 class=
"title">Contents
</h2>
306 <ul class=
"contents">
308 <li><a href=
"#OVERVIEW">Overview
</a></li>
309 <li><a href=
"#COMPILING">Compiling Programs
</a><ul class=
"subcontents">
310 <li><a href=
"#XCODE">Compiling with Xcode
</a></li>
311 <li><a href=
"#COMMANDLINE">Compiling with GCC
</a></li>
312 </ul class=
"subcontents"></li>
313 <li><a href=
"#WHERETOGO">Where to Go Next
</a></li>
316 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
318 Introduction to CUPS programming content for the Common UNIX Printing System
321 Copyright 2008 by Apple Inc.
323 These coded instructions, statements, and computer programs are the
324 property of Apple Inc. and are protected by Federal copyright
325 law. Distribution and use rights are outlined in the file "LICENSE.txt"
326 which should have been included with this file. If this file is
327 file is missing or damaged, see the license at "http://www.cups.org/".
330 <h2 class=
"title"><a name=
"OVERVIEW">Overview
</a></h2>
332 <p>CUPS provides two libraries that interface with the different parts of the
333 printing system. The
"cups" library provides all of the common application and
334 filter functions while the
"cupsimage" library provides all of the imaging
335 functions used in raster printer drivers. The
"cups" library functions are
336 accessed by including the
<var><cups/cups.h
></var> header, while
337 "cupsimage" functions are found in the
<var><cups/raster.h
></var>
340 <h2 class=
"title"><a name=
"COMPILING">Compiling Programs
</a></h2>
342 <p>The CUPS libraries can be used from any C, C++, or Objective C program.
343 The method of compiling against the libraries varies depending on the
344 operating system and installation of CUPS. The following sections show how
345 to compile a simple program (shown below) in two common environments.
</p>
347 <p>The following simple program lists the available printers on the system:
</p>
349 <pre class=
"example">
350 #include
<stdio.h
>
351 #include
<cups/cups.h
>
356 cups_dest_t *dests, *dest;
357 int num_dests = cupsGetDests(
&dests);
359 for (i = num_dests, dest = dests; i
> 0; i --, dest ++)
362 printf(
"%s/%s\n", dest-
>name, dest-
>instance);
371 <h3><a name=
"XCODE">Compiling with Xcode
</a></h3>
373 <p>In Xcode, choose
<var>New Project...
</var> from the
<var>File
</var> menu,
374 then select the
<var>Standard Tool
</var> project type under
<var>Command Line
375 Utility
</var>. Click
<var>Next
</var> and choose a project directory. Click
376 <var>Next
</var> to create the project.
</p>
378 <p>In the project window, double-click on the
<var>Targets
</var> group and
379 control-click on the simple target to show the context menu. Choose
380 <var>Existing Framework...
</var> from the
<var>Add
</var> submenu. When the file
381 chooser sheet appears, press the
<kbd>/
</kbd> key and enter
"/usr/lib". Scroll
382 down the file list and select the
<var>libcups.dylib
</var> file. Click the
383 <var>Add
</var> button in the file chooser and attributes sheets.
</p>
385 <p>In the project window, double-click on the
<var>main.c
</var> source file.
386 Replace the template source code with the listing above and save it. Click the
387 <var>Build and Go
</var> button to build the sample program and run it.
</p>
389 <h3><a name=
"COMMANDLINE">Compiling with GCC
</a></h3>
391 <p>From the command-line, create a file called
<var>sample.c
</var> using your
392 favorite editor and then run the following command to compile it with GCC and
395 <pre class=
"command">
396 gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
400 <p>The
<code>cups-config
</code> command provides the compiler flags
401 (
"cups-config --cflags") and libraries (
"cups-config --libs") needed for the
404 <h2 class=
"title"><a name=
"WHERETOGO">Where to Go Next
</a></h2>
406 <p>If you are developing a print filter, driver, or backend, see the
407 <a href=
"api-filter.html" target=
"_top">Filter and Backend Programming
</a>
408 guide. Raster printer driver developers should also read the
409 <a href=
"api-raster.html" target=
"_top">Raster API
</a> reference.
</p>