douan3019 2011-07-26 20:13
浏览 28
已采纳

我可以做getest pass编译器标志吗?

I have just put together a Go package that is going to be a part in a fairly large system with a lot of shared packages. I was able to get it to compile by writing its Makefile such that the compiler is called with -I flags:

include $(GOROOT)/src/Make.inc

TARG=foobar
GOFILES=\
    foobar.go\

foobar:
    $(GC) -I$(CURDIR)/../intmath -I$(CURDIR)/../randnum foobar.go

include $(GOROOT)/src/Make.pkg

It compiles just fine, and being a good boy, I wrote a comprehensive set of tests. However, when I try to run the tests with gotest, I get a compile error:

$ gotest
rm -f _test/foobar.a
8g  -o _gotest_.8 foobar.go  foobar_test.go
foobar.go:4: can't find import: intmath
make: *** [_gotest_.8] Error 1
gotest: "C:\\msys\\bin\\sh.exe -c \"gomake\" \"testpackage\" \"GOTESTFILES=foobar_test.go\"" failed: exit status 2

So, the Go file itself will compile when I use the -I flags to tell it where to find the intmath and randnum packages, but gotest doesn't seem to use the Makefile.

Answering peterSO's question: foobar.go's import section looks like this:

import (
    "intmath"
    "randnum"
    "container/vector"
)

And the compile works fine as long as I have the -I flags going to the compiler. I have tried to use relative paths, like this:

import (
    "../intmath"
    "../randnum"
    "container/vector"
)

but that just doesn't seem to work.

EDIT: answering further peterSO questions:

GOROOT is set to C:\Go the directory where I have all of the Go stuff -- aside from my source code -- installed. I was expecting the relative path to be relative to the directory in which the source file lives.

My source tree looks like this:

server/
    foobar/
    randnum/
    intmath/

So, while I am open to a different, more Go-idiomatic directory structure, my instinct is to arrange them as peers.

Is there some way that I can nudge gotest into compiling foobar.go with the needed flags?

  • 写回答

1条回答 默认 最新

  • douju7765 2011-07-26 22:00
    关注

    Create the Windows source code directory structure:

    C:\server
    C:\server\foobar
    C:\server\intnum
    

    For intnum.go:

    package intnum
    
    func IntNum() int {
        return 42
    }
    

    Makefile:

    include $(GOROOT)/src/Make.inc
    TARG=server/intnum
    GOFILES=\
        intnum.go\
    include $(GOROOT)/src/Make.pkg
    

    Run:

    $ cd c/server/intnum
    $ make install
    

    For foobar.go:

    package foobar
    
    import (
        "math"
        "server/intnum"
    )
    
    func FooBar() float64 {
        return float64(intnum.IntNum()) * math.Pi
    }
    

    Makefile:

    include $(GOROOT)/src/Make.inc
    TARG=server/foobar
    GOFILES=\
        foobar.go\
    include $(GOROOT)/src/Make.pkg
    

    Run:

    $ cd /c/server/foobar
    $ make install
    

    After the install, the intnum.a and foobar.a package files will be in the $GOROOT\pkg\windows_386\server (C:\Go\pkg\windows_386\server) directory`.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决