Compiling LJM Programs for C/C++ | LabJack
 
« Close

Datasheets and User Guides

Software & Driver

 

Compiling LJM Programs for C/C++

Requirements

See LJM system requirements.

Installation

See the full list of installed LJM files.

Compilation

General Instructions

1. You need to include the LabJackM.h header file in your code. For example:

#include "LabJackM.h"

2. You need to include LabJackM as a library during link time. For example, with gcc using the -l flag:

$ gcc -o eReadNames.o -c eReadNames.c
$ gcc -o eReadNames eReadNames.o -lLabJackM

Windows - Compiling with Visual Studio

Example .sln/.vcproj Files

If you're using Visual Studio, see the visual_studio_2008\ folder (contained in the examples C/C++ download) for example .sln and .vcproj files.

When using a version of Visual Studio greater than 2008, Visual Studio will present a pop-up asking if you'd like make a one-way upgrade. Press "OK" to upgrade. After the upgrade, you can build and run the project as normal.

From Scratch

If you're making a Visual Studio project from scratch, you'll need to alter the project Properties to compile with LabJackM.h and to link to LabJackM.lib. Before doing either of the following steps, select which build you want—both the build configuration (e.g. Debug or Release) and build platform (e.g. x86 or x64). You'll need to apply the following properties to all the build configurations and platforms you want to build. In the Properties pane, you can select what build configuration and platform the current changes will apply to.

To compile with LabJackM.h for either 32-bit or 64-bit builds:

  1. Right-click on the project and click Properties.
  2. Under Configuration Properties, select C/C++, then General.
  3. In Additional Include Directories, add C:\Program Files (x86)\LabJack\Drivers. (If you have a different root drive instead of C:\, then use that root drive.)

To link LabJackM.lib for a 64-bit (x64) build:

  1. Right-click on the project and click Properties.
  2. Under Configuration Properties, select Linker, then General.
  3. In Additional Library Directories, add C:\Program Files (x86)\LabJack\Drivers\64bit. (If you have a different root drive instead of C:\, then use that root drive.)
  4. Under Configuration Properties, select Linker, then Input.
  5. In Additional Dependencies, add LabJackM.lib.

To link LabJackM.lib for a 32-bit (x86) build, follow the steps above for 64-bit, but add C:\Program Files\LabJack\Drivers to the Additional Library Directories instead.

Linux and macOS - Using the make.sh Build Scripts

To compile the example programs, cd to the examples directory and run ./make_all.sh. For example:

$ cd C_C++_LJM_2019-05-20/
$ ./make_all.sh

make_all.sh calls the make.sh script in each example directory to build the examples.

The make.sh scripts use the Python build tool SCons, so make sure Python is installed and up-to-date on your machine. SCons has been included in LabJackM/examples/scons-local-2.5.1/.

Run one of the example programs like this:

$ ./eReadNames

macOS - Example Xcode Project

There is an example Xcode project. In the examples C/C++ download, it's in xcode/basic/write_read_loop_with_config/.

Troubleshooting

Linux

If linking with -lLabJackM complains about undefined references to std:: references, you may have an old version of gcc. Try to update gcc to version 4.6. Add https://launchpad.net/~ubuntu-toolchain-r/+archive/test to your repositories by running:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Then: update apt-get, install gcc-4.6, and map gcc to the version you just installed. For example:

$ sudo apt-get update
$ sudo apt-get install gcc-4.6
$ sudo apt-get install g++-4.6
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
$ sudo update-alternatives --config gcc
$ sudo update-alternatives --config g++

For more information, see this post on superuser.com: "How can I update gcc to the latest version in Ubuntu 10.04?"