例如:
linux环境: liblinux.so
windows环境:libwindows.dll
注:两种库里面内容相同。
问题:
1、在go语言判断系统,那怎么区分库
2、C语言里面做判断吗?用define
第一种方式怎么区分?
https://groups.google.com/forum/#!topic/Golang-Nuts/MwTQVXly9wo
https://github.com/draffensperger/go-interlang/blob/master/go_to_c/dynamic_c_lib/lp.go
#cgo windows LDFLAGS: -lwindows
#cgo linux LDFLAGS: -llinux
#2
更多评论
https://golang.google.cn/pkg/go/build/#hdr-Build_Constraints
http://blog.ralch.com/tutorial/golang-conditional-compilation/
#1
https://golang.google.cn/cmd/cgo/#hdr-Using_cgo_with_the_go_command
CFLAGS, CPPFLAGS, CXXFLAGS, FFLAGS and LDFLAGS may be defined with pseudo #cgo directives within these comments to tweak the behavior of the C, C++ or Fortran compiler. Values defined in multiple directives are concatenated together. The directive can include a list of build constraints limiting its effect to systems satisfying one of the constraints (see https://golang.google.cn/pkg/go/build/#hdr-Build_Constraints for details about the constraint syntax). For example:
// #cgo CFLAGS: -DPNG_DEBUG=1
// #cgo amd64 386 CFLAGS: -DX86=1
// #cgo LDFLAGS: -lpng
// #include <png.h>
import "C"
`// +build`的约束条件同样适用于`// #cgo`
#3