Language - C Windows GCC: Difference between revisions

From Phidgets Support
No edit summary
(Redirected page to Language - C)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Language]]
#REDIRECT [[Language - C]]
{{NoTitle}}
{{Language_-_C_Dev_Environment_Table}}
{|
|style="vertical-align:middle; width: 60%;"|
<font size=6>'''Language - C'''
 
'''Windows 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. It is available on Windows by using tools like MinGW or Cygwin to allow compilation of C programs from the command line.
|{{TOC limit|2}}
|}
 
{{Language_-_C_Intro|Windows|GCC}}
 
==Use Our Examples==
One of the best ways to start programming with Phidgets is to use our example code as a guide. In order to run the examples, you will need to download and install either [http://www.mingw.org/ MinGW] or [https://www.cygwin.com/ Cygwin].
 
 
Now that you have either MinGW or Cygwin installed, select an example that will work with your Phidget:
*{{SampleCode|C|C Examples}}
 
===Cygwin===
 
If you are using Cygwin, navigate to the folder where the example is and open the command prompt. Enter the following command to compile the example:
 
====Cygwin x86====
<syntaxhighlight lang='bash'>
gcc example.c ../Common/PhidgetHelperFunctions.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -I"../Common" -L"/cygdrive/c/Program Files/Phidgets/Phidget22/x86" -lphidget22
</syntaxhighlight>
 
====Cygwin x64====
<syntaxhighlight lang='bash'>
gcc example.c ../Common/PhidgetHelperFunctions.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -I"../Common" -L"/cygdrive/c/Program Files/Phidgets/Phidget22" -lphidget22
</syntaxhighlight>
 
===MinGW===
 
If you are using MinGW, navigate to the folder where the example is and open the command prompt. Enter the following command to compile the example:
<syntaxhighlight lang='bash'>
gcc example.c ../Common/PhidgetHelperFunctions.c -o example -I"C:/Program Files/Phidgets/Phidget22" -I"../Common" -L"C:/Program Files/Phidgets/Phidget22/x86" -lphidget22
</syntaxhighlight>
 
After running the commands above for either Cygwin or MinGW, an executable file called ''example.exe'' will be created. Enter the following command to run the example:
<syntaxhighlight lang='bash'>
example.exe
</syntaxhighlight>
 
{{Edit_the_Examples}}
 
==Editing the Examples==
{{Language_-_C_Editing_The_Examples}}
 
==Write Code==
{{Language_-_C_Write_Code}}
 
==Setting up a New Project==
In order compile C programs from the command prompt, you will need to download and install either [http://www.mingw.org/ MinGW] or [https://www.cygwin.com/ Cygwin].
 
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>
 
===Cygwin===
 
If you are using Cygwin, navigate to the folder where the example is and open the command prompt. Enter the following command to compile your program, substituting "example" for the name of your C file:
 
====Cygwin x86====
<syntaxhighlight lang='bash'>
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22"-L"/cygdrive/c/Program Files/Phidgets/Phidget22/x86" -lphidget22
</syntaxhighlight>
 
====Cygwin x64====
<syntaxhighlight lang='bash'>
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -L"/cygdrive/c/Program Files/Phidgets/Phidget22" -lphidget22
</syntaxhighlight>
 
===MinGW===
 
If you are using MinGW, navigate to the folder where the example is and open the command prompt. Enter the following command to compile the example:
<syntaxhighlight lang='bash'>
gcc example.c -o example -I"C:/Program Files/Phidgets/Phidget22" -L"C:/Program Files/Phidgets/Phidget22/x86" -lphidget22
</syntaxhighlight>
 
After running the commands above for either Cygwin or MinGW, an executable file called ''example.exe'' will be created. Enter the following command to run the example:
<syntaxhighlight lang='bash'>
example.exe
</syntaxhighlight>
 
Success! The project now has access to Phidgets.
 
{{Language_-_C_Further_Reading}}

Latest revision as of 16:32, 15 March 2021

Redirect to: