* * *

Author Topic: unit hwiringpi; on a RASPBERRY  (Read 3832 times)


  • Jr. Member
  • **
  • Posts: 60
unit hwiringpi; on a RASPBERRY
« on: September 22, 2015, 09:04:10 pm »
Raspberry Raspbian linux:

Can somebody explain why hwiringpi.pas is compiling fine. Like here:

Code: [Select]
pi@raspberrypi:/opt/wiringPi$ sudo fpc hwiringpi.pas
Free Pascal Compiler version 2.6.0 [2011/12/27] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for ARMEL
Compiling hwiringpi.pas
Assembling hwiringpi
93 lines compiled, 0.4 sec

But if i compile my own start.pas containing:

Code: [Select]
uses hwiringpi

it results in:
Code: [Select]
pi@raspberrypi:/opt/wiringPi$ sudo fpc start.pas
Free Pascal Compiler version 2.6.0 [2011/12/27] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for ARMEL
Compiling start.pas
Assembling program
Linking start
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/lib/fpc/2.6.0/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi':
(.text+0x88): undefined reference to `_fini'
/usr/lib/fpc/2.6.0/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi':
(.text+0x90): undefined reference to `_init'
./wiringPi.o: In function `gpioClockSet':
wiringPi.c:(.text+0xd20): undefined reference to `__aeabi_idiv'
wiringPi.c:(.text+0xd30): undefined reference to `__aeabi_idivmod'
./wiringPi.o: In function `interruptHandler':
wiringPi.c:(.text+0x1558): undefined reference to `piHiPri'
./wiringPi.o: In function `wiringPiISR':
wiringPi.c:(.text+0x17b4): undefined reference to `pthread_create'
./wiringPi.o: In function `pwmToneWrite':
wiringPi.c:(.text+0x1d30): undefined reference to `__aeabi_idiv'
./wiringPi.o: In function `pinMode':
wiringPi.c:(.text+0x1d88): undefined reference to `softPwmStop'
wiringPi.c:(.text+0x1d90): undefined reference to `softToneStop'
wiringPi.c:(.text+0x1f10): undefined reference to `softPwmCreate'
wiringPi.c:(.text+0x1f1c): undefined reference to `softToneCreate'
start.pas(10) Error: Error while linking
start.pas(10) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)

I use to have versions installed who do not have this problem. I can not fix it anymore. Can somebody help for a re-look.

complete unit:
Code: [Select]
unit hwiringpi;

(* Pascal wrapper unit for Gordon Henderson wiringPi library. The source can
 * be found at https://projects.drogon.net/raspberry-pi/wiringpi/. Wrapper and
 * pascal sample by Alex Schaller.
 * wiringPi:
 * Arduino compatable (ish) Wiring library for the Raspberry Pi
 * Copyright (c) 2012 Gordon Henderson
 * This file is part of wiringPi:
 * https://projects.drogon.net/raspberry-pi/wiringpi/
 *    wiringPi is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *    wiringPi is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    GNU General Public License for more details.
 *    You should have received a copy of the GNU General Public License
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.

// Handy defines

{$link ./wiringPi/wiringPi.o}
{$linklib c}


    NUM_PINS = 17;   
    WPI_MODE_PINS = 0;   
    WPI_MODE_GPIO = 1;   
    INPUT = 0;   
    OUTPUT = 1;   
    PWM_OUTPUT = 2;   
    LOW = 0;   
    HIGH = 1;   
    PUD_OFF = 0;   
    PUD_DOWN = 1;   
    PUD_UP = 2;

    // Pin mappings from P1 connector to WiringPi library
    // Px represents to physical pin on the RaspberryPi P1 connector
    P3  = 8;
    P5  = 9;
    P7  = 7;
    P8  = 15;
    P10 = 16;
    P11 = 0;
    P12 = 1;
    P13 = 2;
    P15 = 3;
    P16 = 4;
    P18 = 5;
    P19 = 12;
    P21 = 13;
    P22 = 6;
    P23 = 14;
    P24 = 10;
    P26 = 11;

Function wiringPiSetup:longint;cdecl;external;

Procedure wiringPiGpioMode(mode:longint);cdecl;external;

Procedure pullUpDnControl(pin:longint; pud:longint);cdecl;external;

Procedure pinMode(pin:longint; mode:longint);cdecl;external;

Procedure digitalWrite(pin:longint; value:longint);cdecl;external;

Procedure pwmWrite(pin:longint; value:longint);cdecl;external;

Function digitalRead(pin:longint):longint;cdecl;external;

Procedure delay(howLong:dword);cdecl;external;

Procedure delayMicroseconds(howLong:dword);cdecl;external;

Function millis:dword;cdecl;external;



PS: Does anyone have example code for the hwiringpi.pas unit ? Thank you very much in Advance.

Is this the right place to post this Message? What forum/topic should i try it again?
« Last Edit: September 22, 2015, 09:17:40 pm by pascalbythree »


  • Hero Member
  • *****
  • Posts: 7902
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: unit hwiringpi; on a RASPBERRY
« Reply #1 on: September 23, 2015, 06:11:41 am »
{$link ./wiringPi/wiringPi.o}
{$linklib c}
This won't be enough. At least I see reference to pthread_create, which means you also need to linklib pthread. I don't know which wiringPi are you using, but at least from here, it's clear that there are many .c files -> many .o / archived as 1 .a. linking to wiringPi.o alone won't be enough, as can be indicated in the linker error message.



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus