0 votes
1 view
in Blockchain by (4.1k points)

Here is my code:

package main

import (
    kusb "github.com/karalabe/usb"
    tusb "github.com/trezor/trezord-go/usb"

func main() {
    kusb.Enumerate(0, 0)

When I compile (I'm using go mod to manage the packages), it returns this error:

duplicate symbol _libusb_dev_mem_alloc in:
ld: 136 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)



Some investigation i had:

The both packages use the same hidapi and libusb C packages in order to interact with usb devices.
Those C packages are identical, hence it defines the same functions so i think it is directly related to the error.
in trezord-go/usb, they include .C file, not the header file.
It is very counterintuitive to me because in the perspective of package users, I shouldn't need to worry about how a C package is used in the internal of the package, only the exposed types, functions and its behaviors.

Can anyone really explain what is going on here and how can I import both of them? They do different functions, eventhough they use the same C package.

1 Answer

0 votes
by (14.4k points)

We are facing the issue because what we are doing is trying to link the same method from multiple source files. Update the header of the method and the source file. Finally, you can update your reference to the method in the CGo code that you have written.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !