Language - C Windows GCC: Difference between revisions
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
{{Language_-_C_Intro|Windows|GCC}} | {{Language_-_C_Intro|Windows|GCC}} | ||
{{Finding Code Samples|C}} | |||
==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== | ||
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]. | 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]. | ||
Next, navigate to the folder where your code is and open the command prompt. | |||
The specific command you will use depends on your compiler of choice. Select the tab for your compiler below, and enter the command within to compile your program, substituting "example" for the name of your C file: | |||
<tabber> | |||
Cygwin x86= | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22"-L"/cygdrive/c/Program Files/Phidgets/Phidget22/x86" -lphidget22 | gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22"-L"/cygdrive/c/Program Files/Phidgets/Phidget22/x86" -lphidget22 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|-| | |||
Cygwin x64= | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -L"/cygdrive/c/Program Files/Phidgets/Phidget22" -lphidget22 | gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -L"/cygdrive/c/Program Files/Phidgets/Phidget22" -lphidget22 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|-| | |||
MinGW= | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
gcc example.c -o example -I"C:/Program Files/Phidgets/Phidget22" -L"C:/Program Files/Phidgets/Phidget22/x86" -lphidget22 | gcc example.c -o example -I"C:/Program Files/Phidgets/Phidget22" -L"C:/Program Files/Phidgets/Phidget22/x86" -lphidget22 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</tabber> | |||
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 | |||
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 program: | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
example.exe | example.exe | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Language Page What's Next}} | {{Language Page What's Next}} |
Revision as of 21:07, 16 October 2019
Language - C Windows 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. It is available on Windows by using tools like MinGW or Cygwin to allow compilation of C programs from the command line. |
Install Phidget Drivers for Windows
Before getting started with the guides below, ensure you have the following components installed on your machine:
- You will need the Phidgets Windows 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.
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.
Once you have the example, you can compile and run your code:
Compile and Run
In order compile C programs from the command prompt, you will need to download and install either MinGW or Cygwin.
Next, navigate to the folder where your code is and open the command prompt.
The specific command you will use depends on your compiler of choice. Select the tab for your compiler below, and enter the command within to compile your program, substituting "example" for the name of your C file:
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22"-L"/cygdrive/c/Program Files/Phidgets/Phidget22/x86" -lphidget22
gcc example.c -o example -I"/cygdrive/c/Program Files/Phidgets/Phidget22" -L"/cygdrive/c/Program Files/Phidgets/Phidget22" -lphidget22
gcc example.c -o example -I"C:/Program Files/Phidgets/Phidget22" -L"C:/Program Files/Phidgets/Phidget22/x86" -lphidget22
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 program:
example.exe
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.