golang with imported c lib problems

119 views Asked by At

I use a USB Device wit a single Button and LED inside.

I tested software to change color of the device, API for the hardware is only implemented in c: https://github.com/katie-snow/Ultimarc-linux

To run it at golang, the c-code was embedded in go-code (above import "C") The c-library "libultimarc" of the USB-Button was provided to the sw as static c lib: libultimarc.a Also the lib for USB is static: libusb-1.0.a Other libs are dynamic. (see ldd below)

I use Linux and x86_64 computers. Build-host is ubuntu, test Host is debian.

The program compiles and works nice, the color of the USB Device is changing as intended. But only at the build system.

If I try to run the executable from the compile-host at other x86_64 linux machines (test-host) it is doing nothing, just waiting without any response.

Golang code with embedded c-code goC-LedButton.go :

package main
/*
// Everything in comments above the import "C" is C code and will be compiled with GCC. 
#cgo LDFLAGS: "/home/user/BUTTON/Ultimarc-linux/src/libs/.libs/libultimarc.a"  "/home/user/BUTTON/libusb-1.0.26/libusb/.libs/libusb-1.0.a" "-ludev" "-ljson-c" 
// path of json.h
#cgo CFLAGS: "-I/usr/local/include/json-c/" 

#include "Ultimarc-linux/src/libs/ulboard.h"
#include "Ultimarc-linux/src/libs/common.h"
#include "Ultimarc-linux/src/libs/usbbutton.h"
#include "Ultimarc-linux/src/libs/ipacseries.h"

#include <json.h>

int changeColor(char *str) {
    ulboard myboard;
    myboard.type = ulboard_type_usbbutton;
    myboard.version = ulboard_version_null;
    struct json_object *parsed_json_color;
    _Bool ret;
    parsed_json_color = json_tokener_parse(str);
    ret = updateBoardUSBButtonColor(parsed_json_color, &myboard);
    return ret;
}

int toRed(void) {
    _Bool ret;
    char *str = "{ \"red\" : 255,  \"green\" : 0, \"blue\" : 0 }";
    ret = changeColor(str);
    return ret;
}

int toGreen(void) {
    _Bool ret;
    char *str = "{ \"red\" : 0,  \"green\" : 255, \"blue\" : 0 }";
    ret = changeColor(str);
    return ret;
}

int toBlue(void) {
    _Bool ret;
    char *str = "{ \"red\" : 0,  \"green\" : 0, \"blue\" : 255 }";
    ret = changeColor(str);
    return ret;
}
 */
import "C"
import "fmt"

func main() {


       c := C.toRed()
       fmt.Println("Changing Color to Red ", c )
       
       c = C.toGreen()
       fmt.Println("Changing Color to Green ", c )

       c = C.toBlue()
       fmt.Println("Changing Color to Blue ", c )

}

Used libraries of binary:

ldd goC-LedButton
        linux-vdso.so.1 (0x00007ffe9fafa000)
        libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007ff9cbd49000)
        libjson-c.so.3 => /lib/x86_64-linux-gnu/libjson-c.so.3 (0x00007ff9cbd3b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff9cbd18000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff9cbb26000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff9cbd9c000)

The lib /lib/x86_64-linux-gnu/libjson-c.so.3 is on both machines installed.

The problem is that the sw is not running on other machines, and I don't understand why. The behavior is, that at the test-host it is not responding at all after start, but can be stopped with [str]+[c].

I will be very thankful for hints about how to get the sw also running on the test-host. It's most probable a lib problem?

All the best, Alex

0

There are 0 answers