]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/api-overview.shtml
Merge changes from CUPS 1.6svn-r10188, including changes for <rdar://problem/10127258...
[thirdparty/cups.git] / cups / api-overview.shtml
CommitLineData
5a738aea
MS
1<!--
2 "$Id: api-cups.header 7279 2008-01-31 01:50:44Z mike $"
3
eac3a0a0 4 Introduction to CUPS programming content for CUPS.
5a738aea 5
eac3a0a0 6 Copyright 2008-2011 by Apple Inc.
5a738aea
MS
7
8 These coded instructions, statements, and computer programs are the
9 property of Apple Inc. and are protected by Federal copyright
10 law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 which should have been included with this file. If this file is
12 file is missing or damaged, see the license at "http://www.cups.org/".
13-->
14
15<h2 class="title"><a name="OVERVIEW">Overview</a></h2>
16
17<p>CUPS provides two libraries that interface with the different parts of the
18printing system. The "cups" library provides all of the common application and
19filter functions while the "cupsimage" library provides all of the imaging
20functions used in raster printer drivers. The "cups" library functions are
21accessed by including the <var>&lt;cups/cups.h&gt;</var> header, while
22"cupsimage" functions are found in the <var>&lt;cups/raster.h&gt;</var>
23header.</p>
24
25<h2 class="title"><a name="COMPILING">Compiling Programs</a></h2>
26
27<p>The CUPS libraries can be used from any C, C++, or Objective C program.
28The method of compiling against the libraries varies depending on the
29operating system and installation of CUPS. The following sections show how
30to compile a simple program (shown below) in two common environments.</p>
31
32<p>The following simple program lists the available printers on the system:</p>
33
34<pre class="example">
35#include &lt;stdio.h&gt;
36#include &lt;cups/cups.h&gt;
37
38int main(void)
39{
40 int i;
41 cups_dest_t *dests, *dest;
42 int num_dests = cupsGetDests(&amp;dests);
43
44 for (i = num_dests, dest = dests; i &gt; 0; i --, dest ++)
45 {
46 if (dest->instance)
47 printf("%s/%s\n", dest->name, dest->instance);
48 else
49 puts(dest->name);
50 }
51
52 return (0);
53}
54</pre>
55
56<h3><a name="XCODE">Compiling with Xcode</a></h3>
57
58<p>In Xcode, choose <var>New Project...</var> from the <var>File</var> menu,
59then select the <var>Standard Tool</var> project type under <var>Command Line
60Utility</var>. Click <var>Next</var> and choose a project directory. Click
61<var>Next</var> to create the project.</p>
62
63<p>In the project window, double-click on the <var>Targets</var> group and
64control-click on the simple target to show the context menu. Choose
65<var>Existing Framework...</var> from the <var>Add</var> submenu. When the file
66chooser sheet appears, press the <kbd>/</kbd> key and enter "/usr/lib". Scroll
67down the file list and select the <var>libcups.dylib</var> file. Click the
68<var>Add</var> button in the file chooser and attributes sheets.</p>
69
70<p>In the project window, double-click on the <var>main.c</var> source file.
71Replace the template source code with the listing above and save it. Click the
72<var>Build and Go</var> button to build the sample program and run it.</p>
73
74<h3><a name="COMMANDLINE">Compiling with GCC</a></h3>
75
76<p>From the command-line, create a file called <var>sample.c</var> using your
77favorite editor and then run the following command to compile it with GCC and
78run it:</p>
79
80<pre class="command">
81gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
82./simple
83</pre>
84
85<p>The <code>cups-config</code> command provides the compiler flags
86("cups-config --cflags") and libraries ("cups-config --libs") needed for the
87local system.</p>
88
89<h2 class="title"><a name="WHERETOGO">Where to Go Next</a></h2>
90
91<p>If you are developing a print filter, driver, or backend, see the
92<a href="api-filter.html" target="_top">Filter and Backend Programming</a>
93guide. Raster printer driver developers should also read the
94<a href="api-raster.html" target="_top">Raster API</a> reference.</p>