ca110us / go-clamav

go wrapper for libclamav
GNU General Public License v2.0
33 stars 12 forks source link

Error in building... #9

Open UnveilTech opened 1 year ago

UnveilTech commented 1 year ago

Hello,

trying to use your example but something wrong ;o) Go: go1.21.3

compilation: CGO_LDFLAGS="-L/usr/local/lib -lclamav" go run main.go

"error: ca110us/go-clamav@v0.6.0/define.go:128:45: cannot use _Ctype_int(code) (value of type _Ctype_int) as _Ctype_cl_error_t value in argument to (_Cfunc_cl_strerror)"

any idea ? bye Fred

marius-enlock commented 1 year ago

You either have an older version of libclamav or too new version of libclamav; check clamav.h in /usr/local/include to see the signature of the cl_strerror; if you do not want to upgrade you can modify the ca110us/go-clamav@v0.6.0/define.go::128 to not use the Ctype_int(code) and instead use the Ctype_cl_error_t.

But I think your error will go away if you use the latest version of libclamav built from source 1.2.0

tmheath commented 10 months ago

@marius-enlock

Trying to get this running for something I'm working on to help a friend out. Building from source ClamAV 1.2.1 is a single minor version ahead of your mention of 1.2.0 but building this I'm getting the same error message. From the below I know I'm building the closest version that I can via my package manager. I can show you all of my code, but this is just a build issue, I don't see how that would be useful right now.

`

Completed (1 of 1) app-antivirus/clamav-1.2.1::gentoo

My exact question is, am I doing something wrong, and if I am what should I try, if I'm not then how would you recommend that I try working around it?

jasperkuperus commented 10 months ago

I had some issues with building from source as well. Easiest option I think is taking the clamav docker image, run your app from there.

marius-enlock commented 10 months ago

@marius-enlock

Trying to get this running for something I'm working on to help a friend out. Building from source ClamAV 1.2.1 is a single minor version ahead of your mention of 1.2.0 but building this I'm getting the same error message. From the below I know I'm building the closest version that I can via my package manager. I can show you all of my code, but this is just a build issue, I don't see how that would be useful right now.

`

Completed (1 of 1) app-antivirus/clamav-1.2.1::gentoo

  • Messages for package app-antivirus/clamav-1.2.1:
  • You must run freshclam manually to populate the virus database
  • before starting clamav for the first time.
  • This version of ClamAV provides separate OpenRC services
  • for clamd, freshclam, clamav-milter, and clamonacc. The
  • clamd service now starts only the clamd daemon itself. You
  • should add freshclam (and perhaps clamav-milter) to any
  • runlevels that previously contained clamd.
  • GNU info directory index is up-to-date. `

My exact question is, am I doing something wrong, and if I am what should I try, if I'm not then how would you recommend that I try working around it? @tmheath

This are the steps from my CI/CD that builds it from source, and links it statically for my go program:

 sudo apt-get update && sudo apt-get install -y \
          gcc make pkg-config python3 python3-pip python3-pytest valgrind \
          check libbz2-dev libcurl4-openssl-dev libjson-c-dev libmilter-dev \
          libncurses5-dev libpcre2-dev libssl-dev libxml2-dev zlib1g-dev liblzma-dev

        sudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sudo sh -s -- -y

        sudo apt-get install cmake

        sudo wget https://www.clamav.net/downloads/production/clamav-1.2.0.tar.gz
        sudo tar xzf clamav-1.2.0.tar.gz
        cd clamav-1.2.0
        sudo mkdir build && cd build
        sudo cmake -DENABLE_STATIC_LIB=ON -DENABLE_SHARED_LIB=OFF -DENABLE_JSON_SHARED=OFF -DLIBXML2_INCLUDE_DIR="/usr/include/libxml2/" -DLIBXML2_LIBRARY="/usr/lib/x86_64-linux-gnu/libxml2.so" -DENABLE_UNRAR=ON ..
        sudo cmake --build .
        sudo cmake --build . --target install

        sudo apt-get install -y clamav-freshclam

        sudo mkdir -p /var/log/clamav
        sudo chown -R clamav /var/log/clamav
        sudo mkdir -p /var/lib/clamav
        sudo chown -R clamav /var/lib/clamav
        sudo chmod -R 777 /var/lib/clamav
        sudo chmod -R 777 /var/log/clamav
        sudo chown -R clamav /var/log/clamav
        sudo echo "" > /var/log/clamav/freshclam.log
        sudo chmod -R 777 /var/log/clamav
        sudo chmod -R 777 /usr/local/etc/
        sudo printf "\nDatabaseOwner clamav\nUpdateLogFile /var/log/clamav/freshclam2.log\nLogVerbose false\nLogSyslog false\nLogFacility LOG_LOCAL6\nLogFileMaxSize 0\nLogRotate true\nLogTime true\nForeground false\nDebug false\nMaxAttempts 5\nDatabaseDirectory /var/lib/clamav\nDNSDatabaseInfo current.cvd.clamav.net\nConnectTimeout 30\nReceiveTimeout 0\nTestDatabases yes\nScriptedUpdates yes\nCompressLocalDatabase no\nBytecode true\nNotifyClamd /etc/clamav/clamd.conf\n# Check for new database 24 times a day\nChecks 1\nDatabaseMirror db.local.clamav.net\nDatabaseMirror database.clamav.net\n" > /usr/local/etc/freshclam.conf
        sudo chmod -R 777 /usr/local/etc/freshclam.conf
        sudo freshclam --foreground

and then I build the go program like this:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib/x86_64-linux-gnu:$CLAMAV_BASE_PATH/clamav-1.2.0/build/x86_64-unknown-linux-gnu/release:#CLAMAV_BASE_PATH/clamav-1.2.0/build/libclamunrar:$CLAMAV_BASE_PATH/clamav-1.2.0/build/libclamunrar_iface CGO_LDFLAGS="-L/usr/local/lib/libclamav_static.a -lclamav_static -L/usr/local/include -l:libxml2.a -l:libpcre2-16.a -l:libz.a -lcrypto -l:libjson-c.a -lbz2 -l:libmspack.so.0 -L$CLAMAV_BASE_PATH/clamav-1.2.0/build/x86_64-unknown-linux-gnu/release -L$CLAMAV_BASE_PATH/clamav-1.2.0/build/libclamunrar -L$CLAMAV_BASE_PATH/clamav-1.2.0/build/libclamunrar_iface -l:libclamav_rust.a -l:libpcre2-8.a -l:libclamunrar_iface_static.a -l:libclamunrar_static.a -l:liblzma.a -l:libicuuc.a -l:libicudata.a" go build -v ./...

CLAMAV_BASE_PATH is the full path where the folder got extracted at this step:

        sudo wget https://www.clamav.net/downloads/production/clamav-1.2.0.tar.gz
        sudo tar xzf clamav-1.2.0.tar.gz
        cd clamav-1.2.0

For example: /home/marius/Desktop where the folder clamav-1.2.0 got extracted

To use it dynamically it is similar, but you would need .so files instead of .a, I no longer have the script for building it dynamically and linking it in the go program as I had no need for it. You can get to it by minor changes in the build flags, and in the env variables needed to build the go program.

Hope this helps.

tmheath commented 10 months ago

Thanks, I'll try building from home tonight.

tmheath commented 10 months ago

@jasperkuperus

Docker is not a solution. I'm writing this to run as a simple/free thing for MS Windows. I just read through the docker documentation, even ignoring the fact that for having a GUI I'd be required to have at least two packages instead of one, I'd have to constantly change the scandir mount (while trying to for instance scan on demand over specific folders such as downloads and schedule scans so there could be a queue to manage). I've got a part of the GUI designed, if I'm unable to figure out how to build this properly, then I might end up just using the cli directly. Thanks though, that was at least a good rough idea.

marius-enlock commented 7 months ago

@tmheath Relevant discussion on building it for windows: https://github.com/ca110us/go-clamav/issues/6

tungyao commented 6 months ago

replace define.go C.cl_error_t to C.int , I changed it and It has been compiled