在C中,我们可以构建二进制文件的调试版本或发行版本(目标文件和可执行文件).我们怎么能在Go中做到这一点?
我是Golang的新手,我正在尝试构建一个使用静态库(.a文件)的golang程序
我的项目的目录结构如下
??testserver
??bin
??pkg
??src
??logging
??testserver
??libtest.a
??test.go
Run Code Online (Sandbox Code Playgroud)
test.go中的cgo标志如下
// #cgo LDFLAGS: -L /home/test/testserver/src/testserver -ltest
// #include "test.h"
import "C"
Run Code Online (Sandbox Code Playgroud)
当我使用LDFLAGS -L的绝对路径时,它会产生罚款,但是当我将路径更改为相对路径时,例如
// #cgo LDFLAGS: -L ./testserver -ltest
Run Code Online (Sandbox Code Playgroud)
然后运行该命令
go install testserver
Run Code Online (Sandbox Code Playgroud)
它向我返回一个错误,并说"找不到-ltest"
我的问题是如何在LDFLAGS中使用相对路径?,以便我可以在任何路径上构建项目.谢谢!
使用template包为客户端生成动态网页时速度太慢.
测试代码如下,golang 1.4.1
http.Handle("/js/", (http.FileServer(http.Dir(webpath))))
http.Handle("/css/", (http.FileServer(http.Dir(webpath))))
http.Handle("/img/", (http.FileServer(http.Dir(webpath))))
http.HandleFunc("/test", TestHandler)
func TestHandler(w http.ResponseWriter, r *http.Request) {
Log.Info("Entering TestHandler ...")
r.ParseForm()
filename := NiConfig.webpath + "/test.html"
t, err := template.ParseFiles(filename)
if err != nil {
Log.Error("template.ParseFiles err = %v", err)
}
t.Execute(w, nil)
}
Run Code Online (Sandbox Code Playgroud)
根据日志,我发现它花了大约3秒钟t.Execute(w, nil),我不知道它为什么用这么多时间.我也试过Apache服务器进行测试test.html,它响应速度非常快.