Trying to use these external modules, which are written in plain C.
When linking in B4R, "undefined reference errors" occur because the c source files are being converted to cpp files.
Have flagged in Inline C that the functions are c code with extern "C" blocks = see below snippet.
Using the Arduino IDE 1.8.13 no issues compiling & linking, i.e. sketch is running ok.
Q: How to link external modules written in plain C.
When linking in B4R, "undefined reference errors" occur because the c source files are being converted to cpp files.
Have flagged in Inline C that the functions are c code with extern "C" blocks = see below snippet.
Using the Arduino IDE 1.8.13 no issues compiling & linking, i.e. sketch is running ok.
Q: How to link external modules written in plain C.
Error Messages:
... b4r_main.cpp:48: undefined reference to `tf_io4_v2_set_selected_value'
... Local\Temp\ccK8QaUj.ltrans0.ltrans.o: In function `io4_init':
... b4r_main.cpp:38: undefined reference to `tf_hal_arduino_init'
Inline C Snippet:
' Inline code setting up & use TF functions
' Tested first with Arduino IDE
#If C
// Tinkerforge
#include "src/hal_arduino/hal_arduino.h"
#include "src/bindings/hal_common.h"
#include "src/bindings/bricklet_io4_v2.h"
#ifdef __cplusplus
extern "C" {
#endif
// Define port connected Arduino CS pin: UNO=#10, MEGA=#53
TF_Port ports[1] = {
{
.chip_select_pin=53,
.port_name='A'
}
};
TF_HalContext hal;
TF_IO4V2 io;
char* IO4_UID = "G4d";
int IO4_CH_LED = 0;
void io4_init (B4R::Object* o) {
b4r_main::_tfrc = tf_hal_arduino_init(&hal, ports, sizeof(ports)/sizeof(ports[0]));
if (b4r_main::_tfrc < 0)
return
b4r_main::_tfrc = tf_io4_v2_create(&io, IO4_UID, &hal);
if (b4r_main::_tfrc < 0)
return
tf_io4_v2_set_configuration(&io, IO4_CH_LED, 'o', false);
}
void io4_set_state(B4R::Object* o) {
tf_io4_v2_set_selected_value(&io, IO4_CH_LED, b4r_main::_state);
}
#ifdef __cplusplus
}
#endif
#End If
Last edited: