help: go build 失败,提示 usage: compile [options] file.go... - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
codists
V2EX    Go 编程语言

help: go build 失败,提示 usage: comple [options] file.go...

  •  
  •   codists
    codists 2024-05-18 19:15:51 +08:00 1981 次点击
    这是一个创建于 564 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一、说明

    GOROOT=D:\apps\go1.18 GOPATH=D:\GoProject 

    二、问题描述

    在 D:\GoProject\src\power\project_name\cmd\listener> 目录下执行 go build 命令(说明:project 是 项目名称):

    \GoProject\src\power\project\cmd\listener>go build .\main.go 

    结果编译失败,提示信息如下:

    # auto-task/task/create usage: compile [options] file.go... -% int debug non-static initializers -+ compiling runtime -B disable bounds checking -C disable printing of columns in error messages -D path set relative path for local imports -E debug symbol export -G accept generic code (default 3) -I directory add directory to import search path -K debug missing line numbers -L show full file names in error messages -N disable optimizations -S print assembly listing -V print version and exit -W debug parse tree after type checking -asan build code compatible with C/C++ address sanitizer -asmhdr file write assembly header to file -bench file append benchmark times to file -blockprofile file write block profile to file -buildid id record id as the build id in the export metadata -c int concurrency during compilation (1 means no concurrency) (default 1) -clobberdead clobber dead stack slots (for debugging) -clobberdeadreg clobber dead registers (for debugging) -complete compiling complete package (no C or assembly) -cpuprofile file write cpu profile to file -d value enable debugging settings; try -d help -dwarf generate DWARF symbols (default true) -dwarfbasentries use base address selection entries in DWARF (default true) -dwarflocationlists add location lists to DWARF in optimized mode (default true) -dynlink support references to Go symbols defined in other shared libraries -e no limit on number of errors reported -embedcfg file read go:embed configuration from file -gendwarfinl int generate DWARF inline info records (default 2) -goversion string required version of the runtime -h halt on error -importcfg file read import configuration from file -importmap definition add definition of the form source=actual to import map -installsuffix suffix set pkg directory suffix -j debug runtime-initialized variables -json string version,file for JSON compiler/optimizer detail output -l disable inlining -lang string Go language version source code expects -linkobj file write linker-specific object to file -linkshared generate code that will be linked against Go shared libraries -live debug liveness analysis -m print optimization decisions -memprofile file write memory profile to file -memprofilerate rate set runtime.MemProfileRate to rate -msan build code compatible with C/C++ memory sanitizer -mutexprofile file write mutex profile to file -nolocalimports reject local (relative) imports -o file write output to file -p path set expected package import path -pack write to file.a instead of file.o -r debug generated wrappers -race enable race detector -shared generate code that can be linked into a shared library -smallframes reduce the size limit for stack allocated objects -spectre list enable spectre mitigations in list (all, index, ret) -std compiling standard library -symabis file read symbol ABIs from file -t enable tracing for debugging the compiler -traceprofile file write an execution trace to file -trimpath prefix remove prefix from recorded source file paths -v increase debug verbosity -w debug type checking -wb enable write barrier (default true) 

    说明:(1)错误提示中第一行的 auto-task/task/create 是项目的目录。

    二、尝试的解决方法

    1.修改 project 上一级目录名称,如 power 修改为 power1,结果可以正常编译。 2.将 project 移动到 GoProject 之外的目录,结果可以正常编译。 

    请教各位大佬,为什么用 power 这个名字就不行,可能是因为什么原因造成的?

    1 条回复    2024-05-19 09:56:07 +08:00
    body007
        1
    body007  
       2024-05-19 09:56:07 +08:00
    第二个就是答案,自从有了 go mod 之后,不要把项目放到 gopath 目录下,gopath 在 go mod 之后就是个缓存目录,里面的文件也尽量不要编辑。

    我估计你的 go mod 文件 第一行有包含 .../power/project/... ,go 编译时会查找 gopath 目录下的代码也会查找 go.mod 文件开始的子目录路径,而你把项目放到 gopath 目录下,估计引起了冲突。把 power 改为 power1 后,如果你的 go.mod 文件没有同步更改,那么 go 在查找路径时不会冲突,所以第一个也能编译(这个是我推测的)
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1262 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 17:14 PVG 01:14 LAX 09:14 JFK 12:14
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86