The sample program(s) Gordon refers to are at github/wiringPi - specifically for me lcd-adafruit.c. On my Rpi, the correct libraries are in /usr/lib and are libwiringPi.so and libwiringPiDev.so.

from /home/pi/bin this works:

gcc -o lcd-adafruit lcd-adafruit.c -lwiringPi -lwiringPiDev

I must assume both libraries are in the buster distro - I previously installed Adafruit package(s) to use the I2C LCD display in Python3 on this Rpi.

Thanks - keep well.


I discovered Gordon's forum with posts dated 2012 - 2013. He offers some sample programs with wiringPi functions and some suggested compile/link commands - for example:

gcc -o filename.c -I/usr/local/include filename -L/usr/local/lib -lwiringPi

Lots of tries, lots of missing file errors - as well, on this buster rpi3, the library path does not include /local. Running each step separately, the preprocessor, the compiler, and the assembler finish without errors, but the linker stops on missing symbols in different library modules. Seems like maybe a shared library issue - any ideas?

Dirk: Thanks for cleaning up the look of my question and the code.

Joan: gcc i2clcd.c -o i2clcd executed command from /home/pi

I have become aware that Gordon has moved on/wiringpi is deprecated, but the last update to gpio was 2018 - seems pretty current to me .... enlighten me as needed. Also, both of the included wiringPi header files are found in /usr/include, and the relevant setup function appears in each. Thanks.

Raspbian buster on Rpi3 with Adafruit 16 x 2 LCD display on I2C. Display works fine with Python3 test program. Gordon's example gpio commands also work. gpio version is 2.50.

I am moving a working Arduino C++ application with the LCD display to Rpi. Neither (WiringPi) Gordon's sample programs or the sample .c program from bristolwatch.com will compile - both sources #include and . Compile fails with undefined reference to wiringPiSetup() and wiringPiI2CSetup(). The compiler does not report any missing libraries.

The gpio package is the package that comes with buster - when I tried an install with apt-get, Apt-get reported I had the latest version. Many other forum questions here indicate that wiringpi should be working, but most other questions are a bit older. What am I missing here? I am attaching Lewis Loftin's (bristolwatch) sample code that does not compile for me.`

* by Lewis Loflin www.bristolwatch.com lewis@bvu.net
* http://www.bristolwatch.com/rpi/i2clcd.htm
* Using wiringPi by Gordon Henderson
* Port over lcd_i2c.py to C and added improvements.
* Supports 16x2 and 20x4 screens.
* This was to learn now the I2C lcd displays operate.
* There is no warrenty of any kind use at your own risk.

#include <wiringPiI2C.h>
#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>

// Define some device parameters
#define I2C_ADDR   0x27 // I2C device address

// Define some device constants
#define LCD_CHR  1 // Mode - Sending data
#define LCD_CMD  0 // Mode - Sending command

#define LINE1  0x80 // 1st line
#define LINE2  0xC0 // 2nd line

#define LCD_BACKLIGHT   0x08  // On
// LCD_BACKLIGHT = 0x00  # Off

#define ENABLE  0b00000100 // Enable bit

void lcd_init(void);
void lcd_byte(int bits, int mode);
void lcd_toggle_enable(int bits);

// added by Lewis
void typeInt(int i);
void typeFloat(float myFloat);
void lcdLoc(int line); //move cursor
void ClrLcd(void); // clr LCD return home
void typeln(const char *s);
void typeChar(char val);
int fd;  // seen by all subroutines

int main()   {

  if (wiringPiSetup () == -1) exit (1);

  fd = wiringPiI2CSetup(I2C_ADDR);

  //printf("fd = %d ", fd);

  lcd_init(); // setup LCD

  char array1[] = "Hello world!";

  while (1)   {

    typeln("Using wiringPi");
    typeln("Geany editor.");

    typeln("I2c  Programmed");
    typeln("in C not Python.");

    typeln("Arduino like");
    typeln("fast and easy.");


    ClrLcd(); // defaults LINE1
    typeln("Int  ");
    int value = 20125;

    typeln("Float ");
    float FloatVal = 10045.25989;

  return 0;


// float to string
void typeFloat(float myFloat)   {
  char buffer[20];
  sprintf(buffer, "%4.2f",  myFloat);

// int to string
void typeInt(int i)   {
  char array1[20];
  sprintf(array1, "%d",  i);

// clr lcd go home loc 0x80
void ClrLcd(void)   {
  lcd_byte(0x01, LCD_CMD);
  lcd_byte(0x02, LCD_CMD);

// go to location on LCD
void lcdLoc(int line)   {
  lcd_byte(line, LCD_CMD);

// out char to LCD at current position
void typeChar(char val)   {

  lcd_byte(val, LCD_CHR);

// this allows use of any size string
void typeln(const char *s)   {

  while ( *s ) lcd_byte(*(s++), LCD_CHR);


void lcd_byte(int bits, int mode)   {

  //Send byte to data pins
  // bits = the data
  // mode = 1 for data, 0 for command
  int bits_high;
  int bits_low;
  // uses the two half byte writes to LCD
  bits_high = mode | (bits & 0xF0) | LCD_BACKLIGHT ;
  bits_low = mode | ((bits << 4) & 0xF0) | LCD_BACKLIGHT ;

  // High bits
  wiringPiI2CReadReg8(fd, bits_high);

  // Low bits
  wiringPiI2CReadReg8(fd, bits_low);

void lcd_toggle_enable(int bits)   {
  // Toggle enable pin on LCD display
  wiringPiI2CReadReg8(fd, (bits | ENABLE));
  wiringPiI2CReadReg8(fd, (bits & ~ENABLE));

void lcd_init()   {
  // Initialise display
  lcd_byte(0x33, LCD_CMD); // Initialise
  lcd_byte(0x32, LCD_CMD); // Initialise
  lcd_byte(0x06, LCD_CMD); // Cursor move direction
  lcd_byte(0x0C, LCD_CMD); // 0x0F On, Blink Off
  lcd_byte(0x28, LCD_CMD); // Data length, number of lines, font size
  lcd_byte(0x01, LCD_CMD); // Clear display
  • 1
    Please edit your question and include the command you are using to compile and link your C program.
    – joan
    Mar 31 '20 at 20:31
  • 1
    Please note this: wiringpi.com/wiringpi-deprecated
    – Dougie
    Mar 31 '20 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.