我有一个简单Makefile
的这样的:
unexport GOPATH
help :
@echo "libedkafka"
@echo "libedkafka-clean"
opt/librdkafka:
(mkdir -p ./opt && cd ./opt && git clone https://github.com/edenhill/librdkafka.git --depth=1)
opt/librdkafka/config.cache: opt/librdkafka
(cd ./opt/librdkafka && ./configure --prefix build)
opt/librdkafka/build/lib/pkgconfig/rdkafka.pc: opt/librdkafka/config.cache
(cd ./opt/librdkafka && make && make install)
make -t opt/librdkafka/build/lib/pkgconfig/rdkafka.pc
opt/librdkafka-goget-done: opt/librdkafka/build/lib/pkgconfig/rdkafka.pc
( export PKG_CONFIG_PATH="$$PKG_CONFIG_PATH:opt/librdkafka/build/lib/pkgconfig"; \
go env; \
echo $$PKG_CONFIG_PATH; \
pkg-config --cflags -- rdkafka-static; \
echo "So it should work "; \
go get -u -tags static gopkg.in/confluentinc/confluent-kafka-go.v1/kafka && \
touch opt/librdkafka-goget-done; )
librdkafka: opt/librdkafka-goget-done
librdkafka-clean:
rm -rf ./opt/librdkafka
rm -rf ./opt/librdkafka-goget-done
pkg-config
当我运行它时,它失败并出现错误,当我在目标中打印它时找不到相关配置,它向我显示了价值!
$ make librdkafka
( export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:opt/librdkafka/build/lib/pkgconfig"; \
go env; \
echo $PKG_CONFIG_PATH; \
pkg-config --cflags -- rdkafka-static; \
echo "So it should work "; \
go get -u -tags static gopkg.in/confluentinc/confluent-kafka-go.v1/kafka && \
touch opt/librdkafka-goget-done; )
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/me/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/me/Workspace/TBNew/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s_/tygqt0_56pzg6jk2xycqr7_w0000gq/T/go-build935984301=/tmp/go-build -gno-record-gcc-switches -fno-common"
:opt/librdkafka/build/lib/pkgconfig
-I/Users/me/Workspace/TBNew/test/opt/librdkafka/build/include
So it should work
# pkg-config --cflags -- rdkafka-static
Package rdkafka-static was not found in the pkg-config search path.
Perhaps you should add the directory containing `rdkafka-static.pc'
to the PKG_CONFIG_PATH environment variable
No package 'rdkafka-static' found
pkg-config: exit status 1
make: *** [opt/librdkafka-goget-done] Error 2
所以我的问题是 go-get 在构建时是否使用了不同的环境?
我使用 mac-os (Darwin Kernel Version 18.5.0) 作为我的操作系统。