Language - C Linux GCC: Difference between revisions

From Phidgets Support
No edit summary
(Redirected page to Language - C)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Language]]{{NoTitle}}
#REDIRECT [[Language - C]]
{|
|style="vertical-align:middle; width: 60%;"|
<font size=6>'''Language - C'''
 
'''Linux with GCC'''</font>
 
Welcome to using Phidgets with C! By using C, you will have access to the complete Phidget22 API, including events.
 
GCC is a compiler system for originally written for GNU, and is the standard compiler on unix-like operating systems like Linux. It allows compilation of C programs from the command line.
|{{TOC limit|2}}
|}
{{Language_-_C_Intro|Linux|GCC}}
 
==Use Our Examples==
One of the best ways to start programming with Phidgets is to use our example code as a guide. You likely have gcc installed on your Linux machine already, but if not, you can easily get it by entering the following command in the terminal:
<syntaxhighlight lang='C'>
apt-get install gcc
</syntaxhighlight>
 
 
Next, select an example that will work with your Phidget:
*{{SampleCode|C|C Examples}}
 
 
To compile the example, enter the following command in the terminal:
 
<syntaxhighlight lang='bash'>
gcc example.c ../Common/PhidgetHelperFunctions.c -o example -I../Common -lphidget22
</syntaxhighlight>
 
After compiling, you can run the program by entering the following command in the terminal:
<syntaxhighlight lang='bash'>
./example
</syntaxhighlight>
 
{{Edit_the_Examples}}
 
==Editing the Examples==
{{Language_-_C_Editing_The_Examples}}
 
==Setting up a New Project==
To compile C programs, you will need gcc. You likely have gcc installed on your Linux machine already, but if not, you can easily get it by entering the following command in the terminal:
<syntaxhighlight lang='C'>
apt-get install gcc
</syntaxhighlight>
 
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.
 
To include the Phidget C library, add the following line to your code:
<syntaxhighlight lang='C'>
#include <phidget22.h>
</syntaxhighlight>
 
To compile the program, enter the following command in the terminal, substituting "example" for the name of your C file:
 
<syntaxhighlight lang='bash'>
gcc example.c -o example -lphidget22
</syntaxhighlight>
 
After compiling, you can run the program by entering the following command in the terminal:
<syntaxhighlight lang='bash'>
./example
</syntaxhighlight>
 
Success! The project now has access to Phidgets.
 
{{Language Page What's Next}}

Latest revision as of 16:36, 15 March 2021

Redirect to: