Language - C Linux GCC: Difference between revisions

From Phidgets Support
(Created page with "{{NoTitle}} {{Language_-_C_Dev_Environment_Table}} {| |style="vertical-align:middle; width: 60%;"| <font size=6>'''Language - C''' '''Linux with GCC'''</font> Welcome to usi...")
 
No edit summary
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{NoTitle}}
[[Category:Language]]{{NoTitle}}
{{Language_-_C_Dev_Environment_Table}}
{|
{|
|style="vertical-align:middle; width: 60%;"|
|style="vertical-align:middle; width: 60%;"|
Line 14: Line 13:
{{Language_-_C_Intro|Linux|GCC}}
{{Language_-_C_Intro|Linux|GCC}}


==Use Our Examples==
{{Finding Code Samples|C}}
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:
 
==Using the Code Samples==
To use the code sample from the [{{server}}/?view=code_samples&lang=C Code Samples] page, you can click the '''Download Example''' button to download a C file with the sample code.
 
[[Image:C_Sample_Code_Download.png|link=|center|border|800px]]
 
 
Once you have the example, you can compile and run your code:
 
==Compile and Run==
 
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'>
<syntaxhighlight lang='C'>
apt-get install gcc
apt-get install gcc
</syntaxhighlight>
</syntaxhighlight>


 
To compile the program, enter the following command in the terminal, substituting "example" for the name of your C file:
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'>
<syntaxhighlight lang='bash'>
Line 36: Line 41:
</syntaxhighlight>
</syntaxhighlight>


{{Edit_the_Examples}}
Success! The project now has access to Phidgets.
 
{{Language_-_C_Write_Code}}
 
==Setting up a New Project==
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>
 
You can now compile the file as shown in the [[#Use Our Examples|Use Our Examples]] section.
 
The project now has access to Phidgets.


{{Language_-_C_Further_Reading}}
{{Language Page What's Next}}

Revision as of 21:17, 16 October 2019

Language - C

Linux with GCC

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.

Install Phidget Drivers for Linux

Before getting started with the guides below, ensure you have the following components installed on your machine:

  1. You will need the Phidgets Linux Drivers

Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

C sample code.jpg


Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Using the Code Samples

To use the code sample from the Code Samples page, you can click the Download Example button to download a C file with the sample code.

C Sample Code Download.png


Once you have the example, you can compile and run your code:

Compile and Run

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:

apt-get install gcc

To compile the program, enter the following command in the terminal, substituting "example" for the name of your C file:

gcc example.c -o example -lphidget22

After compiling, you can run the program by entering the following command in the terminal:

./example

Success! The project now has access to Phidgets.

What's Next?

Now that you have set up Phidgets to work with your programming environment, we recommend you read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.Next Arrow.png