{"id":384000,"date":"2021-03-11T05:06:09","date_gmt":"2021-03-10T21:06:09","guid":{"rendered":"http:\/\/4563.org\/?p=384000"},"modified":"2021-03-11T05:06:09","modified_gmt":"2021-03-10T21:06:09","slug":"xmake-v2-5-2-%e5%8f%91%e5%b8%83-%e6%94%af%e6%8c%81%e8%87%aa%e5%8a%a8%e6%8b%89%e5%8f%96%e4%ba%a4%e5%8f%89%e5%b7%a5%e5%85%b7%e9%93%be%e5%92%8c%e4%be%9d%e8%b5%96%e5%8c%85%e9%9b%86%e6%88%90","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=384000","title":{"rendered":"xmake v2.5.2 \u53d1\u5e03, \u652f\u6301\u81ea\u52a8\u62c9\u53d6\u4ea4\u53c9\u5de5\u5177\u94fe\u548c\u4f9d\u8d56\u5305\u96c6\u6210"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  xmake v2.5.2 \u53d1\u5e03, \u652f\u6301\u81ea\u52a8\u62c9\u53d6\u4ea4\u53c9\u5de5\u5177\u94fe\u548c\u4f9d\u8d56\u5305\u96c6\u6210               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : waruqi <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>xmake \u662f\u4e00\u4e2a\u57fa\u4e8e Lua \u7684\u8f7b\u91cf\u7ea7\u8de8\u5e73\u53f0\u6784\u5efa\u5de5\u5177\uff0c\u4f7f\u7528 xmake.lua \u7ef4\u62a4\u9879\u76ee\u6784\u5efa\uff0c\u76f8\u6bd4 makefile\/CMakeLists.txt \uff0c\u914d\u7f6e\u8bed\u6cd5\u66f4\u52a0\u7b80\u6d01\u76f4\u89c2\uff0c\u5bf9\u65b0\u624b\u975e\u5e38\u53cb\u597d\uff0c\u77ed\u65f6\u95f4\u5185\u5c31\u80fd\u5feb\u901f\u5165\u95e8\uff0c\u80fd\u591f\u8ba9\u7528\u6237\u628a\u66f4\u591a\u7684\u7cbe\u529b\u96c6\u4e2d\u5728\u5b9e\u9645\u7684\u9879\u76ee\u5f00\u53d1\u4e0a\u3002<\/p>\n<p>\u5728 2.5.2 \u7248\u672c\u4e2d\uff0c\u6211\u4eec\u589e\u52a0\u4e86\u4e00\u4e2a\u91cd\u91cf\u7ea7\u7684\u65b0\u7279\u6027\uff1a<code>\u81ea\u52a8\u62c9\u53d6\u8fdc\u7a0b\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe<\/code>\u3002<\/p>\n<p>\u8fd9\u662f\u7528\u6765\u5e72\u4ec0\u4e48\u7684\u5462\uff0c\u505a\u8fc7\u4ea4\u53c9\u7f16\u8bd1\u4ee5\u53ca\u6709 C\/C++ \u9879\u76ee\u79fb\u690d\u7ecf\u9a8c\u7684\u540c\u5b66\u5e94\u8be5\u77e5\u9053\uff0c\u6298\u817e\u5404\u79cd\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\uff0c\u79fb\u690d\u7f16\u8bd1\u9879\u76ee\u662f\u975e\u5e38\u9ebb\u70e6\u7684\u4e00\u4ef6\u4e8b\uff0c\u9700\u8981\u81ea\u5df1\u4e0b\u8f7d\u5bf9\u5e94\u5de5\u5177\u94fe\uff0c\u5e76\u4e14\u914d\u7f6e\u5de5\u5177\u94fe\u548c\u7f16\u8bd1\u73af\u5883\u5f88\u5bb9\u6613\u51fa\u9519\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\u3002<\/p>\n<p>\u73b0\u5728\uff0cxmake \u5df2\u7ecf\u53ef\u4ee5\u652f\u6301\u81ea\u52a8\u4e0b\u8f7d\u9879\u76ee\u6240\u9700\u7684\u5de5\u5177\u94fe\uff0c\u7136\u540e\u4f7f\u7528\u5bf9\u5e94\u5de5\u5177\u94fe\u76f4\u63a5\u7f16\u8bd1\u9879\u76ee\uff0c\u7528\u6237\u4e0d\u9700\u8981\u5173\u5fc3\u5982\u4f55\u914d\u7f6e\u5de5\u5177\u94fe\uff0c\u4efb\u4f55\u60c5\u51b5\u4e0b\u53ea\u9700\u8981\u6267\u884c <code>xmake<\/code> \u547d\u4ee4\u5373\u53ef\u5b8c\u6210\u7f16\u8bd1\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/03\/20210311_604a4e03795c6.gif\" alt=\"xmake v2.5.2 \u53d1\u5e03, \u652f\u6301\u81ea\u52a8\u62c9\u53d6\u4ea4\u53c9\u5de5\u5177\u94fe\u548c\u4f9d\u8d56\u5305\u96c6\u6210\" \/><\/p>\n<p>\u751a\u81f3\u5bf9\u4e8e C\/C++ \u4f9d\u8d56\u5305\u7684\u96c6\u6210\uff0c\u4e5f\u53ef\u4ee5\u81ea\u52a8\u5207\u6362\u5230\u5bf9\u5e94\u5de5\u5177\u94fe\u7f16\u8bd1\u5b89\u88c5\u96c6\u6210\uff0c\u4e00\u5207\u5b8c\u5168\u81ea\u52a8\u5316\uff0c\u5b8c\u5168\u4e0d\u9700\u8981\u7528\u6237\u64cd\u5fc3\u3002<\/p>\n<p>\u9664\u4e86\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u81ea\u52a8\u62c9\u53d6\u5de5\u5177\u94fe\uff0c\u6bd4\u5982\u7279\u5b9a\u7248\u672c\u7684 llvm\uff0cllvm-mingw, zig \u7b49\u5404\u79cd\u5de5\u5177\u94fe\u6765\u53c2\u4e0e\u7f16\u8bd1 C\/C++\/Zig \u9879\u76ee\u7684\u7f16\u8bd1\u3002<\/p>\n<p>\u5373\u4f7f\u662f cmake \u4e5f\u8fd8\u4e0d\u652f\u6301\u5de5\u5177\u94fe\u7684\u81ea\u52a8\u62c9\u53d6\uff0c\u9876\u591a\u53ea\u80fd\u914d\u5408 vcpkg\/conan \u7b49\u7b2c\u4e09\u65b9\u5305\u7ba1\u7406\u5bf9 C\/C++ \u4f9d\u8d56\u5305\u8fdb\u884c\u96c6\u6210\uff0c\u53e6\u5916\uff0c\u5373\u4f7f\u5bf9\u4e8e C\/C++\u4f9d\u8d56\u5305\uff0cxmake \u4e5f\u6709\u81ea\u5df1\u539f\u751f\u5185\u7f6e\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5b8c\u5168\u65e0\u4efb\u4f55\u4f9d\u8d56\u3002<\/p>\n<ul>\n<li>\u9879\u76ee\u6e90\u7801<\/li>\n<li>\u5b98\u65b9\u6587\u6863<\/li>\n<li>\u5165\u95e8\u8bfe\u7a0b<\/li>\n<\/ul>\n<h2>\u65b0\u7279\u6027\u4ecb\u7ecd<\/h2>\n<h3>\u81ea\u52a8\u62c9\u53d6\u8fdc\u7a0b\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe<\/h3>\n<p>\u4ece 2.5.2 \u7248\u672c\u5f00\u59cb\uff0c\u6211\u4eec\u53ef\u4ee5\u62c9\u53d6\u6307\u5b9a\u7684\u5de5\u5177\u94fe\u6765\u96c6\u6210\u7f16\u8bd1\u9879\u76ee\uff0c\u6211\u4eec\u4e5f\u652f\u6301\u5c06\u4f9d\u8d56\u5305\u5207\u6362\u5230\u5bf9\u5e94\u7684\u8fdc\u7a0b\u5de5\u5177\u94fe\u53c2\u4e0e\u7f16\u8bd1\u540e\u96c6\u6210\u8fdb\u6765\u3002<\/p>\n<p>\u76f8\u5173\u4f8b\u5b50\u4ee3\u7801\u89c1\uff1aToolchain\/Packages Examples<\/p>\n<p>\u76f8\u5173\u7684 issue #1217<\/p>\n<p>\u5f53\u524d\uff0c\u6211\u4eec\u5df2\u7ecf\u5728 xmake-repo \u4ed3\u5e93\u6536\u5f55\u4e86\u4ee5\u4e0b\u5de5\u5177\u94fe\u5305\uff0c\u53ef\u4ee5\u8ba9 xmake \u8fdc\u7a0b\u62c9\u53d6\u96c6\u6210\uff1a<\/p>\n<ul>\n<li>llvm<\/li>\n<li>llvm-mingw<\/li>\n<li>gnu-rm<\/li>\n<li>muslcc<\/li>\n<li>zig<\/li>\n<\/ul>\n<p>\u867d\u7136\u73b0\u5728\u652f\u6301\u7684\u5de5\u5177\u94fe\u5305\u4e0d\u591a\uff0c\u5f53\u4f46\u662f\u6574\u4f53\u67b6\u6784\u5df2\u7ecf\u6253\u901a\uff0c\u540e\u671f\u6211\u4eec\u53ea\u9700\u8981\u6536\u5f55\u66f4\u591a\u7684\u5de5\u5177\u94fe\u8fdb\u6765\u5c31\u884c\uff0c\u6bd4\u5982\uff1agcc, tinyc, vs-buildtools \u7b49\u5de5\u5177\u94fe\u3002<\/p>\n<p>\u7531\u4e8e xmake \u7684\u5305\u652f\u6301\u8bed\u4e49\u7248\u672c\uff0c\u56e0\u6b64\u5982\u679c\u9879\u76ee\u4f9d\u8d56\u7279\u5b9a\u7248\u672c\u7684 gcc\/clang \u7f16\u8bd1\u5668\uff0c\u5c31\u4e0d\u8981\u7528\u6237\u53bb\u6298\u817e\u5b89\u88c5\u4e86\uff0cxmake \u4f1a\u81ea\u52a8\u68c0\u6d4b\u5f53\u524d\u7cfb\u7edf\u7684 gcc\/clang \u7248\u672c\u662f\u5426\u6ee1\u8db3\u9700\u6c42\u3002<\/p>\n<p>\u5982\u679c\u7248\u672c\u4e0d\u6ee1\u8db3\uff0c\u90a3\u4e48 xmake \u5c31\u4f1a\u8d70\u8fdc\u7a0b\u62c9\u53d6\uff0c\u81ea\u52a8\u5e2e\u7528\u6237\u5b89\u88c5\u96c6\u6210\u7279\u5b9a\u7248\u672c\u7684 gcc\/clang\uff0c\u7136\u540e\u518d\u53bb\u7f16\u8bd1\u9879\u76ee\u3002<\/p>\n<h4>\u62c9\u53d6\u6307\u5b9a\u7248\u672c\u7684 llvm \u5de5\u5177\u94fe<\/h4>\n<p>\u6211\u4eec\u4f7f\u7528 llvm-10 \u4e2d\u7684 clang \u6765\u7f16\u8bd1\u9879\u76ee\u3002<\/p>\n<pre><code>add_requires(\"llvm 10.x\", {alias = \"llvm-10\"}) target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.c)     set_toolchains(\"[email&#160;protected]\") <\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>[email&#160;protected]<\/code> \u7684\u524d\u534a\u90e8\u5206\u4e3a\u5de5\u5177\u94fe\u540d\uff0c\u4e5f\u5c31\u662f <code>toolchain(\"llvm\")<\/code>\uff0c\u540e\u9762\u7684\u540d\u5b57\u662f\u9700\u8981\u88ab\u5173\u8054\u5de5\u5177\u94fe\u5305\u540d\uff0c\u4e5f\u5c31\u662f <code>package(\"llvm\")<\/code>\uff0c\u4e0d\u8fc7\u5982\u679c\u8bbe\u7f6e\u4e86\u522b\u540d\uff0c\u90a3\u4e48\u4f1a\u4f18\u5148\u4f7f\u7528\u522b\u540d\uff1a<code>llvm-10<\/code><\/p>\n<p>\u53e6\u5916\uff0c\u6211\u4eec\u540e\u7eed\u8fd8\u4f1a\u589e\u52a0 gcc \u5de5\u5177\u94fe\u5305\u5230 xmake-repo\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u81ea\u7531\u5207\u6362 gcc-10, gcc-11 \u7b49\u7279\u5b9a\u7248\u672c\u7684 gcc \u7f16\u8bd1\u5668\uff0c\u800c\u65e0\u9700\u7528\u6237\u53bb\u624b\u52a8\u5b89\u88c5\u3002<\/p>\n<h3>\u62c9\u53d6\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe<\/h3>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u62c9\u53d6\u6307\u5b9a\u7684\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u6765\u7f16\u8bd1\u9879\u76ee\u3002<\/p>\n<pre><code>add_requires(\"muslcc\") target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.c)     set_toolchains(\"@muslcc\") <\/code><\/pre>\n<p>muslcc \u662f https:\/\/musl.cc \u63d0\u4f9b\u7684\u4e00\u6b3e\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\uff0c\u9ed8\u8ba4 xmake \u4f1a\u81ea\u52a8\u96c6\u6210\u7f16\u8bd1 <code>x86_64-linux-musl-<\/code> \u76ee\u6807\u5e73\u53f0\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>xmake f -a arm64<\/code> \u5207\u6362\u5230 <code>aarch64-linux-musl-<\/code> \u76ee\u6807\u5e73\u53f0\u6765\u8fdb\u884c\u4ea4\u53c9\u7f16\u8bd1\u3002<\/p>\n<h4>\u62c9\u53d6\u5de5\u5177\u94fe\u5e76\u4e14\u96c6\u6210\u5bf9\u5e94\u5de5\u5177\u94fe\u7f16\u8bd1\u7684\u4f9d\u8d56\u5305<\/h4>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6307\u5b9a\u7684 muslcc \u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\u94fe\u53bb\u7f16\u8bd1\u548c\u96c6\u6210\u6240\u6709\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<pre><code>add_requires(\"muslcc\") add_requires(\"zlib\", \"libogg\", {system = false})  set_toolchains(\"@muslcc\")  target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.c\")     add_packages(\"zlib\", \"libogg\") <\/code><\/pre>\n<p>\u8fd9\u4e2a\u65f6\u5019\uff0c\u5de5\u7a0b\u91cc\u9762\u914d\u7f6e\u7684 zlib, libogg \u7b49\u4f9d\u8d56\u5305\uff0c\u4e5f\u4f1a\u5207\u6362\u4f7f\u7528 muslcc \u5de5\u5177\u94fe\uff0c\u81ea\u52a8\u4e0b\u8f7d\u7f16\u8bd1\u7136\u540e\u96c6\u6210\u8fdb\u6765\u3002<\/p>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>set_plat\/set_arch<\/code> \u56fa\u5b9a\u5e73\u53f0\uff0c\u8fd9\u6837\u53ea\u9700\u8981\u4e00\u4e2a xmake \u547d\u4ee4\uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210\u6574\u4e2a\u4ea4\u53c9\u7f16\u8bd1\u73af\u5883\u7684\u96c6\u6210\u4ee5\u53ca\u67b6\u6784\u5207\u6362\u3002<\/p>\n<pre><code>add_requires(\"muslcc\") add_requires(\"zlib\", \"libogg\", {system = false})  set_plat(\"cross\") set_arch(\"arm64\") set_toolchains(\"@muslcc\")  target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.c\")     add_packages(\"zlib\", \"libogg\") <\/code><\/pre>\n<p>\u5b8c\u6574\u4f8b\u5b50\u89c1\uff1aExamples (muslcc)<\/p>\n<h4>\u62c9\u53d6\u96c6\u6210 Zig \u5de5\u5177\u94fe<\/h4>\n<p>xmake \u4f1a\u5148\u4e0b\u8f7d\u7279\u5b9a\u7248\u672c\u7684 zig \u5de5\u5177\u94fe\uff0c\u7136\u540e\u4f7f\u7528\u6b64\u5de5\u5177\u94fe\u7f16\u8bd1 zig \u9879\u76ee\uff0c\u5f53\u7136\u7528\u6237\u5982\u679c\u5df2\u7ecf\u81ea\u884c\u5b89\u88c5\u4e86 zig \u5de5\u5177\u94fe\uff0cxmake \u4e5f\u4f1a\u81ea\u52a8\u68c0\u6d4b\u5bf9\u5e94\u7248\u672c\u662f\u5426\u6ee1\u8db3\uff0c\u5982\u679c\u6ee1\u8db3\u9700\u6c42\uff0c\u90a3\u4e48\u4f1a\u76f4\u63a5\u4f7f\u7528\u5b83\uff0c\u65e0\u9700\u91cd\u590d\u4e0b\u8f7d\u5b89\u88c5\u3002<\/p>\n<pre><code>add_rules(\"mode.debug\", \"mode.release\") add_requires(\"zig 0.7.x\")  target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.zig\")     set_toolchains(\"@zig\") <\/code><\/pre>\n<h3>\u589e\u52a0\u5bf9 zig cc \u7f16\u8bd1\u5668\u652f\u6301<\/h3>\n<p><code>zig cc<\/code> \u662f zig \u5185\u7f6e\u7684 c\/c++ \u7f16\u8bd1\u5668\uff0c\u53ef\u4ee5\u5b8c\u5168\u72ec\u7acb\u8fdb\u884c c\/c++ \u4ee3\u7801\u7684\u7f16\u8bd1\u548c\u94fe\u63a5\uff0c\u5b8c\u5168\u4e0d\u4f9d\u8d56 gcc\/clang\/msvc\uff0c\u975e\u5e38\u7ed9\u529b\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u7f16\u8bd1 c\/c++ \u9879\u76ee\uff0c\u5173\u952e\u662f zig \u7684\u5de5\u5177\u94fe\u8fd8\u975e\u5e38\u8f7b\u91cf\uff0c\u4ec5\u4ec5\u51e0\u5341 M \u3002<\/p>\n<p>\u6211\u4eec\u53ea\u9700\u8981\u5207\u6362\u5230 zig \u5de5\u5177\u94fe\u5373\u53ef\u5b8c\u6210\u7f16\u8bd1\uff1a<\/p>\n<pre><code>$ xmake f --toolchain=zig $ xmake [ 25%]: compiling.release src\/main.c \"zig cc\" -c -arch x86_64 -fvisibility=hidden -O3 -DNDEBUG -o build\/.objs\/xmake_test\/macosx\/x86_64\/release\/src\/main.c.o src\/main.c [ 50%]: linking.release test \"zig c++\" -o build\/macosx\/x86_64\/release\/test build\/.objs\/xmake_test\/macosx\/x86_64\/release\/src\/main.c.o -arch x86_64 -stdlib=libc++ -Wl,-x -lz [100%]: build ok! <\/code><\/pre>\n<p>\u53e6\u5916\uff0c<code>zig cc<\/code> \u7684\u53e6\u5916\u4e00\u4e2a\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\uff0c\u5b83\u8fd8\u652f\u6301\u4e0d\u540c\u67b6\u6784\u7684\u4ea4\u53c9\u7f16\u8bd1\uff0c\u592a happy \u4e86\u3002<\/p>\n<p>\u901a\u8fc7 xmake\uff0c\u6211\u4eec\u4e5f\u53ea\u9700\u518d\u989d\u5916\u5207\u6362\u4e0b\u67b6\u6784\u5230 arm64\uff0c\u5373\u53ef\u5b9e\u73b0\u5bf9 arm64 \u7684\u4ea4\u53c9\u7f16\u8bd1\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>$ xmake f -a arm64 --toolchain=zig $ xmake [ 25%]: compiling.release src\/main.c \"zig cc\" -c -target aarch64-macos-gnu -arch arm64 -fvisibility=hidden -O3 -DNDEBUG -o build\/.objs\/xmake_test\/macosx\/arm64\/release\/src\/main.c.o src\/main.c checking for flags (-MMD -MF) ... ok checking for flags (-fdiagnostics-color=always) ... ok [ 50%]: linking.release xmake_test \"zig c++\" -o build\/macosx\/arm64\/release\/xmake_test build\/.objs\/xmake_test\/macosx\/arm64\/release\/src\/main.c.o -target aarch64-macos-gnu -arch arm64 -stdlib=libc++ -Wl,-x -lz [100%]: build ok! <\/code><\/pre>\n<p>\u5373\u4f7f\u4f60\u662f\u5728\u5728 macOS\uff0c\u4e5f\u53ef\u4ee5\u7528 <code>zig cc<\/code> \u53bb\u4ea4\u53c9\u7f16\u8bd1 windows\/x64 \u76ee\u6807\u7a0b\u5e8f\uff0c\u76f8\u5f53\u4e8e\u66ff\u4ee3\u4e86 mingw \u5e72\u7684\u4e8b\u60c5\u3002<\/p>\n<pre><code>$ xmake f -p windows -a x64 --toolchain=zig $ xmake <\/code><\/pre>\n<h3>\u81ea\u52a8\u5bfc\u51fa\u6240\u6709 windows\/dll \u4e2d\u7684\u7b26\u53f7<\/h3>\n<p>cmake \u4e2d\u6709\u8fd9\u6837\u4e00\u4e2a\u529f\u80fd\uff1a<code>WINDOWS_EXPORT_ALL_SYMBOLS<\/code>\uff0c\u5b89\u88c5 cmake \u6587\u6863\u4e2d\u7684\u8bf4\u6cd5\uff1a<\/p>\n<p>https:\/\/cmake.org\/cmake\/help\/latest\/prop_tgt\/WINDOWS_EXPORT_ALL_SYMBOLS.html<\/p>\n<blockquote>\n<p>Enable this boolean property to automatically create a module definition (.def) file with all global symbols found in the input .obj files for a SHARED library (or executable with ENABLE_EXPORTS) on Windows. The module definition file will be passed to the linker causing all symbols to be exported from the .dll. For global data symbols, __declspec(dllimport) must still be used when compiling against the code in the .dll. All other function symbols will be automatically exported and imported by callers. This simplifies porting projects to Windows by reducing the need for explicit dllexport markup, even in C++ classes.<\/p>\n<\/blockquote>\n<p>\u5927\u4f53\u610f\u601d\u5c31\u662f\uff1a<\/p>\n<blockquote>\n<p>\u542f\u7528\u6b64\u5e03\u5c14\u5c5e\u6027\uff0c\u53ef\u4ee5\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u6a21\u5757\u5b9a\u4e49(.def)\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u5728 Windows \u4e0a\u7684\u5171\u4eab\u5e93(\u6216\u4f7f\u7528 ENABLE_EXPORTS \u7684\u53ef\u6267\u884c\u6587\u4ef6)\u7684\u8f93\u5165.obj \u6587\u4ef6\u4e2d\u627e\u5230\u7684\u6240\u6709\u5168\u5c40\u7b26\u53f7\u3002 \u6a21\u5757\u5b9a\u4e49\u6587\u4ef6\u5c06\u88ab\u4f20\u9012\u7ed9\u94fe\u63a5\u5668\uff0c\u4f7f\u6240\u6709\u7b26\u53f7\u4ece.dll \u4e2d\u5bfc\u51fa\u3002\u5bf9\u4e8e\u5168\u5c40\u6570\u636e\u7b26\u53f7\uff0c\u5f53\u5bf9.dll \u4e2d\u7684\u4ee3\u7801\u8fdb\u884c\u7f16\u8bd1\u65f6\uff0c\u4ecd\u7136\u5fc5\u987b\u4f7f\u7528__declspec(dllimport)\u3002 \u6240\u6709\u5176\u5b83\u7684\u51fd\u6570\u7b26\u53f7\u5c06\u88ab\u8c03\u7528\u8005\u81ea\u52a8\u5bfc\u51fa\u548c\u5bfc\u5165\u3002\u8fd9\u5c31\u7b80\u5316\u4e86\u5c06\u9879\u76ee\u79fb\u690d\u5230 Windows \u7684\u8fc7\u7a0b\uff0c\u51cf\u5c11\u4e86\u5bf9\u663e\u5f0f dllexport \u6807\u8bb0\u7684\u9700\u6c42\uff0c\u751a\u81f3\u5728 C++ \u7c7b\u4e2d\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n<\/blockquote>\n<p>\u73b0\u5728\uff0cxmake \u4e2d\u4e5f\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u5feb\u901f\u5168\u91cf\u5bfc\u51fa windows\/dll \u4e2d\u7684\u7b26\u53f7\uff0c\u6765\u7b80\u5316\u5bf9\u7b2c\u4e09\u65b9\u9879\u76ee\u79fb\u690d\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u7b26\u53f7\u5bfc\u51fa\u7684\u5904\u7406\u3002\u53e6\u5916\uff0c\u5982\u679c\u9879\u76ee\u4e2d\u7684\u7b26\u53f7\u592a\u591a\uff0c\u4e5f\u53ef\u4ee5\u7528\u6b64\u6765\u7b80\u5316\u4ee3\u7801\u4e2d\u7684\u663e\u5f0f\u5bfc\u51fa\u9700\u6c42\u3002<\/p>\n<p>\u6211\u4eec\u53ea\u9700\u5728\u5bf9\u5e94\u751f\u6210\u7684 dll \u76ee\u6807\u4e0a\uff0c\u914d\u7f6e <code>utils.symbols.export_all<\/code> \u89c4\u5219\u5373\u53ef\u3002<\/p>\n<pre><code>target(\"foo\")     set_kind(\"shared\")     add_files(\"src\/foo.c\")     add_rules(\"utils.symbols.export_all\")  target(\"test\")     set_kind(\"binary\")     add_deps(\"foo\")     add_files(\"src\/main.c\") <\/code><\/pre>\n<p>xmake \u4f1a\u81ea\u52a8\u626b\u63cf\u6240\u6709\u7684 obj \u5bf9\u8c61\u6587\u4ef6\uff0c\u7136\u540e\u751f\u6210 def \u7b26\u53f7\u5bfc\u51fa\u6587\u4ef6\uff0c\u4f20\u5165 link.exe \u5b9e\u73b0\u5feb\u901f\u5168\u91cf\u5bfc\u51fa\u3002<\/p>\n<h3>\u8f6c\u6362 mingw\/.dll.a \u5230 msvc\/.lib<\/h3>\n<p>\u8fd9\u4e2a\u7279\u6027\u4e5f\u662f\u53c2\u8003\u81ea CMAKE_GNUtoMS \u529f\u80fd\uff0c\u53ef\u4ee5\u628a MinGW \u751f\u6210\u7684\u52a8\u6001\u5e93\uff08 xxx.dll &amp; xxx.dll.a \uff09\u8f6c\u6362\u6210 Visual Studio \u53ef\u4ee5\u8bc6\u522b\u7684\u683c\u5f0f\uff08 xxx.dll &amp; xxx.lib \uff09\uff0c\u4ece\u800c\u5b9e\u73b0\u6df7\u5408\u7f16\u8bd1\u3002<\/p>\n<p>\u8fd9\u4e2a\u529f\u80fd\u5bf9 Fortran &amp; C++\u6df7\u5408\u9879\u76ee\u7279\u522b\u6709\u5e2e\u52a9\uff0c\u56e0\u4e3a VS \u4e0d\u63d0\u4f9b fortran \u7f16\u8bd1\u5668\uff0c\u53ea\u80fd\u7528 MinGW \u7684 gfortran \u6765\u7f16\u8bd1 fortran \u90e8\u5206\uff0c\u7136\u540e\u548c VS \u7684\u9879\u76ee\u94fe\u63a5\u3002 \u5f80\u5f80\u8fd9\u6837\u7684\u9879\u76ee\u540c\u65f6\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u5e93\u4ee5 vs \u683c\u5f0f\u63d0\u4f9b\uff0c\u56e0\u6b64\u7eaf\u7528 MinGW \u7f16\u8bd1\u4e5f\u4e0d\u884c\uff0c\u53ea\u80fd\u4f7f\u7528 cmake \u7684\u8fd9\u4e2a\u529f\u80fd\u6765\u6df7\u5408\u7f16\u8bd1\u3002<\/p>\n<p>\u56e0\u6b64\uff0cxmake \u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8f85\u52a9\u6a21\u5757\u63a5\u53e3\u53bb\u652f\u6301\u5b83\uff0c\u4f7f\u7528\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code>import(\"utils.platform.gnu2mslib\")  gnu2mslib(\"xxx.lib\", \"xxx.dll.a\") gnu2mslib(\"xxx.lib\", \"xxx.def\") gnu2mslib(\"xxx.lib\", \"xxx.dll.a\", {dllname = \"xxx.dll\", arch = \"x64\"}) <\/code><\/pre>\n<p>\u652f\u6301\u4ece def \u751f\u6210 xxx.lib \uff0c\u4e5f\u652f\u6301\u4ece xxx.dll.a \u81ea\u52a8\u5bfc\u51fa .def \uff0c\u7136\u540e\u518d\u751f\u6210 xxx.lib<\/p>\n<p>\u5177\u4f53\u7ec6\u8282\u89c1\uff1aissue #1181<\/p>\n<h3>\u5b9e\u73b0\u6279\u5904\u7406\u547d\u4ee4\u6765\u7b80\u5316\u81ea\u5b9a\u4e49\u89c4\u5219<\/h3>\n<p>\u4e3a\u4e86\u7b80\u5316\u7528\u6237\u81ea\u5b9a\u4e49 rule \u7684\u914d\u7f6e\uff0cxmake \u65b0\u63d0\u4f9b\u4e86 <code>on_buildcmd_file<\/code>, <code>on_buildcmd_files<\/code> \u7b49\u81ea\u5b9a\u4e49\u811a\u672c\u5165\u53e3\uff0c \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 batchcmds \u5bf9\u8c61\uff0c\u6784\u9020\u4e00\u4e2a\u6279\u5904\u7406\u547d\u4ee4\u884c\u4efb\u52a1\uff0cxmake \u5728\u5b9e\u9645\u6267\u884c\u6784\u5efa\u7684\u65f6\u5019\uff0c\u4e00\u6b21\u6027\u6267\u884c\u8fd9\u4e9b\u547d\u4ee4\u3002<\/p>\n<p>\u8fd9\u5bf9\u4e8e <code>xmake project<\/code> \u6b64\u7c7b\u5de5\u7a0b\u751f\u6210\u5668\u63d2\u4ef6\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3a\u751f\u6210\u5668\u751f\u6210\u7684\u7b2c\u4e09\u65b9\u5de5\u7a0b\u6587\u4ef6\u5e76\u4e0d\u652f\u6301 <code>on_build_files<\/code> \u6b64\u7c7b\u5185\u7f6e\u811a\u672c\u7684\u6267\u884c\u652f\u6301\u3002<\/p>\n<p>\u4f46\u662f <code>on_buildcmd_file<\/code> \u6784\u9020\u7684\u6700\u7ec8\u7ed3\u679c\uff0c\u5c31\u662f\u4e00\u6279\u539f\u59cb\u7684 cmd \u547d\u4ee4\u884c\uff0c\u53ef\u4ee5\u76f4\u63a5\u7ed9\u5176\u4ed6\u5de5\u7a0b\u6587\u4ef6\u4f5c\u4e3a custom commands \u6765\u6267\u884c\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u76f8\u6bd4 <code>on_build_file<\/code>\uff0c\u5b83\u4e5f\u7b80\u5316\u5bf9\u6269\u5c55\u6587\u4ef6\u7684\u7f16\u8bd1\u5b9e\u73b0\uff0c\u66f4\u52a0\u7684\u53ef\u8bfb\u6613\u914d\u7f6e\uff0c\u5bf9\u7528\u6237\u4e5f\u66f4\u52a0\u53cb\u597d\u3002<\/p>\n<pre><code>rule(\"foo\")     set_extensions(\".xxx\")     on_buildcmd_file(function (target, batchcmds, sourcefile, opt)         batchcmds:vrunv(\"gcc\", {\"-o\", objectfile, \"-c\", sourcefile})     end) <\/code><\/pre>\n<p>\u9664\u4e86 <code>batchcmds:vrunv<\/code>\uff0c\u6211\u4eec\u8fd8\u652f\u6301\u4e00\u4e9b\u5176\u4ed6\u7684\u6279\u5904\u7406\u547d\u4ee4\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>batchcmds:show(\"hello %s\", \"xmake\") batchcmds:vrunv(\"gcc\", {\"-o\", objectfile, \"-c\", sourcefile}, {envs = {LD_LIBRARY_PATH=\"\/xxx\"}}) batchcmds:mkdir(\"\/xxx\") -- and cp, mv, rm, ln .. batchcmds:compile(sourcefile_cx, objectfile, {configs = {includedirs = sourcefile_dir, languages = (sourcekind == \"cxx\" and \"c++11\")}}) batchcmds:link(objectfiles, targetfile, {configs = {linkdirs = \"\"}}) <\/code><\/pre>\n<p>\u540c\u65f6\uff0c\u6211\u4eec\u5728\u91cc\u9762\u4e5f\u7b80\u5316\u5bf9\u4f9d\u8d56\u6267\u884c\u7684\u914d\u7f6e\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u5b8c\u6574\u4f8b\u5b50\uff1a<\/p>\n<pre><code>rule(\"lex\")     set_extensions(\".l\", \".ll\")     on_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt)          -- imports         import(\"lib.detect.find_tool\")          -- get lex         local lex = assert(find_tool(\"flex\") or find_tool(\"lex\"), \"lex not found!\")          -- get c\/c++ source file for lex         local extension = path.extension(sourcefile_lex)         local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"lex_yacc\", path.basename(sourcefile_lex) .. (extension == \".ll\" and \".cpp\" or \".c\"))          -- add objectfile         local objectfile = target:objectfile(sourcefile_cx)         table.insert(target:objectfiles(), objectfile)          -- add commands         batchcmds:show_progress(opt.progress, \"${color.build.object}compiling.lex %s\", sourcefile_lex)         batchcmds:mkdir(path.directory(sourcefile_cx))         batchcmds:vrunv(lex.program, {\"-o\", sourcefile_cx, sourcefile_lex})         batchcmds:compile(sourcefile_cx, objectfile)          -- add deps         batchcmds:add_depfiles(sourcefile_lex)         batchcmds:set_depmtime(os.mtime(objectfile))         batchcmds:set_depcache(target:dependfile(objectfile))     end) <\/code><\/pre>\n<p>\u6211\u4eec\u4ece\u4e0a\u9762\u7684\u914d\u7f6e\u53ef\u4ee5\u770b\u5230\uff0c\u6574\u4f53\u6267\u884c\u547d\u4ee4\u5217\u8868\u975e\u5e38\u6e05\u6670\uff0c\u800c\u5982\u679c\u6211\u4eec\u7528 <code>on_build_file<\/code> \u6765\u5b9e\u73b0\uff0c\u53ef\u4ee5\u5bf9\u6bd4\u4e0b\u4e4b\u524d\u8fd9\u4e2a\u89c4\u5219\u7684\u914d\u7f6e\uff0c\u5c31\u80fd\u76f4\u89c2\u611f\u53d7\u5230\u65b0\u63a5\u53e3\u7684\u914d\u7f6e\u65b9\u5f0f\u786e\u5b9e\u7b80\u5316\u4e86\u4e0d\u5c11\uff1a<\/p>\n<pre><code>rule(\"lex\")      -- set extension     set_extensions(\".l\", \".ll\")      -- load lex\/flex     before_load(function (target)         import(\"core.project.config\")         import(\"lib.detect.find_tool\")         local lex = config.get(\"__lex\")         if not lex then             lex = find_tool(\"flex\") or find_tool(\"lex\")             if lex and lex.program then                 config.set(\"__lex\", lex.program)                 cprint(\"checking for Lex ... ${color.success}%s\", lex.program)             else                 cprint(\"checking for Lex ... ${color.nothing}${text.nothing}\")                 raise(\"lex\/flex not found!\")             end         end     end)      -- build lex file     on_build_file(function (target, sourcefile_lex, opt)          -- imports         import(\"core.base.option\")         import(\"core.theme.theme\")         import(\"core.project.config\")         import(\"core.project.depend\")         import(\"core.tool.compiler\")         import(\"private.utils.progress\")          -- get lex         local lex = assert(config.get(\"__lex\"), \"lex not found!\")          -- get extension: .l\/.ll         local extension = path.extension(sourcefile_lex)          -- get c\/c++ source file for lex         local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"lex_yacc\", path.basename(sourcefile_lex) .. (extension == \".ll\" and \".cpp\" or \".c\"))         local sourcefile_dir = path.directory(sourcefile_cx)          -- get object file         local objectfile = target:objectfile(sourcefile_cx)          -- load compiler         local compinst = compiler.load((extension == \".ll\" and \"cxx\" or \"cc\"), {target = target})          -- get compile flags         local compflags = compinst:compflags({target = target, sourcefile = sourcefile_cx})          -- add objectfile         table.insert(target:objectfiles(), objectfile)          -- load dependent info         local dependfile = target:dependfile(objectfile)         local dependinfo = option.get(\"rebuild\") and {} or (depend.load(dependfile) or {})          -- need build this object?         local depvalues = {compinst:program(), compflags}         if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then             return         end          -- trace progress info         progress.show(opt.progress, \"${color.build.object}compiling.lex %s\", sourcefile_lex)          -- ensure the source file directory         if not os.isdir(sourcefile_dir) then             os.mkdir(sourcefile_dir)         end          -- compile lex         os.vrunv(lex, {\"-o\", sourcefile_cx, sourcefile_lex})          -- trace         if option.get(\"verbose\") then             print(compinst:compcmd(sourcefile_cx, objectfile, {compflags = compflags}))         end          -- compile c\/c++ source file for lex         dependinfo.files = {}         assert(compinst:compile(sourcefile_cx, objectfile, {dependinfo = dependinfo, compflags = compflags}))          -- update files and values to the dependent file         dependinfo.values = depvalues         table.insert(dependinfo.files, sourcefile_lex)         depend.save(dependinfo, dependfile)     end) <\/code><\/pre>\n<p>\u5173\u4e8e\u8fd9\u4e2a\u7684\u8be6\u7ec6\u8bf4\u660e\u548c\u80cc\u666f\uff0c\u89c1\uff1aissue 1246<\/p>\n<h3>\u4f9d\u8d56\u5305\u914d\u7f6e\u6539\u8fdb<\/h3>\n<h4>\u4f7f\u7528 add_extsources \u6539\u8fdb\u5305\u540d\u67e5\u627e<\/h4>\n<p>\u5173\u4e8e\u8fdc\u7a0b\u4f9d\u8d56\u5305\u5b9a\u4e49\u8fd9\u5757\uff0c\u6211\u4eec\u4e5f\u65b0\u589e\u4e86 <code>add_extsources<\/code> \u548c <code>on_fetch<\/code> \u4e24\u4e2a\u914d\u7f6e\u63a5\u53e3\uff0c\u53ef\u4ee5\u66f4\u597d\u7684\u914d\u7f6e xmake \u5728\u5b89\u88c5 C\/C++ \u5305\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u7cfb\u7edf\u5e93\u7684\u67e5\u627e\u8fc7\u7a0b\u3002<\/p>\n<p>\u81f3\u4e8e\u5177\u4f53\u80cc\u666f\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6bd4\u5982\u6211\u4eec\u5728 xmake-repo \u4ed3\u5e93\u65b0\u589e\u4e86\u4e00\u4e2a <code>package(\"libusb\")<\/code> \u7684\u5305\u3002<\/p>\n<p>\u90a3\u4e48\u7528\u6237\u5c31\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u65b9\u5f0f\uff0c\u76f4\u63a5\u96c6\u6210\u4f7f\u7528\u5b83\uff1a<\/p>\n<pre><code>add_requires(\"libusb\") target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.c\")     add_packages(\"libusb\") <\/code><\/pre>\n<p>\u5982\u679c\u7528\u6237\u7cfb\u7edf\u4e0a\u786e\u5b9e\u6ca1\u6709\u5b89\u88c5 libusb\uff0c\u90a3\u4e48 xmake \u4f1a\u81ea\u52a8\u4e0b\u8f7d libusb \u5e93\u6e90\u7801\uff0c\u81ea\u52a8\u7f16\u8bd1\u5b89\u88c5\u96c6\u6210\uff0c\u6ca1\u5565\u95ee\u9898\u3002<\/p>\n<p>\u4f46\u5982\u679c\u7528\u6237\u901a\u8fc7 <code>apt install libusb-1.0<\/code> \u5b89\u88c5\u4e86 libusb \u5e93\u5230\u7cfb\u7edf\uff0c\u90a3\u4e48\u6309\u7406 xmake \u5e94\u8be5\u4f1a\u81ea\u52a8\u4f18\u5148\u67e5\u627e\u7528\u6237\u5b89\u88c5\u5230\u7cfb\u7edf\u73af\u5883\u7684 libusb \u5305\uff0c\u76f4\u63a5\u4f7f\u7528\uff0c\u907f\u514d\u989d\u5916\u7684\u4e0b\u8f7d\u7f16\u8bd1\u5b89\u88c5\u3002<\/p>\n<p>\u4f46\u662f\u95ee\u9898\u6765\u4e86\uff0cxmake \u5185\u90e8\u901a\u8fc7 <code>find_package(\"libusb\")<\/code> \u5e76\u6ca1\u6709\u627e\u6253\u5b83\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f\u56e0\u4e3a\u901a\u8fc7 apt \u5b89\u88c5\u7684 libusb \u5305\u540d\u662f <code>libusb-1.0<\/code>, \u800c\u4e0d\u662f libusb \u3002<\/p>\n<p>\u6211\u4eec\u53ea\u80fd\u901a\u8fc7 <code>pkg-config --cflags libusb-1.0<\/code> \u624d\u80fd\u627e\u5230\u5b83\uff0c\u4f46\u662f xmake \u5185\u90e8\u7684\u9ed8\u8ba4 find_package \u903b\u8f91\u5e76\u4e0d\u77e5\u9053 <code>libusb-1.0<\/code> \u7684\u5b58\u5728\uff0c\u6240\u4ee5\u627e\u4e0d\u5230\u3002<\/p>\n<p>\u56e0\u6b64\u4e3a\u4e86\u66f4\u597d\u5730\u9002\u914d\u4e0d\u540c\u7cfb\u7edf\u73af\u5883\u4e0b\uff0c\u7cfb\u7edf\u5e93\u7684\u67e5\u627e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 <code>add_extsources(\"pkgconfig::libusb-1.0\")<\/code> \u53bb\u8ba9 xmake \u6539\u8fdb\u67e5\u627e\u903b\u8f91\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>package(\"libusb\")     add_extsources(\"pkgconfig::libusb-1.0\")     on_install(function (package)         -- ...     end) <\/code><\/pre>\n<p>\u53e6\u5916\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u65b9\u5f0f\uff0c\u6539\u8fdb\u67e5\u627e homebrew\/pacman \u7b49\u5176\u4ed6\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u7684\u5305\uff0c\u4f8b\u5982\uff1a<code>add_extsources(\"pacman::libusb-1.0\")<\/code>\u3002<\/p>\n<h4>\u4f7f\u7528 on_fetch \u5b8c\u5168\u5b9a\u5236\u7cfb\u7edf\u5e93\u67e5\u627e<\/h4>\n<p>\u5982\u679c\u4e0d\u540c\u7cfb\u7edf\u4e0b\u5b89\u88c5\u7684\u7cfb\u7edf\u5e93\uff0c\u4ec5\u4ec5\u53ea\u662f\u5305\u540d\u4e0d\u540c\uff0c\u90a3\u4e48\u4f7f\u7528 <code>add_extsources<\/code> \u6539\u8fdb\u7cfb\u7edf\u5e93\u67e5\u627e\u5df2\u7ecf\u8db3\u591f\uff0c\u7b80\u5355\u65b9\u4fbf\u3002<\/p>\n<p>\u4f46\u662f\u5982\u679c\u6709\u4e9b\u5b89\u88c5\u5230\u7cfb\u7edf\u7684\u5305\uff0c\u4f4d\u7f6e\u66f4\u52a0\u590d\u6742\uff0c\u60f3\u8981\u627e\u5230\u5b83\u4eec\uff0c\u4e5f\u8bb8\u9700\u8981\u4e00\u4e9b\u989d\u5916\u7684\u811a\u672c\u624d\u80fd\u5b9e\u73b0\uff0c\u4f8b\u5982\uff1awindows \u4e0b\u6ce8\u518c\u8868\u7684\u8bbf\u95ee\u53bb\u67e5\u627e\u5305\u7b49\u7b49\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7 <code>on_fetch<\/code> \u5b8c\u5168\u5b9a\u5236\u5316\u67e5\u627e\u7cfb\u7edf\u5e93\u903b\u8f91\u3002<\/p>\n<p>\u8fd8\u662f\u4ee5 libusb \u4e3a\u4f8b\uff0c\u6211\u4eec\u4e0d\u7528 <code>add_extsources<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u5f0f\uff0c\u5b9e\u73b0\u76f8\u540c\u7684\u6548\u679c\uff0c\u5f53\u7136\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u91cc\u9762\u505a\u66f4\u591a\u7684\u4e8b\u60c5\u3002<\/p>\n<pre><code>package(\"libusb\")     on_fetch(\"linux\", function(package, opt)         if opt.system then             return find_package(\"pkgconfig::libusb-1.0\")         end     end) <\/code><\/pre>\n<h3>manifest \u6587\u4ef6\u652f\u6301<\/h3>\n<p>\u5728\u65b0\u7248\u672c\u4e2d\uff0c\u6211\u4eec\u8fd8\u65b0\u589e\u4e86\u5bf9 windows <code>.manifest<\/code> \u6587\u4ef6\u7684\u652f\u6301\uff0c\u53ea\u9700\u8981\u901a\u8fc7 <code>add_files<\/code> \u6dfb\u52a0\u8fdb\u6765\u5373\u53ef\u3002<\/p>\n<pre><code>add_rules(\"mode.debug\", \"mode.release\") target(\"test\")     set_kind(\"binary\")     add_files(\"src\/*.cpp\")     add_files(\"src\/*.manifest\") <\/code><\/pre>\n<h3>xrepo \u547d\u4ee4\u6539\u8fdb<\/h3>\n<p>\u5173\u4e8e xrepo \u547d\u4ee4\uff0c\u6211\u4eec\u4e5f\u7a0d\u5fae\u6539\u8fdb\u4e86\u4e0b\uff0c\u73b0\u5728\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u6279\u91cf\u5378\u8f7d\u5220\u9664\u5df2\u7ecf\u5b89\u88c5\u7684\u5305\uff0c\u652f\u6301\u6a21\u5f0f\u5339\u914d\uff1a<\/p>\n<pre><code>$ xrepo remove --all $ xrepo remove --all zlib pcr* <\/code><\/pre>\n<h3>\u5305\u7684\u4f9d\u8d56\u5bfc\u51fa\u652f\u6301<\/h3>\n<p>\u6211\u4eec\u4e5f\u6539\u8fdb\u4e86 <code>add_packages<\/code>\uff0c\u4f7f\u5176\u4e5f\u652f\u6301 <code>{public = true}<\/code> \u6765\u5bfc\u51fa\u5305\u914d\u7f6e\u7ed9\u7236 target \u3002<\/p>\n<pre><code>add_rules(\"mode.debug\", \"mode.release\") add_requires(\"pcre2\")  target(\"test\")     set_kind(\"shared\")     add_packages(\"pcre2\", {public = true})     add_files(\"src\/test.cpp\")  target(\"demo\")     add_deps(\"test\")     set_kind(\"binary\")     add_files(\"src\/main.cpp\")  -- \u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u4f7f\u7528\u88ab test \u76ee\u6807\u5bfc\u51fa pcre2 \u5e93 <\/code><\/pre>\n<p>\u81f3\u4e8e\u5177\u4f53\u5bfc\u51fa\u54ea\u4e9b\u914d\u7f6e\u5462\uff1f<\/p>\n<pre><code>-- \u9ed8\u8ba4\u79c1\u6709\uff0c\u4f46\u662f links\/linkdirs \u8fd8\u662f\u4f1a\u81ea\u52a8\u5bfc\u51fa add_packages(\"pcre2\")  -- \u5168\u90e8\u5bfc\u51fa\u3002\u5305\u62ec includedirs, defines add_packages(\"pcre2\", {public = true}) <\/code><\/pre>\n<h2>\u66f4\u65b0\u5185\u5bb9<\/h2>\n<h3>\u65b0\u7279\u6027<\/h3>\n<ul>\n<li>#955: \u652f\u6301 <code>zig cc<\/code> \u548c <code>zig c++<\/code> \u4f5c\u4e3a c\/c++ \u7f16\u8bd1\u5668<\/li>\n<li>#955: \u652f\u6301\u4f7f\u7528 zig \u8fdb\u884c\u4ea4\u53c9\u7f16\u8bd1<\/li>\n<li>#1177: \u6539\u8fdb\u7ec8\u7aef\u548c color codes \u63a2\u6d4b<\/li>\n<li>#1216: \u4f20\u9012\u81ea\u5b9a\u4e49 includes \u811a\u672c\u7ed9 xrepo<\/li>\n<li>\u6dfb\u52a0 linuxos \u5185\u7f6e\u6a21\u5757\u83b7\u53d6 linux \u7cfb\u7edf\u4fe1\u606f<\/li>\n<li>#1217: \u652f\u6301\u5f53\u7f16\u8bd1\u9879\u76ee\u65f6\u81ea\u52a8\u62c9\u53d6\u5de5\u5177\u94fe<\/li>\n<li>#1123: \u6dfb\u52a0 <code>rule(\"utils.symbols.export_all\")<\/code> \u81ea\u52a8\u5bfc\u51fa\u6240\u6709 windows\/dll \u4e2d\u7684\u7b26\u53f7<\/li>\n<li>#1181: \u6dfb\u52a0 <code>utils.platform.gnu2mslib(mslib, gnulib)<\/code> \u6a21\u5757\u63a5\u53e3\u53bb\u8f6c\u6362 mingw\/xxx.dll.a \u5230 msvc xxx.lib<\/li>\n<li>#1246: \u6539\u8fdb\u89c4\u5219\u652f\u6301\u65b0\u7684\u6279\u5904\u7406\u547d\u4ee4\u53bb\u7b80\u5316\u81ea\u5b9a\u4e49\u89c4\u5219\u5b9e\u73b0<\/li>\n<li>#1239: \u6dfb\u52a0 <code>add_extsources<\/code> \u53bb\u6539\u8fdb\u5916\u90e8\u5305\u7684\u67e5\u627e<\/li>\n<li>#1241: \u652f\u6301\u4e3a windows \u7a0b\u5e8f\u6dfb\u52a0 .manifest \u6587\u4ef6\u53c2\u4e0e\u94fe\u63a5<\/li>\n<li>\u652f\u6301\u4f7f\u7528 <code>xrepo remove --all<\/code> \u547d\u4ee4\u53bb\u79fb\u9664\u6240\u6709\u7684\u5305\uff0c\u5e76\u4e14\u652f\u6301\u6a21\u5f0f\u5339\u914d<\/li>\n<li>#1254: \u652f\u6301\u5bfc\u51fa\u5305\u914d\u7f6e\u7ed9\u7236 target\uff0c\u5b9e\u73b0\u5305\u914d\u7f6e\u7684\u4f9d\u8d56\u7ee7\u627f<\/li>\n<\/ul>\n<h3>\u6539\u8fdb<\/h3>\n<ul>\n<li>#1226: \u6dfb\u52a0\u7f3a\u5931\u7684 Qt \u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84<\/li>\n<li>#1183: \u6539\u8fdb C++ \u8bed\u8a00\u6807\u51c6\uff0c\u4ee5\u4fbf\u652f\u6301 Qt6<\/li>\n<li>#1237: \u4e3a vsxmake \u63d2\u4ef6\u6dfb\u52a0 qt.ui \u6587\u4ef6<\/li>\n<li>\u6539\u8fdb vs\/vsxmake \u63d2\u4ef6\u53bb\u652f\u6301\u9884\u7f16\u8bd1\u5934\u6587\u4ef6\u548c\u667a\u80fd\u63d0\u793a<\/li>\n<li>#1090: \u7b80\u5316\u81ea\u5b9a\u4e49\u89c4\u5219<\/li>\n<li>#1065: \u6539\u8fdb protobuf \u89c4\u5219\uff0c\u652f\u6301 compile_commands \u751f\u6210\u5668<\/li>\n<li>#1249: \u6539\u8fdb vs\/vsxmake \u751f\u6210\u5668\u53bb\u652f\u6301\u542f\u52a8\u5de5\u7a0b\u8bbe\u7f6e<\/li>\n<li>#605: \u6539\u8fdb add_deps \u548c add_packages \u76f4\u63a5\u7684\u5bfc\u51fa links \u987a\u5e8f<\/li>\n<li>\u79fb\u9664\u5e9f\u5f03\u7684 <code>add_defines_h_if_ok<\/code> and <code>add_defines_h<\/code> \u63a5\u53e3<\/li>\n<\/ul>\n<h3>Bugs \u4fee\u590d<\/h3>\n<ul>\n<li>#1219: \u4fee\u590d\u7248\u672c\u68c0\u6d4b\u548c\u66f4\u65b0<\/li>\n<li>#1235: \u4fee\u590d includes \u641c\u7d22\u8def\u5f84\u4e2d\u5e26\u6709\u7a7a\u683c\u7f16\u8bd1\u4e0d\u8fc7\u95ee\u9898<\/li>\n<\/ul><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5405521\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dcoder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u652f\u6301\u4e00\u4e2a, \u4e3b\u7ee7\u7eed\u52a0\u6cb9<br \/>\u4f60\u5973\u513f\u7684\u5934\u50cf\u597d\u840c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5405522\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : waruqi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dcoder \u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5405523\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lniwn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e48\u591a\u5e74\uff0c\u4e00\u76f4\u770b\u7740\u4e3b\u9ed8\u9ed8\u63a8\u5e7f\uff0c\u786e\u5b9e\u5389\u5bb3\uff0c\u8868\u793a\u656c\u610f\u3002\u52a0\u6cb9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5405524\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : waruqi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lniwn \u8c22\u8c22\u652f\u6301                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5405525\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\uff0c\u8fd9\u662f\u4f60\u4e2a\u4eba\u9879\u76ee\uff0c\u8fd8\u662f\u516c\u53f8\u7684\u9879\u76ee\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5405526\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : waruqi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yazoox \u4e2a\u4eba\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>xmake v2.5.2 \u53d1\u5e03, &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384000"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=384000"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384000\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384000"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}