4.9 KiB
libicsneo C Example
This is an example console application that uses the icsneoc library to control an Intrepid Control Systems hardware device.
Cloning
This will create a copy of the repository on your local machine.
Run:
git clone https://github.com/intrepidcs/libicsneo-examples -b v0.2.0-dev --recursive
Alternatively, if you cloned without the --recursive flag, you must enter the libicsneo-examples folder and run the following:
git submodule update --recursive --init
If you haven't done this, third-party/libicsneo will be empty and you won't be able to build!
Windows using Visual Studio 2017+
Building the DLL
First, we are going to build the icsneoc library into a .dll file that we can later use in order to access the library functions.
- Launch Visual Studio and open the
libicsneo-examplesfolder. - Choose
File->Open->Cmake... - Navigate to
third-party/libicsneoand select theCMakeLists.txtthere. - Visual Studio will process the CMake project.
- Select
Build->Rebuild All - Visual Studio will generate the
icsneoc.dllfile, which can then be found by selectingProject->Cmake Cache (x64-Debug Only)->Open in Explorer. If the file cannot be found, search inlibicsneo-examples/third-party/libicsneo/out/build/x64-Debugand double-check that the build succeeded in step 5. - Move the
icsneoc.dllfile to the/C/Windows/System32folder. This will allow it to be found by icsneo_init(), which loads all the library functions.- Alternatively, the
icsneoc.dllfile can be placed in the same directory aslibicsneoc-example.exe, which is typicallylibicsneo-examples/libicsneoc-example/out/build/x64-Debug, although this is not recommended. For more information, refer to the Microsoft documentation.
- Alternatively, the
Building the example program
Although the example program will build without successfully completing the steps above, it will exit immediately upon running due to a failure to load any library functions.
- Choose
File->Open->Cmake... - Navigate to
libicsneo-examples/libicsneoc-exampleand select theCMakeLists.txtthere. - Visual Studio will process the CMake project.
- Select
Build->Rebuild All - Click on the dropdown arrow attached to the green play button (labelled "Select Startup Item") and select
libicsneoc-example.exe - Click on the green play button to run the example.
Ubuntu 18.04 LTS
Building the .so
First, we are going to build the icsneoc library into a .so file that we can later use in order to access the library functions.
- Install dependencies with
sudo apt updatethensudo apt install build-essential cmake libpcap0.8-dev - Change directories to
libicsneo-examples/third-party/libicsneoand create a build directory by runningmkdir -p build - Enter the build directory with
cd build - Run
cmake ..to generate your Makefile.- Hint! Running
cmake -DCMAKE_BUILD_TYPE=Debug ..will generate the proper scripts to build debug, andcmake -DCMAKE_BUILD_TYPE=Release ..will generate the proper scripts to build with all optimizations on.
- Hint! Running
- Run
maketo build the library.- Hint! Speed up your build by using multiple processors! Use
make -j#where#is the number of cores/threads your system has plus one. For instance, on a standard 8 thread Intel i7, you might use-j9for an ~8x speedup.
- Hint! Speed up your build by using multiple processors! Use
- Run
sudo cp libicsneoc.so /usr/libso that it can be found via the default ubuntu .so search path. For more information, see the ld.so.8 man page.
Building the example program
Although the example program will build without successfully completing the steps above, it will exit immediately upon running due to a failure to load any library functions.
- Change directories to
libicsneo-examples/libicsneoc-example - Create a build directory by running
mkdir -p build - Enter the build directory with
cd build - Run
cmake ..to generate your Makefile.- Hint! Running
cmake -DCMAKE_BUILD_TYPE=Debug ..will generate the proper scripts to build debug, andcmake -DCMAKE_BUILD_TYPE=Release ..will generate the proper scripts to build with all optimizations on.
- Hint! Running
- Run
maketo build the library.- Hint! Speed up your build by using multiple processors! Use
make -j#where#is the number of cores/threads your system has plus one. For instance, on a standard 8 thread Intel i7, you might use-j9for an ~8x speedup.
- Hint! Speed up your build by using multiple processors! Use
- Run
sudo ./libicsneoc-exampleto run the example.- Hint! In order to run without sudo, you will need to set up the udev rules. Copy
libicsneo-examples/third-party/libicsneo/99-intrepidcs.rulesto/etc/udev/rules.d, then runudevadm control --reload-rules && udevadm triggerafterwards. While the program will still run without setting up these rules, it will fail to open any devices.
- Hint! In order to run without sudo, you will need to set up the udev rules. Copy
macOS
Instructions coming soon™