Compiling
To compile a C or C++ program that uses LJM see the compilation instructions, which include instructions for compiling programs including:
- General instructions
- Visual Studio instructions
- Using included make.sh build scripts
- Using Xcode
Code Snippet
#include <stdio.h>
#include <LabJackM.h>
#include "LJM_Utilities.h"
// Available in the C/C++ examples download. Provides the ErrorCheck function.
int main()
{
int err, handle;
double value = 0;
const char * NAME = {"SERIAL_NUMBER"};
// Open first found LabJack
err = LJM_Open(LJM_dtANY, LJM_ctANY, "LJM_idANY", &handle);
ErrorCheck(err, "LJM_Open");
// Call LJM_eReadName to read the serial number from the LabJack.
err = LJM_eReadName(handle, NAME, &value);
ErrorCheck(err, "LJM_eReadName");
printf("eReadName result:\n");
printf(" %s = %f\n", NAME, value);
// Close device handle
err = LJM_Close(handle);
ErrorCheck(err, "LJM_Close");
return LJME_NOERROR;
}
File list
C_C++_LJM_2019-03-27.zip contains:
README
scons-local-2.5.1/scons.py (as well as SConstruct files for each example folder)
CHANGES.txt
LabJackMModbusMap.h
LJM_StreamUtilities.h
LJM_Utilities.h
make_all.sh
basic\eAddresses.c
basic\eAddresses.exe
basic\eNames.c
basic\eNames.exe
basic\eReadAddress.c
basic\eReadAddress.exe
basic\eReadAddresses.c
basic\eReadAddresses.exe
basic\eReadName.c
basic\eReadName.exe
basic\eReadNames.c
basic\eReadNames.exe
basic\eWriteAddress.c
basic\eWriteAddress.exe
basic\eWriteAddresses.c
basic\eWriteAddresses.exe
basic\eWriteName.c
basic\eWriteName.exe
basic\eWriteNames.c
basic\eWriteNames.exe
basic\make.sh
basic\write_read_loop_with_config.c
basic\write_read_loop_with_config.exe
more\1-wire\1-wire.c
more\1-wire\1-wire.exe
more\1-wire\make.sh
more\ain\dual_ain_loop.c
more\ain\dual_ain_loop.exe
more\ain\make.sh
more\ain\single_ain.c
more\ain\single_ain.exe
more\ain\single_ain_with_config.c
more\ain\single_ain_with_config.exe
more\asynch\make.sh
more\asynch\uart_loopback_test.c
more\asynch\uart_loopback_test.exe
more\config\make.sh
more\config\read_config.c
more\config\read_config.exe
more\config\read_device_name_string.c
more\config\read_device_name_string.exe
more\config\write_device_name_string.c
more\config\write_device_name_string.exe
more\config\write_power_config.c
more\config\write_power_config.exe
more\dio\make.sh
more\dio\single_dio_read.c
more\dio\single_dio_read.exe
more\dio\single_dio_write.c
more\dio\single_dio_write.exe
more\dio_ef\dio_ef_config_1_pwm_and_1_counter.c
more\dio_ef\dio_ef_config_1_pwm_and_1_counter.exe
more\dio_ef\make.sh
more\ethernet\make.sh
more\ethernet\read_ethernet_config.c
more\ethernet\read_ethernet_config.exe
more\ethernet\read_ethernet_mac.c
more\ethernet\read_ethernet_mac.exe
more\ethernet\write_ethernet_config.c
more\ethernet\write_ethernet_config.exe
more\i2c\i2c_eeprom.c
more\i2c\i2c_eeprom.exe
more\i2c\make.sh
more\list_all\list_all.c
more\list_all\list_all.exe
more\list_all\list_all_extended.c
more\list_all\list_all_extended.exe
more\list_all\make.sh
more\sd\change_directory.cpp
more\sd\change_directory.exe
more\sd\delete_file.cpp
more\sd\delete_file.exe
more\sd\get_disk_info.cpp
more\sd\get_disk_info.exe
more\sd\list_directory.cpp
more\sd\list_directory.exe
more\sd\make.sh
more\sd\print_working_directory.cpp
more\sd\print_working_directory.exe
more\sd\read_file.cpp
more\sd\read_file.exe
more\sd\sd_util.hpp
more\spi\make.sh
more\spi\spi.c
more\spi\spi.exe
more\stream\make.sh
more\stream\stream_basic.c
more\stream\stream_basic.exe
more\stream\stream_basic_with_stream_out.c
more\stream\stream_basic_with_stream_out.exe
more\stream\stream_burst.c
more\stream\stream_burst.exe
more\stream\stream_callback.c
more\stream\stream_callback.exe
more\stream\stream_external_clock.c
more\stream\stream_external_clock.exe
more\stream\stream_out_only.c
more\stream\stream_out_only.exe
more\stream\stream_out_update.c
more\stream\stream_out_update.exe
more\stream\stream_sequential_ain.c
more\stream\stream_sequential_ain.exe
more\stream\stream_triggered.c
more\stream\stream_triggered.exe
more\testing\auto_reconnect_test.c
more\testing\auto_reconnect_test.exe
more\testing\c-r_speed_test.c
more\testing\c-r_speed_test.exe
more\testing\externally_clocked_stream_test.c
more\testing\externally_clocked_stream_test.exe
more\testing\make.sh
more\testing\stream_burst_test.c
more\testing\stream_burst_test.exe
more\testing\system_reboot_test.c
more\testing\system_reboot_test.exe
more\testing\write_read_loop_with_config_speed_test_eNames.c
more\testing\write_read_loop_with_config_speed_test_eNames.exe
more\utilities\device_info.c
more\utilities\device_info.exe
more\utilities\error.c
more\utilities\error.exe
more\utilities\lua_script_basic.c
more\utilities\lua_script_basic.exe
more\utilities\make.sh
more\utilities\names_to_addresses.c
more\utilities\names_to_addresses.exe
more\utilities\raw_bytes.c
more\utilities\raw_bytes.exe
more\utilities\read_cal.c
more\utilities\read_cal.exe
more\utilities\read_ljm_config.c
more\utilities\read_ljm_config.exe
more\utilities\set_timeout.cpp
more\utilities\set_timeout.exe
more\utilities\stepwise_feedback.c
more\utilities\stepwise_feedback.exe
more\utilities\t7_tcp_configure.c
more\utilities\t7_tcp_configure.exe
more\utilities\thermocouple_example.c
more\utilities\thermocouple_example.exe
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.c
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.exe
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.sln
more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking.vcproj
more\watchdog\make.sh
more\watchdog\read_watchdog_config.c
more\watchdog\read_watchdog_config.exe
more\watchdog\write_watchdog_config.c
more\watchdog\write_watchdog_config.exe
more\wifi\make.sh
more\wifi\read_wifi_config.c
more\wifi\read_wifi_config.exe
more\wifi\read_wifi_mac.c
more\wifi\read_wifi_mac.exe
more\wifi\read_wifi_rssi.c
more\wifi\read_wifi_rssi.exe
more\wifi\write_wifi_config.c
more\wifi\write_wifi_config.exe
visual_studio_2008\basic\eAddresses\eAddresses.sln
visual_studio_2008\basic\eAddresses\eAddresses.vcproj
visual_studio_2008\basic\eNames\eNames.sln
visual_studio_2008\basic\eNames\eNames.vcproj
visual_studio_2008\basic\eReadAddress\eReadAddress.sln
visual_studio_2008\basic\eReadAddress\eReadAddress.vcproj
visual_studio_2008\basic\eReadAddresses\eReadAddresses.sln
visual_studio_2008\basic\eReadAddresses\eReadAddresses.vcproj
visual_studio_2008\basic\eReadName\eReadName.sln
visual_studio_2008\basic\eReadName\eReadName.vcproj
visual_studio_2008\basic\eReadNames\eReadNames.sln
visual_studio_2008\basic\eReadNames\eReadNames.vcproj
visual_studio_2008\basic\eWriteAddress\eWriteAddress.sln
visual_studio_2008\basic\eWriteAddress\eWriteAddress.vcproj
visual_studio_2008\basic\eWriteAddresses\eWriteAddresses.sln
visual_studio_2008\basic\eWriteAddresses\eWriteAddresses.vcproj
visual_studio_2008\basic\eWriteName\eWriteName.sln
visual_studio_2008\basic\eWriteName\eWriteName.vcproj
visual_studio_2008\basic\eWriteNames\eWriteNames.sln
visual_studio_2008\basic\eWriteNames\eWriteNames.vcproj
visual_studio_2008\basic\write_read_loop_with_config\write_read_loop_with_config.sln
visual_studio_2008\basic\write_read_loop_with_config\write_read_loop_with_config.vcproj
visual_studio_2008\more\1-wire\1-wire\1-wire.sln
visual_studio_2008\more\1-wire\1-wire\1-wire.vcproj
visual_studio_2008\more\ain\dual_ain_loop\dual_ain_loop.sln
visual_studio_2008\more\ain\dual_ain_loop\dual_ain_loop.vcproj
visual_studio_2008\more\ain\single_ain\single_ain.sln
visual_studio_2008\more\ain\single_ain\single_ain.vcproj
visual_studio_2008\more\ain\single_ain_with_config\single_ain_with_config.sln
visual_studio_2008\more\ain\single_ain_with_config\single_ain_with_config.vcproj
visual_studio_2008\more\asynch\uart_loopback_test\uart_loopback_test.sln
visual_studio_2008\more\asynch\uart_loopback_test\uart_loopback_test.vcproj
visual_studio_2008\more\config\read_config\read_config.sln
visual_studio_2008\more\config\read_config\read_config.vcproj
visual_studio_2008\more\config\read_device_name_string\read_device_name_string.sln
visual_studio_2008\more\config\read_device_name_string\read_device_name_string.vcproj
visual_studio_2008\more\config\write_device_name_string\write_device_name_string.sln
visual_studio_2008\more\config\write_device_name_string\write_device_name_string.vcproj
visual_studio_2008\more\config\write_power_config\write_power_config.sln
visual_studio_2008\more\config\write_power_config\write_power_config.vcproj
visual_studio_2008\more\dio\single_dio_read\single_dio_read.sln
visual_studio_2008\more\dio\single_dio_read\single_dio_read.vcproj
visual_studio_2008\more\dio\single_dio_write\single_dio_write.sln
visual_studio_2008\more\dio\single_dio_write\single_dio_write.vcproj
visual_studio_2008\more\dio_ef\dio_ef_config_1_pwm_and_1_counter\dio_ef_config_1_pwm_and_1_counter.sln
visual_studio_2008\more\dio_ef\dio_ef_config_1_pwm_and_1_counter\dio_ef_config_1_pwm_and_1_counter.vcproj
visual_studio_2008\more\ethernet\read_ethernet_config\read_ethernet_config.sln
visual_studio_2008\more\ethernet\read_ethernet_config\read_ethernet_config.vcproj
visual_studio_2008\more\ethernet\read_ethernet_mac\read_ethernet_mac.sln
visual_studio_2008\more\ethernet\read_ethernet_mac\read_ethernet_mac.vcproj
visual_studio_2008\more\ethernet\write_ethernet_config\write_ethernet_config.sln
visual_studio_2008\more\ethernet\write_ethernet_config\write_ethernet_config.vcproj
visual_studio_2008\more\i2c\i2c_eeprom\i2c_eeprom.sln
visual_studio_2008\more\i2c\i2c_eeprom\i2c_eeprom.vcproj
visual_studio_2008\more\list_all\list_all\list_all.sln
visual_studio_2008\more\list_all\list_all\list_all.vcproj
visual_studio_2008\more\list_all\list_all_extended\list_all_extended.sln
visual_studio_2008\more\list_all\list_all_extended\list_all_extended.vcproj
visual_studio_2008\more\sd\change_directory\change_directory.sln
visual_studio_2008\more\sd\change_directory\change_directory.vcproj
visual_studio_2008\more\sd\delete_file\delete_file.sln
visual_studio_2008\more\sd\delete_file\delete_file.vcproj
visual_studio_2008\more\sd\get_disk_info\get_disk_info.sln
visual_studio_2008\more\sd\get_disk_info\get_disk_info.vcproj
visual_studio_2008\more\sd\list_directory\list_directory.sln
visual_studio_2008\more\sd\list_directory\list_directory.vcproj
visual_studio_2008\more\sd\print_working_directory\print_working_directory.sln
visual_studio_2008\more\sd\print_working_directory\print_working_directory.vcproj
visual_studio_2008\more\sd\read_file\read_file.sln
visual_studio_2008\more\sd\read_file\read_file.vcproj
visual_studio_2008\more\spi\spi\spi.sln
visual_studio_2008\more\spi\spi\spi.vcproj
visual_studio_2008\more\stream\stream_basic\stream_basic.sln
visual_studio_2008\more\stream\stream_basic\stream_basic.vcproj
visual_studio_2008\more\stream\stream_basic_with_stream_out\stream_basic_with_stream_out.sln
visual_studio_2008\more\stream\stream_basic_with_stream_out\stream_basic_with_stream_out.vcproj
visual_studio_2008\more\stream\stream_burst\stream_burst.sln
visual_studio_2008\more\stream\stream_burst\stream_burst.vcproj
visual_studio_2008\more\stream\stream_callback\stream_callback.sln
visual_studio_2008\more\stream\stream_callback\stream_callback.vcproj
visual_studio_2008\more\stream\stream_external_clock\stream_external_clock.sln
visual_studio_2008\more\stream\stream_external_clock\stream_external_clock.vcproj
visual_studio_2008\more\stream\stream_out_only\stream_out_only.sln
visual_studio_2008\more\stream\stream_out_only\stream_out_only.vcproj
visual_studio_2008\more\stream\stream_out_update\stream_out_update.sln
visual_studio_2008\more\stream\stream_out_update\stream_out_update.vcproj
visual_studio_2008\more\stream\stream_sequential_ain\stream_sequential_ain.sln
visual_studio_2008\more\stream\stream_sequential_ain\stream_sequential_ain.vcproj
visual_studio_2008\more\stream\stream_triggered\stream_triggered.sln
visual_studio_2008\more\stream\stream_triggered\stream_triggered.vcproj
visual_studio_2008\more\testing\auto_reconnect_test\auto_reconnect_test.sln
visual_studio_2008\more\testing\auto_reconnect_test\auto_reconnect_test.vcproj
visual_studio_2008\more\testing\c-r_speed_test\c-r_speed_test.sln
visual_studio_2008\more\testing\c-r_speed_test\c-r_speed_test.vcproj
visual_studio_2008\more\testing\externally_clocked_stream_test\externally_clocked_stream_test.sln
visual_studio_2008\more\testing\externally_clocked_stream_test\externally_clocked_stream_test.vcproj
visual_studio_2008\more\testing\stream_burst_test\stream_burst_test.sln
visual_studio_2008\more\testing\stream_burst_test\stream_burst_test.vcproj
visual_studio_2008\more\testing\system_reboot_test\system_reboot_test.sln
visual_studio_2008\more\testing\system_reboot_test\system_reboot_test.vcproj
visual_studio_2008\more\testing\write_read_loop_with_config_speed_test_eNames\write_read_loop_with_config_speed_test_eNames.sln
visual_studio_2008\more\testing\write_read_loop_with_config_speed_test_eNames\write_read_loop_with_config_speed_test_eNames.vcproj
visual_studio_2008\more\utilities\device_info\device_info.sln
visual_studio_2008\more\utilities\device_info\device_info.vcproj
visual_studio_2008\more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking\windows_dynamic_runtime_linking.sln
visual_studio_2008\more\utilities\dynamic_runtime_linking\windows_dynamic_runtime_linking\windows_dynamic_runtime_linking.vcproj
visual_studio_2008\more\utilities\error\error.sln
visual_studio_2008\more\utilities\error\error.vcproj
visual_studio_2008\more\utilities\lua_script_basic\lua_script_basic.sln
visual_studio_2008\more\utilities\lua_script_basic\lua_script_basic.vcproj
visual_studio_2008\more\utilities\names_to_addresses\names_to_addresses.sln
visual_studio_2008\more\utilities\names_to_addresses\names_to_addresses.vcproj
visual_studio_2008\more\utilities\raw_bytes\raw_bytes.sln
visual_studio_2008\more\utilities\raw_bytes\raw_bytes.vcproj
visual_studio_2008\more\utilities\read_cal\read_cal.sln
visual_studio_2008\more\utilities\read_cal\read_cal.vcproj
visual_studio_2008\more\utilities\read_ljm_config\read_ljm_config.sln
visual_studio_2008\more\utilities\read_ljm_config\read_ljm_config.vcproj
visual_studio_2008\more\utilities\set_timeout\set_timeout.sln
visual_studio_2008\more\utilities\set_timeout\set_timeout.vcproj
visual_studio_2008\more\utilities\stepwise_feedback\stepwise_feedback.sln
visual_studio_2008\more\utilities\stepwise_feedback\stepwise_feedback.vcproj
visual_studio_2008\more\utilities\t7_tcp_configure\t7_tcp_configure.sln
visual_studio_2008\more\utilities\t7_tcp_configure\t7_tcp_configure.vcproj
visual_studio_2008\more\utilities\thermocouple_example\thermocouple_example.sln
visual_studio_2008\more\utilities\thermocouple_example\thermocouple_example.vcproj
visual_studio_2008\more\watchdog\read_watchdog_config\read_watchdog_config.sln
visual_studio_2008\more\watchdog\read_watchdog_config\read_watchdog_config.vcproj
visual_studio_2008\more\watchdog\write_watchdog_config\write_watchdog_config.sln
visual_studio_2008\more\watchdog\write_watchdog_config\write_watchdog_config.vcproj
visual_studio_2008\more\wifi\read_wifi_config\read_wifi_config.sln
visual_studio_2008\more\wifi\read_wifi_config\read_wifi_config.vcproj
visual_studio_2008\more\wifi\read_wifi_mac\read_wifi_mac.sln
visual_studio_2008\more\wifi\read_wifi_mac\read_wifi_mac.vcproj
visual_studio_2008\more\wifi\read_wifi_rssi\read_wifi_rssi.sln
visual_studio_2008\more\wifi\read_wifi_rssi\read_wifi_rssi.vcproj
visual_studio_2008\more\wifi\write_wifi_config\write_wifi_config.sln
visual_studio_2008\more\wifi\write_wifi_config\write_wifi_config.vcproj
xcode\basic\write_read_loop_with_config\write_read_loop_with_config.xcodeproj
xcode\basic\write_read_loop_with_config\write_read_loop_with_config.xcodeproj\project.pbxproj
8 comments
I am new to Visual Studio and
I am new to Visual Studio and am so far unable to link any programs provided from the examples. Can you provide some direction on how exactly
to reference the header files and libraries in Visual Studio?
The examples downloads on
The examples downloads on this page contain example .sln and .vcproj files in the visual_studio_2008 folder, so you could look at those files for Visual Studio 9 examples.
More generally, here are some Visual Studio Configuration Properties that are necessary for LJM.
C/C++:
Linker:
Looks like an issue with
Looks like an issue with linking to the LJM library. Just for a quick test, you could try opening one of the projects/solutions in the download's visual_studio_2008 folder and see if they compile.
As for the errors you are getting, make sure your linker settings look like:
Linker:
If you are compiling a 64-bit application, change the "Additional Library Directories" to "$(ProgramFiles)\LabJack\Drivers\64bit" instead. If the proper LabJackM.lib file isn't used for linking the compiler will not find the LJM functions/symbols.
The examples in the
The examples in the visual_studio_2008 folder compile with no issues. My linker settings are identical to those above. I am attempting to compile for Win32.
I would recommend going
I would recommend going through Microsoft's LNK2019 error guide, if you haven't already:
https://msdn.microsoft.com/en-us/library/799kze2z.aspx
In particular, it may be helpful to use the /VERBOSE flag to make sure LabJackM.lib is being linked. Also, the stackoverflow it mentions may be generally helpful to you.
You can also try adding LabJackM.lib to your project or otherwise ensuring that LabJackM.lib is where you think it is.
SOLUTION: In the Visual
SOLUTION:
In the Visual Studio 2013 project properties dialog, change C/C++ > Preprocessor > Preprocessor Definitions
from the default: _MBCS;%(PreprocessorDefinitions)
to: WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
The example code snippet will now compile and run.
Note: Add the statement WaitForUserIfWindows(); just above the return LJME_NOERROR; statement to keep the console window open for inspection after the program has finished execution.
Thanks for posting
Thanks for posting this!
Also, WaitForUserIfWindows is defined in LJM_Utilities.h, for anyone who might be looking at this in the future.
I can compile the code
I can compile the code snippet above if I paste it into the .c file of an existing Visual Studio example project, so my problem must be due to incorrect settings somewhere...