问题描述
我是golang的新手,我正尝试构建一个使用静态库(.a文件)的golang程序
我的项目的目录结构为以下
└─testserver
├─bin
├─pkg
└─src
├─logging
└─testserver
├─libtest.a
└─test.go
test.go中的cgo标志如下
// #cgo LDFLAGS: -L / home / test / testserver / src / testserver -ltest
// #includetest.h
importC
当我为LDFLAGS -L使用绝对路径时,它可以正常工作,但是当我将路径更改为相对路径时,例如
// #cgo LDFLAGS:-L ./testserver -ltest
,然后运行命令
go install testserver
它向我返回一个错误,并说找不到-lte st
CGO_LDFLAGS $ {SRCDIR} I am new to golang , and I am trying to build a golang program which uses a static lib (.a file)
the directory struct for my project as below
└─testserver
├─bin
├─pkg
└─src
├─logging
└─testserver
├─libtest.a
└─test.go
the flags for cgo in test.go as below
// #cgo LDFLAGS: -L /home/test/testserver/src/testserver -ltest
// #include "test.h"
import "C"
when I am using absolute path for LDFLAGS -L, it works fines, but when I change the path to a relative path, eg
// #cgo LDFLAGS: -L ./testserver -ltest
and then run the command
go install testserver
it returns an error to me, and says "cannot find -ltest"
my question is how can I use a relative path in LDFLAGS ? , so that I can build the project in any path. Thanks!
CGO_LDFLAGS
${SRCDIR}
这篇关于如何在golang中使用LDFLAGS的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!