【问题】
折腾:
【记录】在用go语言成功模拟登陆百度后把相关函数整理至自己的go语言的库函数:crifanLib.go
期间,去整理和build,然后install了自己的crifanLib:
E:\Dev_Root\go\src\code.google.com\p\crifanLib>go build E:\Dev_Root\go\src\code.google.com\p\crifanLib>go install E:\Dev_Root\go\src\code.google.com\p\crifanLib>ls crifanLib.go E:\Dev_Root\go\src\code.google.com\p\crifanLib>ls ..\..\..\..\pkg\windows_amd64\code.google.com\p\crifanLib.a cygwin warning: MS-DOS style path detected: ..\..\..\..\pkg\windows_amd64\code.google.com\p\crifanLib.a Preferred POSIX equivalent is: ../../../../pkg/windows_amd64/code.google.com/p/crifanLib.a CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames ..\..\..\..\pkg\windows_amd64\code.google.com\p\crifanLib.a E:\Dev_Root\go\src\code.google.com\p\crifanLib>
然后去另外一个go文件:
E:\Dev_Root\go\src\EmulateLoginBaidu\EmulateLoginBaidu.go
中,去调用:
//import "code.google.com/p/crifanLib/crifanLib" import "code.google.com/p/crifanLib" /*************************************************************************************************** Global Variables ***************************************************************************************************/ var gLogger log4go.Logger; /*************************************************************************************************** Functions ***************************************************************************************************/ //do init before all others func initAll(){ gLogger = crifanLib.getCurLogger() }
结果出错:
E:\Dev_Root\go\src\EmulateLoginBaidu>go run EmulateLoginBaidu.go # command-line-arguments .\EmulateLoginBaidu.go:52: cannot refer to unexported name crifanLib.getCurLogger .\EmulateLoginBaidu.go:80: cannot refer to unexported name crifanLib.getUrlRespHtml .\EmulateLoginBaidu.go:82: cannot refer to unexported name crifanLib.dbgPrintCookies .\EmulateLoginBaidu.go:82: cannot refer to unexported name crifanLib.getCurCookies .\EmulateLoginBaidu.go:119: cannot refer to unexported name crifanLib.getUrlRespHtml .\EmulateLoginBaidu.go:121: cannot refer to unexported name crifanLib.dbgPrintCookies .\EmulateLoginBaidu.go:121: cannot refer to unexported name crifanLib.getCurCookies .\EmulateLoginBaidu.go:185: cannot refer to unexported name crifanLib.getUrlRespHtml .\EmulateLoginBaidu.go:187: cannot refer to unexported name crifanLib.dbgPrintCookies .\EmulateLoginBaidu.go:187: cannot refer to unexported name crifanLib.getCurCookies .\EmulateLoginBaidu.go:187: too many errors E:\Dev_Root\go\src\EmulateLoginBaidu>
如图:
即:
cannot refer to unexported name |
【解决过程】
1.参考:
Go” Language Tutorial-5(Exported Names)
去,结果说是:
go,模块中要导出的函数,必须首字母大写。
2.所以只能去改:
crifanLib.go中的getCurLogger为GetCurLogger
以及其他那些函数,都改为大写开头。
3.然后再去build和install:
E:\Dev_Root\go\src\code.google.com\p\crifanLib>go build E:\Dev_Root\go\src\code.google.com\p\crifanLib>go install E:\Dev_Root\go\src\code.google.com\p\crifanLib>ls crifanLib.go crifanLib.go.bak
再去调用试试,结果就可以了。
【总结】
go语言中的各种强制性规矩还真多。。。。
对于这样的强制以大写字母开头的表示导出的函数的做饭,个人很不赞同。
应该加上修饰符,比较合理。
转载请注明:在路上 » 【已解决】go语言中导入另外一个库结果调用时出错:cannot refer to unexported name