Unable to link C shared library in go project

All I have create a custom package of a C shared library, here https://github.com/err-him/go-dcc In this repo I am creating the shared library using Makefile https://github.com/err- him/go-dcc/blob/main/Makefile

When I use this library in this package itself, I am getting successful result but when some other package in GO uses it, it will throw linter error I am accessing this as

  // Package dcc Package provides dcc common code.
  package dcc

   // #cgo CFLAGS: -I${SRCDIR}/
// #cgo linux LDFLAGS: -ldl -Wl,--unresolved-symbols=ignore-in-object-files
// #cgo darwin LDFLAGS: -ldl -Wl,-undefined,dynamic_lookup
// #cgo LDFLAGS: -L${SRCDIR}/ -lm -lresolv -ldccmj
// #include <stdlib.h>
// #include <stdio.h>
// #include "dccmj.h"
import "C"      //nolint:depguard,gocritic // Required for calling c library
import "unsafe" //nolint:depguard,gocritic // Required for free the memory

//ChecksumGenerator generates dcc checksum
func ChecksumGenerator(html string) string {
    var checksum string
    input := C.CString(html)
    defer C.free(unsafe.Pointer(input))
    ptr := C.CString(checksum)
    defer C.free(unsafe.Pointer(ptr))
    C.fingerprint(input, ptr)
    return C.GoString(ptr)

and in some other project I am using this as

package main

import (
    dcc "github.com/err-him/go-dcc"

func main() {
    html := "X-Mailin-EID:NTQwMzk0MzB%2BaS5rbGVpbkBob3RtYWlsLmZyfjwyMDIwMDcyMjEzMDcuNjMzMzUwMDQ2MjdAc210cC1yZWxheS5tYWlsaW4uZnI%2BfmVtWlsLmZhbWlsZW8uY29tnTo: i.klein@hotmail.frnDate: Wed, 22 Jul 2020 11:07:08 +0000nSubject: Confirmation d'inscriptionnMessage-Id: <0d7398ec-4e64-4b6e-980d-a44f68c6500d@smtp-relay.sendinblue.com>nOrigin-messageId: <202007221307.63335004627@smtp-relay.mailin.fr>nContent-Type: text/html; charset=utf-8nContent-Transfer-Encoding: quoted-printablenMIME-Version: 1.0nX-sib-id: g9mCPC8MHeHJarheS6CxOXJ2uYjG4c25hscyFmYoyu14XdNnMaW8cVS8CTXMwg5F4XbZIAmMDg8xsbNkdK2BEOetJi6wPX-NAFp7a3QjOBiy-BGQt5zOAEdMP-MG1PpgYsWVypD322DcHc055aD-o9r_jfW9QIMLvJaNRot3vNsnX-CSA-Complaints: whitelist-complaints@eco.denrnBODY starts here, this is test emailYour work Projects Filters Dashboards People Plans Apps Create Search 9+ 3+ Projects Email Sending email-sending (sprint view) 4 days remainingComplete sprint Board Tools 3rd Jan - 14th Jan - 2022 Show tickets assigned to Regular BluSky Only My Issues Recently Updated Insights TO DO 2 IN PROGRESS 3 CODE IN REVIEW 0 QA IN DEV/STAGING 0 DONE IN STAGING 0 QA IN PROD 1 DONE 2 Dharmendra Yadav2 issues Implement DIC pattern - Fetch Process Consumer Implement DIC pattern TaskMajor priority5 Assignee: Dharmendra Yadav ES 33- specs DCC fingerprint DCC fingerprint in email-sending TaskMajor priority1 Assignee: Dharmendra Yadav ES 512- Dharmendra Yadav4 issues expired-process test coverage improve email-sending test coverage improvement TaskMajor priority3 Assignee: Himanshu Gupta ES 321- handle empty emails records in testmail producer/consumer TaskMajor priority2 Assignee: Himanshu Gupta ES 506- POC DCC fingerprint DCC fingerprint in email-sending TaskMajor priority5 Assignee: Himanshu Gupta ES 513- How to do migration GCP migration TaskMajor priority3 Assignee: Himanshu Gupta ES 509- Sagar Sachdev2 issues ES-501Added Kafka consumers for Sendmail Transarchive Project QA for ES-501 Sub-taskMajor priority Assignee: Sagar Sachdev ES 514- Added Kafka consumers for Sendmail Transarchive Project TaskMajor priority3 Assignee: Sagar Sachdev ES 501-"
    checksum := dcc.ChecksumGenerator(html)

the error I am getting after go build

/tmp/go-build3303125424/b408/sendtomta.test: symbol lookup error: /tmp/go-build3303125424/b408/sendtomta.test: undefined symbol: dcc_syslog_init

Can anyone pls help, what I am doing wrong ? PS: I tried many things but I suspect it’s cross platform issue, when I am creating the library I am using macOS but in build I am using ubuntu, any idea ?

Makefile I am using is



    CC = gcc
    CFLAGS = -I./dccsib/include -Wall -g #-pedantic -Wall -Wextra -ggdb3
    LDFLAGS = -L. libtool -static -a
    LDFLAGS = -Wl,-rpath=${SRCDIR}/
    LDFLAGS = -Wl,--unresolved-symbols=ignore-in-object-files
    LDFLAGS = -Wl,-undefined,dynamic_lookup
    LIBS    = -L. -lpthread -lm -lresolv -ldccmj

    SRC = ./dccsib/dcclib/dccif.c ./dccsib/dcclib/fnm.c ./dccsib/dcclib/get_port.c ./dccsib/dcclib/hstrerror.c ./dccsib/dcclib/inet_ntop.c ./dccsib/dcclib/ipv6_conv.c ./dccsib/dcclib/lock_stubs.c ./dccsib/dcclib/logbad.c ./dccsib/dcclib/mk_su.c ./dccsib/dcclib/msg1.c ./dccsib/dcclib/parse_srvr_nm.c ./dccsib/dcclib/parse_word.c ./dccsib/dcclib/strlcat.c ./dccsib/dcclib/strlcpy.c ./dccsib/dcclib/su2str.c ./dccsib/dcclib/vsyslog.c ./dccsib/dcclib/win32.c ./dccsib/clntlib/aop.c ./dccsib/clntlib/ask.c ./dccsib/clntlib/cdhome.c ./dccsib/clntlib/ck.c ./dccsib/clntlib/ck2str.c ./dccsib/clntlib/ckbody.c ./dccsib/clntlib/ckfuz1.c ./dccsib/clntlib/ckfuz2.c ./dccsib/clntlib/ckmime.c ./dccsib/clntlib/ckparse.c ./dccsib/clntlib/cktbls.c ./dccsib/clntlib/ckwhite.c ./dccsib/clntlib/clnt_init.c ./dccsib/clntlib/clnt_send.c ./dccsib/clntlib/clnt_unthreaded.c ./dccsib/clntlib/daemon.c ./dccsib/clntlib/dnsbl.c ./dccsib/clntlib/escstr.c ./dccsib/clntlib/get_id.c ./dccsib/clntlib/get_secs.c ./dccsib/clntlib/getifaddrs.c ./dccsib/clntlib/hash_divisor.c ./dccsib/clntlib/heap_debug.c ./dccsib/clntlib/helper.c ./dccsib/clntlib/id2str.c ./dccsib/clntlib/inet_pton.c ./dccsib/clntlib/load_ids.c ./dccsib/clntlib/lock_open.c ./dccsib/clntlib/md5.c ./dccsib/clntlib/mkstemp.c ./dccsib/clntlib/msg2.c ./dccsib/clntlib/op2str.c ./dccsib/clntlib/parse_log_opt.c ./dccsib/clntlib/parse_passwd.c ./dccsib/clntlib/parse_whitefile.c ./dccsib/clntlib/print_info.c ./dccsib/clntlib/range.c ./dccsib/clntlib/restart.c ./dccsib/clntlib/select_poll.c ./dccsib/clntlib/sign.c ./dccsib/clntlib/str2cnt.c ./dccsib/clntlib/str2type.c ./dccsib/clntlib/tgts2str.c ./dccsib/clntlib/type2str.c ./dccsib/clntlib/udp_bind.c ./dccsib/clntlib/xhdr.c ./dccmj.c

    OBJ = $(SRC:.c=.o)

    $(STATIC): $(OBJ)
        @echo "[Link (Static)]"
        cd dccsib && ./configure --disable-dccm && cd ..
        ar crv $@ $^

        @echo [Compile] $<
        @$(CC) -c $(CFLAGS) $< -o $@

        rm -f $(OBJ) *~ core tags *.bak Makefile.bak libgeniePi.*

    .PHONY: install
    install: $(STATIC)
        @install -m 0755 $< $(DESTDIR)

    all: install
        $(CC) -g -Wall -o program dccmj.c $(LDFLAGS) $(LIBS)

Leave a Comment