-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Error on Github Actions: could not import C (cgo preprocessing failed) #1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The reason for this working on your local machine and not in the workflow is because you've also installed some dependent C libraries on your machine ( $ go test ./...
# github.com/grongor/go-snmp-proxy/snmpproxy
snmpproxy/mib.go:6:10: fatal error: net-snmp/net-snmp-config.h: No such file or directory
#include <net-snmp/net-snmp-config.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated. Reproducable MVP in Docker outside GitHub action: FROM golang:latest
WORKDIR /workspace
RUN curl -sSfL \
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(go env GOPATH)/bin v1.27.0
RUN git clone https://github.com/grongor/go-snmp-proxy.git
WORKDIR /workspace/go-snmp-proxy
RUN git fetch origin && git checkout first-version
CMD [ "golangci-lint", "run" ] $ docker build -t lint .
$ docker run --rm lint
level=warning msg="[runner] Can't run linter goanalysis_metalinter: bodyclose: failed prerequisites: [[email protected]/grongor/go-snmp-proxy/snmpproxy: analysis skipped: errors in package: [/workspace/go-snmp-proxy/snmpproxy/mib.go:9:8: could not import C (cgo preprocessing failed)]]"
level=warning msg="[runner] Can't run linter unused: buildir: analysis skipped: errors in package: [/workspace/go-snmp-proxy/snmpproxy/mib.go:9:8: could not import C (cgo preprocessing failed)]"
level=error msg="Running error: buildir: analysis skipped: errors in package: [/workspace/go-snmp-proxy/snmpproxy/mib.go:9:8: could not import C (cgo preprocessing failed)]" So to sum it up, you need to add your header files in |
OMG! I should've figured that out...This was my first time playing with cgo so I wasn't sure about many things. I'm so sorry for wasting your time like that and thank you for taking the time to write such a detailed answer. Just for reference, the solution was really simple: - name: Install dependencies
run: sudo apt update && sudo apt install libsnmp-dev |
By the way, do you @bombsimon think that it would be possible to improve the error message somehow, ideally telling the user that it wasn't able to include the required headers? That would immediately put me on the right path...at first I though "ok, golangci-lint doesn't work with C imports at all"...if so, I would take look it :) |
I don't think |
Do you have any suggestions on how to debug this issue? I'm seeing it for my project where everything works fine locally, and building on CI works without issue, but |
still not clear what to do in order to resolve this |
Version of golangci-lint
Config file
Go environment
Verbose output of running
Hello, I have an issue with golangci-lint in Github Actions. I tried using the official

golangci/golangci-lint-action@v1
, then tried manually installing the linter and then I even tried running it multiple times just to see if it's not a random fail. Neither run was succesful and I'm always getting some errors regardingcould not import C (cgo preprocessing failed)
. Strange thing is that if I run the linter locally, everything works as expected (I even tried multiple versions...), see screenshot:Here are the failed builds (with detailed info):
I also tried removing the golangci-lint locally, and running it in the same way as I do on CI ... and it works:
The text was updated successfully, but these errors were encountered: