0

Go/gccgo version: 6.3.0

I am building a program with go build -compiler gccgo -x <args> <args> program.go. Build process fails with

% /usr/bin/gccgo -c -g -fgo-pkgpath=<file_path>/common/flogging -fgo-relative-import-path=<file_path>/common/flogging -o <dest_path>/common/flogging/)obj/_go_.o ./logging.go (some program specific args omitted)
% <file_path>/common/flogging
common/flogging/logging.go:26:26: error: import file 'github.com/op/go-
logging' not found
  "github.com/op/go-logging"
                          ^

logging.go imports

import (
    "io"
    "os"
    "regexp"
    "strings"
    "sync"

    "github.com/op/go-logging"
)

If I compile logging.go standalone with go build, it compiles fine:

[root@eef079aa0103 flogging]# go build logging.go 
[root@eef079aa0103 flogging]# go build -compiler gccgo logging.go 

If I run the /usr/bin/gccgo command standalone, the error persists.

[root@eef079aa0103 flogging]# /usr/bin/gccgo <args> logging.go (args same with above) 
logging.go:26:26: error: import file 'github.com/op/go-logging' not found
  "github.com/op/go-logging"  
                          ^

I used strace to track

% strace -f -o aa /usr/bin/gccgo <args> logging.go (args same with above)

and found out that open("/opt/gopath/src/github.com/op/go-logging", O_RDONLY) = 10 open("/opt/gopath/src/github.com/op/go-logging.gox", O_RDONLY) = -1 ENOENT (No such file or directory) open("/opt/gopath/src/github.com/op/libgo-logging.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/opt/gopath/src/github.com/op/libgo-logging.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/opt/gopath/src/github.com/op/go-logging.o", O_RDONLY) = -1 ENOENT (No such file or directory)

the compiler is able to find go-logging package in my $GOPATH, but it fails for not seeing anything with .gox .so .a or .o file.

Which agrees with whats on the Go website:

When you import the package FILE with gccgo, it will look for the import data in the following files, and use the first one that it finds.

FILE.gox FILE.o libFILE.so libFILE.a

The gccgo compiler will look in the current directory for import files

Any idea how could I resolve the issue?

Thanks.

chingy
  • 31
  • 1
  • 3
  • `go env` and tells us what your setup is. Also may want to run `which go` and `which gccgo` – eduncan911 Apr 18 '17 at 02:30
  • `gccgo` is just the compiler, it's not a replacement for the `go` tool. If you want to see how the compiler is invoked, use the `-x` flag: `go build -x -compiler gccgo logging.go` – JimB Apr 18 '17 at 12:56
  • @JimB You are right. My original attempt was to build a program, to which a Makefile (and inside, a 'go build' command) was already given. The build fails and I used the '-x' flag to narrow down to a 'gccgo' command where it could not import. The example above was just manually running that command standalone. – chingy Apr 19 '17 at 17:05
  • Updated the question with some clarifications and recent development. – chingy Apr 19 '17 at 17:40

0 Answers0