{"id":42916,"date":"2024-12-01T14:17:49","date_gmt":"2024-12-01T06:17:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42916\/"},"modified":"2024-12-01T14:17:49","modified_gmt":"2024-12-01T06:17:49","slug":"golang-alpine-docker-%e4%ba%a4%e5%8f%89%e7%bc%96%e8%af%91c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42916\/","title":{"rendered":"golang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>golang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++<\/span><\/p>\n<h1>golang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 14:09:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300agolang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6709\u4e00\u4e2agolang\u9879\u76ee\uff0c\u4f9d\u8d56c\u8fdb\u884c\u8c03\u7528\u548c\u7f16\u8bd1\u3002\u73b0\u5728\uff0c\u6211\u5728golang:alpine\u7684docker\u955c\u50cf\u4e2d\u4f7f\u7528<code>make all<\/code>\u547d\u4ee4\u8fdb\u884c\u6784\u5efa\uff0c\u53d1\u73b0\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>\/usr\/lib\/gcc\/x86_64-alpine-linux-musl\/9.3.0\/..\/..\/..\/..\/x86_64-alpine-linux-musl\/bin\/ld: \/go\/pkg\/mod\/git.ipyker.com\/combase\/[email&nbsp;protected]\/src\/py\/cgo\/3party\/protobuf\/libprotobuf.a(structurally_valid.o): relocation r_x86_64_32 against `.rodata' can not be used when making a pie object; recompile with -fpie\n<\/pre>\n<p>golang\u9879\u76ee\u4e2d\u5f15\u5165\u4e86c\uff0c\u6211\u5728ldflags\u4e2d\u8bbe\u7f6e\u4e86-fpie\u53c2\u6570\u3002<\/p>\n<pre>package l5\n\n\/*\n#cgo cflags: -i.\/include\n#cgo ldflags: -fpie -l.\/lib -wl,-bstatic -lqos_client -wl,-bdynamic -lstdc++\n#include \"qos_client_c.h\"\n#include &lt;stdlib.h&gt;\n#include &lt;stdint.h&gt;\n*\/\nimport \"c\"\n<\/pre>\n<p>makefile\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre>version = \"2.1\"\ncommit = $(shell git rev-parse --short head)\nxcfs_as = .\/bin\/xcfs_as\nxcfs_fs = .\/bin\/xcfs_fs\nxcfs_fa = .\/bin\/xcfs_handlefail\n\nall : $(xcfs_as) $(xcfs_fs) $(xcfs_fa)\n$(xcfs_as) : $(shell find .\/pkg\/ .\/cmd\/xcfs_as\/ -name \"*.go\")\n        go build -o $@ -ldflags \"-x main.version=$(version) -x main.commit=$(commit)\" .\/cmd\/xcfs_as\/\n\n$(xcfs_fs) : $(shell find .\/pkg\/ .\/cmd\/xcfs_fs\/ -name \"*.go\")\n        go build -o $@ -ldflags \"-x main.version=$(version) -x main.commit=$(commit)\" .\/cmd\/xcfs_fs\/\n\n$(xcfs_fa) : $(shell find .\/pkg\/ .\/cmd\/xcfs_handlefail\/ -name \"*.go\")\n        go vet .\/cmd\/xcfs_handlefail\/\n        go build -o $@ -ldflags \"-x main.version=$(version) -x main.commit=$(commit)\" .\/cmd\/xcfs_handlefail\/\ntest :\n\nvet :\n        go vet .\/cmd\/xcfs_as\/\n        go vet .\/cmd\/xcfs_fs\/\n        go vet .\/cmd\/xcfs_handlefail\/\n\nclean :\n        @rm -f .\/bin\/*<\/pre>\n<p>\u5e76\u4e14\u6211\u8fd8\u5728golang:alpine\u955c\u50cf\u4e0a\u6267\u884c\u4e86\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>apk add gcc g++ cmake make\nwget -q -O \/etc\/apk\/keys\/sgerrand.rsa.pub https:\/\/alpine-pkgs.sgerrand.com\/sgerrand.rsa.pub\nwget https:\/\/reg.ipyker.com\/artifactory\/package-local\/alpine-pkg-glibc\/2.29-r0\/glibc-2.29-r0.apk\nwget https:\/\/reg.ipyker.com\/artifactory\/package-local\/alpine-pkg-glibc\/2.29-r0\/glibc-bin-2.29-r0.apk\nwget https:\/\/reg.ipyker.com\/artifactory\/package-local\/alpine-pkg-glibc\/2.29-r0\/glibc-i18n-2.29-r0.apk\napk add --no-cache glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk\napk add --no-cache build-base curl automake autoconf libtool git zlib-dev\napk add --no-cache protoc libprotoc libprotobuf-lite libprotobuf\nwget http:\/\/dl-cdn.alpinelinux.org\/alpine\/v3.12\/main\/armhf\/protobuf-3.12.2-r0.apk\napk add protobuf-3.12.2-r0.apk\n<\/pre>\n<p>\u7ed3\u679c\u8fd8\u662f\u4e00\u6837\u7684\u9519\u8bef\uff0c\u672a\u89e3\u51b3\u3002\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u7f16\u8bd1\u5171\u4eab\u5e93\u88ab -no-pie \u7834\u574f\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5e94\u8be5\u662f\u4e00\u4e2a noop\u3002<\/p>\n<pre>go env -w CC=\"gcc -no-pie\"\n<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; golang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++ golang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++ \u6765\u6e90\uff1astackoverflow 2024-04-27 14:09:35 0\u6d4f\u89c8 \u6536\u85cf \u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300agolang alpine docker \u4ea4\u53c9\u7f16\u8bd1C++\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9Golang\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u6709\u4e00\u4e2agolang\u9879\u76ee\uff0c\u4f9d\u8d56c\u8fdb\u884c\u8c03\u7528\u548c\u7f16\u8bd1\u3002\u73b0\u5728\uff0c\u6211\u5728golang:alpine\u7684docker\u955c\u50cf\u4e2d\u4f7f\u7528make all\u547d\u4ee4\u8fdb\u884c\u6784\u5efa\uff0c\u53d1\u73b0\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a \/usr\/lib\/gcc\/x86_64-alpine-linux-musl\/9.3.0\/..\/..\/..\/..\/x86_64-alpine-linux-musl\/bin\/ld: \/go\/pkg\/mod\/git.ipyker.com\/combase\/[email&nbsp;protected]\/src\/py\/cgo\/3party\/protobuf\/libprotobuf.a(structurally_valid.o): relocation r_x86_64_32 against `.rodata&#8217; can not be used when making a pie object; recompile with -fpie golang\u9879\u76ee\u4e2d\u5f15\u5165\u4e86c\uff0c\u6211\u5728ldflags\u4e2d\u8bbe\u7f6e\u4e86-fpie\u53c2\u6570\u3002 package l5 \/* #cgo cflags: -i.\/include #cgo ldflags: -fpie -l.\/lib -wl,-bstatic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42916","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42916"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42916\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}