Build does not include source with file suffix - go

Compiling under ubuntu
Linux ip 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
x86_64 x86_64 x86_64 GNU/Linux
with golang version
go version go1.8.3 linux/amd64
The files I have:
daemon_darwin.go daemon_freebsd.go daemon.go daemon_linux.go
daemon_windows.go LICENSE os.go README.md
The command I'm executing
GOOS=darwin GOARCH=amd64 go build -x
The output I'm getting
WORK=/tmp/go-build026556308 mkdir -p
$WORK/github.com/VividCortex/godaemon/_obj/ mkdir -p
$WORK/github.com/VividCortex/ cd
/root/go/src/github.com/VividCortex/godaemon
/home/jenkinsBuilder/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go_1.8/pkg/tool/linux_amd64/compile
-o $WORK/github.com/VividCortex/godaemon.a -trimpath $WORK -p github.com/VividCortex/godaemon -complete -buildid
398bd35cdb7ed0aa42a3e6ea64677925441c29cb -D
_/root/go/src/github.com/VividCortex/godaemon -I $WORK -pack ./daemon.go ./os.go
# github.com/VividCortex/godaemon ./daemon.go:167: undefined: GetExecutablePath
we can see that daemon_darwin.go is not being included in the compile command, although I've added GOOS=darwin
If I try using GOOS=windows, it builds correctly, and daemon_windows.go is being added

Related

gccgo build can not find custom pakage

when use the gccgo build one single go file is ok, but whn I build a large multi custom pacage go mod project, the project have some sub package(such as app/ app/core/server etc) not build success.
how to fix this? anyhelp? I build with -x and see some debug info.
go build -x -gccgoflags -Wl,-R,/opt/gccgo/lib64/ -compiler gccgo -o bin/app main.go
the error is:
WORK=/tmp/go-build1609005358
mkdir -p $WORK/b001/
cd $WORK
/opt/gccgo/bin/gccgo -fgo-importcfg=/dev/null -c -x c - -o /dev/null || true
mkdir -p $WORK/b001/_importcfgroot_/github.com/gin-gonic
ln -s /home/liangqi1/.cache/go-build/8a/8ae3d6bb3097698b7be6547599d7a61c9c5c54cca0be55c007ca1c8386d1188c-d $WORK/b001/_importcfgroot_/github.com/gin-gonic/libgin.a
mkdir -p $WORK/b001/_importcfgroot_/github.com/logrusorgru
ln -s /home/liangqi1/.cache/go-build/6f/6fb602f3c990310188a3e921909d152810f07d50f1ab4c621ab71b87afd4942d-d $WORK/b001/_importcfgroot_/github.com/logrusorgru/libaurora.a
mkdir -p $WORK/b001/_importcfgroot_/go.uber.org
ln -s /home/liangqi1/.cache/go-build/c0/c0ac9f2f0ebb74e0997bfa1d72d21a79ce906ed736197f83402365203094c3a9-d $WORK/b001/_importcfgroot_/go.uber.org/libautomaxprocs.a
/opt/gccgo/bin/gccgo -ffile-prefix-map=a=b -c -x c - -o /dev/null || true
cd /home/liangqi1/gccgo_demo
/opt/gccgo/bin/gccgo -c -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fgo-relative-import-path=_/home/liangqi1/gccgo_demo -o $WORK/b001/_go_.o -I $WORK/b001/_importcfgroot_ -Wl,-R,/opt/gccgo/lib64/ ./main.go
# command-line-arguments
./main.go:7:23: 错误:import file ‘gccgo_demo/app’ not found
7 | "gccgo_demo/app"
| ^
./main.go:8:35: 错误:import file ‘gccgo_demo/app/core/server’ not found
8 | "gccgo_demo/app/core/server"
| ^
./main.go:24:19: 错误:reference to undefined name ‘app’
24 | if err := app.Init(prjHome); err != nil {
| ^
./main.go:29:12: 错误:reference to undefined name ‘app’
29 | if app.IsProd() {
| ^
./main.go:35:9: 错误:reference to undefined name ‘server’
35 | server.Run()
| ^
the gccgo just clone from gcc git:
gccgo (GCC) 12.0.1 20220217
go version is 1.16.4
my project struct like flow:
gccgo_demo
├── app
│   ├── app.go
│   ...
├── go.mod
├── go.sum
├── main.go
... other code
the go mod name is gccgo_demo so , the app/app.go has some import like gccgo_demo/app path.
I don't see your code but I guess the problem that you do not pass the include path.
The cgo tool will always invoke the C compiler with the source file's directory in the include path; i.e. -I${SRCDIR} is always implied. This means that if a header file foo/bar.h exists both in the source directory and also in the system include directory (or some other place specified by a -I flag), then "#include <foo/bar.h>" will always find the local version in preference to any other version.
So just do smth like
go build -x -gccgoflags -I/path/to/your/file -Wl,-R,/opt/gccgo/lib64/ -compiler gccgo -o bin/app main.go
More details https://pkg.go.dev/cmd/cgo

golang strip symbols with go build vs strip

Why does stripping symbols differ between strip and go build -ldflags "-s -w" (see here)?
$ go build -ldflags "-s -w" -o primes_no_symbols_from_go_build primes.go
$ go build -o primes primes.go && strip -s primes -o primes_no_symbols_from_strip
$ objdump -D primes_no_symbols_from_go_build > primes_no_symbols_from_go_build.human
$ objdump -D primes_no_symbols_from_strip > primes_no_symbols_from_strip.human
$ grep -rn "add" primes_no_symbols_from_go_build.human | wc -l
149568
$ grep -rn "add" primes_no_symbols_from_strip.human | wc -l
149556
what can account for these changes? (the underlying go program, probably irrelevant, is from here).
strip and ld tools are OS specific, from
man strip
When strip is used with no options on an executable file, it checks
that file to see
if it uses the dynamic link editor. If it does, the effect of the strip command is
the same as using the -u and -r options. If the file does not use the dynamic link
editor, the effect of strip without any options is the same as using the -s option of
ld(1). The options -S, -x, and -X have the same effect as the ld(1) options. The
options to strip(1) can be combined to trim the symbol table to just what is desired.
i.e. most ld's don't have -w, which means on OSX "suppress all warning messages"
on Linux/Debian
1187840 Jul 7 09:05 primes_no_symbols_from_go_build_s
1187840 Jul 7 09:05 primes_no_symbols_from_go_build_s_w
1755360 Jul 7 09:05 primes_simple_go_build
1187004 Jul 7 09:06 primes_simple_go_build_strip
on OSX
2076146 Jul 7 16:02 primes_no_symbols_from_go_build_s
1580786 Jul 7 16:02 primes_no_symbols_from_go_build_s_w
2076146 Jul 7 16:02 primes_simple_go_build
1997872 Jul 7 16:04 primes_simple_go_build_strip

Docker doesn't see a binary in PATH inside container

I'm trying to build a Docker image to help automatize code generation from Google Protocol Buffers spec files.
My current Dockerfile:
FROM alpine:latest
WORKDIR /protobuf
VOLUME /dst
RUN apk update \
&& apk add --no-cache bash \
&& apk add --virtual .build-deps curl unzip \
&& curl -k -L https://github.com/google/protobuf/releases/download/v3.6.0/protoc-3.6.0-linux-x86_64.zip -o protoc.zip \
&& unzip protoc.zip \
&& rm protoc.zip \
&& chmod +x ./bin/protoc \
&& apk --purge del .build-deps
COPY . spec/
RUN chmod +x spec/entrypoint.sh
ENV SRC_DIR=/usr/src/protoc/spec DST_DIR=/dst PATH=/protobuf/bin:${PATH}
ENTRYPOINT [ "/bin/bash" ]
When I build and run it with TTY enabled, it runs without issue. However, shell inside the container is somehow unable to see the /protobuf/bin/protoc binary, even though it should be able to:
bash-4.4# echo $PATH
/protobuf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
bash-4.4# ls -l /protobuf/bin
total 4444
-rwxr-xr-x 1 root root 4548312 Jun 15 23:40 protoc
bash-4.4# protoc
bash: /protobuf/bin/protoc: No such file or directory
What can be the issue here?
protobuf is linked against glibc library and alpine uses musl (and older alpine used uclibc). They are not compatible. The error you are seeing comes from the linker not finding the libc standard library /lib64/ld-linux-x86-64.so.2. You can check that, by issuing ldd command:
$ ldd /bin/protoc
/lib64/ld-linux-x86-64.so.2 (0x7faa1a641000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7faa1a641000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7faa1a641000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7faa1a641000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /bin/protoc)
The file exists and the PATH is ok.
To fix this you may install glibc on alpine (not recommended) or just move to a normal linux container.
#edit: My old answer was not true, bash nor sh does not source /etc/profile by default, only when supplied with -l option.

(CHICKEN) Could not install iup Eggs via the terminal

I tried to compile a scheme file with CHICKEN and it says there that I need to install the iup port of CHICKEN. So I went to the website and tried to install the iup port but I got an error. Then I realized I need to get ffcall. I got that installed and tried to install the iup port again. And failed.
I don't know if I got srfi-42 installed on my system. Even if I know it's not installed I still don't know how to install srfi-42 to get the iup port to work.
This is the error that I get:
ander#Ander:~/blah/chicken-4.11.0/chicken-4.11.0$ sudo chicken-install iup
retrieving ...
connecting to host "chicken.kitten-technologies.co.uk", port 80 ...
requesting "/henrietta.cgi?name=iup&mode=default" ...
reading response ...
HTTP/1.1 200 OK
Date: Sat, 12 Nov 2016 06:16:26 GMT
Server: Apache/2.2.31 (Unix) DAV/2 PHP/5.5.36 mod_fastcgi/2.4.6
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain
reading chunks ....
reading files ...
./iup-controls.scm
./iup-base.scm
./iup-config.scm
./iup-glcanvas.scm
./iup-dialogs.scm
./iup-dynamic.scm
./iup-glcontrols.scm
./iup-mglplot.scm
./iup-ole.scm
./iup-plot.scm
./iup-pplot.scm
./iup-scintilla.scm
./iup-types.scm
./iup-web.scm
./iup.meta
./iup.release-info
./iup.scm
./iup.setup
iup located at /tmp/temp5d54.6346/iup
checking platform for `iup' ...
checking dependencies for `iup' ...
install order:
("iup")
installing iup:1.8.0 ...
changing current directory to /tmp/temp5d54.6346/iup
'/usr/local/bin/csi' -bnq -setup-mode -e "(require-library setup-api)" -e "(import setup-api)" -e "(setup-error-handling)" -e "(extension-name-and-version '(\"iup\" \"1.8.0\"))" 'iup.setup'
'/usr/local/bin/csc' -feature compiling-extension -setup-mode -s -O2 -d1 iup.scm -j iup -j iup-base -j iup-controls -j iup-dialogs -j iup-glcanvas -j iup-glcontrols -j iup-plot -j iup-mglplot -j iup-pplot -j iup-scintilla -j iup-web -j iup-config -lcallback -liup -liupim -liupimglib -liupcontrols -liupmatrixex -liupgl -liupglcontrols -liup_plot -liup_mglplot -liup_pplot -liup_scintilla -liupweb
iup.c:17:16: fatal error: im.h: No such file or directory
compilation terminated.
Error: shell command terminated with non-zero exit status 256: 'gcc' 'iup.c' -o 'iup.o' -c -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -fPIC -DPIC -DC_SHARED -I/usr/local/include/chicken
Error: shell command failed with nonzero exit status 256:
'/usr/local/bin/csc' -feature compiling-extension -setup-mode -s -O2 -d1 iup.scm -j iup -j iup-base -j iup-controls -j iup-dialogs -j iup-glcanvas -j iup-glcontrols -j iup-plot -j iup-mglplot -j iup-pplot -j iup-scintilla -j iup-web -j iup-config -lcallback -liup -liupim -liupimglib -liupcontrols -liupmatrixex -liupgl -liupglcontrols -liup_plot -liup_mglplot -liup_pplot -liup_scintilla -liupweb
Error: shell command terminated with nonzero exit code
17920
"'/usr/local/bin/csi' -bnq -setup-mode -e \"(require-library setup-api)\" -e \"(...
I know it's pretty long but the error pops up just about at the end of the heap of output above.
The real error here is iup.c:17:16: fatal error: im.h: No such file or directory, which is actually the C compiler complaining.
This error means either you don't have the development package for iup installed (system headers), or the C compiler cannot find the header files because it's in a nonstandard location. If it's the latter, you can try CSC_OPTIONS=-I/path/to/include chicken-install iup
Unfortunately, IUP itself is known to be a real pain to install, mostly because very few distros have packages for it. What you didn't say in your message is why exactly you need iup. Is this some kind of program you're trying to install, which uses CHICKEN plus IUP?

gcov cannot open graph file

I'm getting the following error when trying to run gcov as part of my Travis CI build:
$ gcov src/bgrep.c
bgrep.gcno:cannot open graph file
My .travis.yml:
language: c
compiler: gcc
sudo: false
before_script:
- uname -a
- printenv
- gcov --version
script:
- scons coverage=1
- ls -l src/
- test/run_test.py
- ls -l src/
- gcov src/bgrep.c
- ls -l src/
- ls -l
after_success:
- bash <(curl -s https://codecov.io/bash)
I can run the exact sequence of commands (scons, test/run_test.py, gcov src/bgrep.c) on my Fedora machine, and gcov produces grep.gcov as expected.
Travis is using gcov (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3. You can see an example build log here.
What am I (or Travis) doing wrong?
I had the same problem with gcov and travis. It seems that gcov indeed requires that the *.gcda and *.gcno files must be in the same directory as the *.c files. And additionally the -o option must be given which points then to the same directory...
So, I have the source files in folder src/ and the binaries in build/coverage/. First, I tried with 'gcov -o build/coverage/ src/*.c' which did not work. Second attempt was with copying the *.gc* files to src/ and executing 'gcov src/*.c' which also did not work. It finally worked with 'gcov -o src/ src/*.c'.

Resources