0

我有一个简单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) 作为我的操作系统。

4

1 回答 1

0

我发现了问题!我的意思是我修复了它:PKG_CONFIG_PATH包含我的配置文件的相对路径中的值。当我将其更改为绝对路径脚本时。

# Assuming PRJ_DIR is defined before!
export PKG_CONFIG_PATH="$$PKG_CONFIG_PATH:$${PRJ_DIR}opt/librdkafka/build/lib/pkgconfig"; 

不确定,但我认为 go-get 在使用环境中的值之前会对它们进行评估,并在检测到不适当的值的情况下,默默地删除它们!

于 2019-08-13T15:58:27.453 回答