dongyao4003 2012-03-30 09:11
浏览 213
已采纳

在GO(GO1)中使用多个文件进行构建

Does anyone know if it's possible to use the "go build" command to build from multiple files in a directory? For example

src/
  file1.go
  file2.go

Where file1.go contains the "func main()" method and file2 provides supporting functions. I've tried by using the following import statements but I'm getting no where

import (
  "file2"
)

import (
  file2 "./file2"
)

I'm wondering if this is a case that I need to modify the GOROOT environment variable to get this to work. Or if I'm just being daft and missing something blindingly obvious.

Thanks

  • 写回答

1条回答 默认 最新

  • duandu1049 2012-03-30 09:13
    关注

    If file1.go and file2.go are part of the same package, this should work fine. You don't have to import files from the same package into each other. Their variables and functions are already shared.

    If the files belong to different packages, they should be in different directories.

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

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿