{"id":10020787,"date":"2025-05-04T12:54:53","date_gmt":"2025-05-04T04:54:53","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020787"},"modified":"2025-05-04T12:54:53","modified_gmt":"2025-05-04T04:54:53","slug":"c-%e4%b8%ad-vs-%e9%a1%b9%e7%9b%ae%e5%bc%95%e5%85%a5%e5%85%ac%e5%85%b1%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020787","title":{"rendered":"C++ \u4e2d VS \u9879\u76ee\u5f15\u5165\u516c\u5171\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"<p>\u5728\u7528 VS \u505a\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u9879\u76ee\u7684\u89e3\u51b3\u65b9\u6848\u7684\u9879\u76ee\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u591a\u4e2a\u9879\u76ee\u9700\u8981\u5f15\u5165\u76f8\u540c\u7684\u914d\u7f6e\u7684\u60c5\u51b5\uff0c\u5982 C++ \u7248\u672c\u3001\u9644\u52a0\u5e93\u76ee\u5f55\u3001\u9644\u52a0\u5305\u542b\u76ee\u5f55\u7b49\uff0c\u53ef\u4ee5\u4f7f\u7528\u672c\u6587\u63d0\u4f9b\u7684\u65b9\u6cd5\u6765\u5f15\u5165\u516c\u5171\u914d\u7f6e\u6587\u4ef6\u907f\u514d\u91cd\u590d\u914d\u7f6e\u3002<\/p>\n<h2>1. \u5c06\u7b2c\u4e09\u65b9\u5e93\u548c\u9a71\u52a8\u76ee\u5f55\u901a\u8fc7\u8f6f\u8fde\u63a5\u914d\u7f6e\u5230\u9879\u76ee\u4e2d<\/h2>\n<p>\u5bf9\u4e8e\u9879\u76ee\u4e2d\u9700\u8981\u5f15\u5165\u7684\u4e00\u4e9b\u672c\u5730\u5b89\u88c5\u7684\u786c\u4ef6\u9a71\u52a8\u548c\u5e93\uff0c\u5982 <code>OpenSSL<\/code> \u9a71\u52a8\u3001\u7b2c\u4e09\u65b9\u786c\u4ef6\u9a71\u52a8\u5e93\u7b49\uff0c\u7531\u4e8e\u6bcf\u4e2a\u4eba\u5b89\u88c5\u7684\u9a71\u52a8\u4f4d\u7f6e\u53ef\u80fd\u4e0d\u4e00\u6837\uff0c\u6216\u8005\u7535\u8111\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684\u9a71\u52a8\u7b49\u60c5\u51b5\uff08\u6bd4\u5982\u6211\u7684\u7535\u8111\u4e0a\u5c31\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684 OpenSSL \u9a71\u52a8\uff09\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f6f\u8fde\u63a5\u7684\u65b9\u5f0f\uff0c\u5c06\u8fd9\u4e9b\u7b2c\u4e09\u65b9\u5e93\u548c\u9a71\u52a8\u7684\u5934\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\u5730\u5740\u94fe\u63a5\u5230\u9879\u76ee\u76ee\u5f55\u7684\u56fa\u5b9a\u4f4d\u7f6e\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u901a\u8fc7 VS \u7684\u5b8f\uff08\u5982\u89e3\u51b3\u65b9\u6848\u76ee\u5f55 <code>SolutionDir<\/code>\u3001\u8fd0\u884c\u6a21\u5f0f <code>Configuration<\/code> \u7b49\uff09\u914d\u7f6e\u7684\u5e93\u76ee\u5f55\u548c\u5305\u542b\u76ee\u5f55\u6765\u5f15\u5165\u8fd9\u4e9b\u7b2c\u4e09\u65b9\u5e93\u548c\u9a71\u52a8\u3002<\/p>\n<p>\u6bd4\u5982\u6211\u7535\u8111\u4e0a\u7684 <code>OpenSSL@1.1.1(x64)<\/code> \u7684\u76ee\u5f55\u662f <code>C:\/Program Files\/OpenSSL-Win64-1_1_1<\/code>\uff0c\u53ef\u4ee5\u5c06\u5176\u653e\u8f6f\u8fde\u63a5\u5230\u9879\u76ee\u7684 <code>thirdparty<\/code> \u76ee\u5f55\u4e0b\uff1a<\/p>\n<pre><code class=\"bash\">mklink \/d &quot;C:\/Projects\/hello_sln\/thirdparty\/OpenSSL-Win64&quot; &quot;C:\/Program Files\/OpenSSL-Win64-1_1_1&quot;<\/code><\/pre>\n<p>\u8fd9\u6837\u5728\u9879\u76ee\u4e2d\u5c31\u53ef\u4ee5\u901a\u8fc7\u5b8f <code>$(SolutionDir)..\/thirdparty\/OpenSSL-Win64\/include<\/code> \u6765\u5f15\u5165 <code>OpenSSL-Win64<\/code> \u7684\u5934\u6587\u4ef6\u76ee\u5f55\u3002<\/p>\n<p>\u9879\u76ee\u6587\u4ef6\u7ec4\u7ec7\uff1a<\/p>\n<pre><code class=\"bash\">hello_sln\n\u251c\u2500\u2500 app\n    \u251c\u2500\u2500 CommonSettings.props\n    \u2514\u2500\u2500 hello_sln.sln\n\u251c\u2500\u2500lib\n    \u2514\u2500\u2500  hello_proj\n        \u251c\u2500\u2500 hello_sln.vcxproj.filters\n        \u2514\u2500\u2500 hello_proj.vcxproj \n\u2514\u2500\u2500 thirdparty\n    \u251c\u2500\u2500 OpenSSL-Win64 -&gt; C:\/Program Files\/OpenSSL-Win64-1_1_1\n    \u2514\u2500\u2500 boost -&gt; C:\/local\/boost_1_83_0<\/code><\/pre>\n<h2>2. \u914d\u7f6e\u7b2c\u4e09\u65b9\u5e93\u548c\u9a71\u52a8\u76ee\u5f55<\/h2>\n<p>\u4e00\u822c\u5728 VS \u7684\u89e3\u51b3\u65b9\u6848\u4e0b\u521b\u5efa\u4e00\u4e2a\u9879\u76ee\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9700\u8981\u5728\u9879\u76ee\u5c5e\u6027\u4e2d\u5bf9\u8be5\u9879\u76ee\u7684\u4e00\u4e9b\u5c5e\u6027\u8fdb\u884c\u914d\u7f6e\uff0c\u6bd4\u5982\u8981\u7528\u7684 C++ \u8bed\u8a00\u7248\u672c\u3001\u9644\u52a0\u5e93\u76ee\u5f55\u3001\u9644\u52a0\u5305\u542b\u76ee\u5f55\u7b49\u7b49\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000046509599\" alt=\"\u9879\u76ee\u5c5e\u6027\u9875\" title=\"\u9879\u76ee\u5c5e\u6027\u9875\"><\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\u4e0b\u6709\u591a\u4e2a\u9879\u76ee\uff0c\u6bcf\u4e2a\u9879\u76ee\u90fd\u9700\u8981\u5bf9\u8fd9\u4e9b\u5c5e\u6027\u8fdb\u884c\u914d\u7f6e\uff0c\u5c31\u4f1a\u5f88\u9ebb\u70e6\uff0c\u53ef\u4e0d\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u516c\u5171\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u5728\u6bcf\u4e2a\u9879\u76ee\u4e2d\u5f15\u5165\u8fd9\u4e2a\u516c\u5171\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u907f\u514d\u91cd\u590d\u914d\u7f6e\u5462\u3002<\/p>\n<p>\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff0cVS \u63d0\u4f9b\u4e86 <code>.props<\/code> \u516c\u5171\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u5728\u6bcf\u4e2a\u9879\u76ee\u4e2d\u5f15\u5165\u8fd9\u4e2a\u516c\u5171\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u5f53\u6210\u9879\u76ee\u914d\u7f6e\u6587\u4ef6 <code>.vcxproj<\/code> \u7684\u8865\u5145\u914d\u7f6e\uff0c\u8fd9<a href=\"https:\/\/link.segmentfault.com\/?enc=UfZaM0uG0vlTsZHt9KK0xQ%3D%3D.LC%2BpkwXOnxLNlioLblPPS7w68lZFVm4GjAd99qYLGyfusu8mnCtmbXUu7J3t6YS9ncraoELd1Hp2sBSRRkzR0Tb0TbK7FoY9GWv5tT888qYiVtLQO%2FJNnDm1XpvbbNer\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4e24\u4e2a\u6587\u4ef6\u7684\u7ed3\u6784\u662f\u4e00\u81f4\u7684<\/a>\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728 <code>.vcxproj<\/code> \u5f15\u5165\u6211\u4eec\u7684 <code>.props<\/code> \u516c\u5171\u914d\u7f6e\u6587\u4ef6\u8ba9 VS \u52a0\u8f7d\u9879\u76ee\u7684\u65f6\u5019\u5408\u5e76\u8fd9\u4e24\u4e2a\u6587\u4ef6\uff0c\u4ece\u800c\u907f\u514d\u91cd\u590d\u914d\u7f6e\u3002<\/p>\n<h2>3. \u521b\u5efa props \u516c\u5171\u914d\u7f6e\u6587\u4ef6<\/h2>\n<p>\u7136\u540e\u5728\u89e3\u51b3\u65b9\u6848\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a <code>CommonSettings.props<\/code> \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; ?&gt;\n&lt;Project xmlns=&quot;http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003&quot; ToolsVersion=&quot;4.0&quot;&gt;\n  &lt;ItemDefinitionGroup Condition=&quot;'$(Configuration)|$(Platform)'=='Debug|x64'&quot;&gt;\n    &lt;ClCompile&gt;\n       &lt;LanguageStandard&gt;stdcpp17&lt;\/LanguageStandard&gt;\n       &lt;PreprocessorDefinitions&gt;_HELLO&lt;\/PreprocessorDefinitions&gt;\n      &lt;AdditionalIncludeDirectories&gt;$(SolutionDir)..\/thirdparty;$(SolutionDir)..\/thirdparty\/OpenSSL-Win64\/include&lt;\/AdditionalIncludeDirectories&gt;\n    &lt;\/ClCompile&gt;\n    &lt;Link&gt;\n      &lt;AdditionalLibraryDirectories&gt;$(SolutionDir)..\/thirdparty\/OpenSSL-Win64\/lib\/VC&lt;\/AdditionalLibraryDirectories&gt;\n    &lt;\/Link&gt;\n  &lt;\/ItemDefinitionGroup&gt;\n&lt;\/Project&gt;<\/code><\/pre>\n<blockquote><p>\u8fd9\u91cc\u4ec5\u52a0\u5165\u4e86 64 \u4f4d Debug \u6a21\u5f0f\u7684\u914d\u7f6e\uff0cRelease \u6a21\u5f0f\u7684\u914d\u7f6e\u53ef\u4ee5\u81ea\u5df1\u6dfb\u52a0\u3002<\/p><\/blockquote>\n<p>\u6bd4\u5982\u6211\u4eec\u5e0c\u671b\u6240\u6709\u9879\u76ee\u90fd\u7528 C++17 \u6807\u51c6\uff0c\u6240\u6709\u9879\u76ee\u90fd\u9700\u8981\u9884\u5904\u7406\u5668\u5b9a\u4e49 <code>_HELLO<\/code>\uff0c\u9644\u52a0\u5305\u542b\u76ee\u5f55\u5f15\u5165 <code>thridparty<\/code> \u7b2c\u4e09\u65b9\u5e93\u548c\u9a71\u52a8\u76ee\u5f55\uff0c\u9644\u52a0\u5e93\u76ee\u5f55\u5f15\u5165 <code>OpenSSL-Win64\/lib\/VC<\/code> \u76ee\u5f55\u3002\u5c31\u53ef\u4ee5\u7528 <code>LanguageStandard<\/code> \u914d\u7f6e\u5176\u8bed\u8a00\uff0c\u7528 <code>PreprocessorDefinitions<\/code> \u914d\u7f6e\u9884\u5904\u7406\u5668\u5b9a\u4e49\uff0c\u7136\u540e\u7528 <code>AdditionalIncludeDirectories<\/code> \u914d\u7f6e\u9644\u52a0\u5305\u542b\u76ee\u5f55\uff0c\u7528 <code>AdditionalLibraryDirectories<\/code> \u914d\u7f6e\u9644\u52a0\u5e93\u76ee\u5f55\uff0c\u8fd9\u51e0\u4e2a\u662f\u5927\u90e8\u5206\u9879\u76ee\u4e2d\u7684\u91cd\u590d\u914d\u7f6e\u3002<\/p>\n<p>\u7136\u540e\u5728\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6 <code>hello_proj.vcxproj<\/code> \u589e\u52a0\u8fd9\u4e2a\u516c\u5171\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"xml\">  &lt;Import Project=&quot;$(SolutionDir)\/CommonSettings.props&quot; Condition=&quot;exists('$(SolutionDir)\/CommonSettings.props')&quot; Label=&quot;LocalCommonSettings&quot; \/&gt;<\/code><\/pre>\n<p>\u50cf\u8fd9\u6837\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000046509600\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u7136\u540e\u6211\u4eec\u91cd\u65b0\u52a0\u8f7d\u9879\u76ee\uff0c\u6216\u8005\u91cd\u542f VS\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u9879\u76ee\u7684\u5c5e\u6027\u914d\u7f6e\u4e2d\u5df2\u7ecf\u5f15\u5165\u4e86\u8fd9\u4e2a\u516c\u5171\u914d\u7f6e\u6587\u4ef6\u7684\u914d\u7f6e\u4e86\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000046509601\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u9879\u76ee\u4ece\u6211\u4eec\u7684 <code>CommonSettings.props<\/code> \u516c\u5171\u914d\u7f6e\u6587\u4ef6\u4e2d\u7ee7\u627f\u4e86\u914d\u7f6e\uff0c\u540e\u9762\u7ed9\u65b0\u589e\u7684\u9879\u76ee\u7684 <code>.vcxproj<\/code> \u5f00\u5934\u589e\u52a0 <code>CommonSettings.props<\/code> \u7684\u914d\u7f6e\u5c31\u53ef\u4ee5\u5f15\u5165\u6211\u4eec\u7684\u516c\u5171\u914d\u7f6e\uff0c\u5982\u679c\u5f15\u5165\u4e86\u65b0\u7684\u516c\u5171\u7b2c\u4e09\u65b9\u9a71\u52a8\u548c\u5e93\uff0c\u901a\u8fc7\u5728 <code>CommonSettings.props<\/code> \u4e2d\u589e\u52a0\u914d\u7f6e\u5373\u53ef\u3002<\/p>\n<hr>\n<p>\u7f51\u4e0a\u7684\u5e16\u5b50\u5927\u591a\u6df1\u6d45\u4e0d\u4e00\uff0c\u751a\u81f3\u6709\u4e9b\u524d\u540e\u77db\u76fe\uff0c\u5728\u4e0b\u7684\u6587\u7ae0\u90fd\u662f\u5b66\u4e60\u8fc7\u7a0b\u4e2d\u7684\u603b\u7ed3\uff0c\u5982\u679c\u53d1\u73b0\u9519\u8bef\uff0c\u6b22\u8fce\u7559\u8a00\u6307\u51fa\uff0c\u5982\u679c\u672c\u6587\u5e2e\u52a9\u5230\u4e86\u4f60\uff0c\u522b\u5fd8\u4e86\u70b9\u8d5e\u652f\u6301\u4e00\u4e0b\uff0c\u4f60\u7684\u70b9\u8d5e\u662f\u6211\u66f4\u65b0\u7684\u6700\u5927\u52a8\u529b\uff01~<\/p>\n<blockquote>\n<p>\u53c2\u8003\u6587\u6863\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=XmOI3yexfA4cLLq3e3NhPA%3D%3D.ybm6SpED%2FtsXU5M%2Fp4hdaumqq9Qo8EPR%2FFamg0PSqg05KqMQYo%2BWXiXB5%2F7oupR0R7uW4wYpRMbeJYP2mDTq2aczlUseSFtD1cZ1O1LtX490%2BhUwlZKxklufKU5nppjo\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">.vcxproj \u548c .props \u6587\u4ef6\u7ed3\u6784 | Microsoft Learn<\/a><\/li>\n<\/ol>\n<\/blockquote>\n<p>PS\uff1a\u672c\u6587\u540c\u6b65\u66f4\u65b0\u4e8e\u5728\u4e0b\u7684\u535a\u5ba2 <a href=\"https:\/\/link.segmentfault.com\/?enc=5ckAo4ByaPb03RQsvX0z8w%3D%3D.TUf6Zkt3WpmRQLgezaIC4br2MWTjmMYo1dxK1TuDd%2F9%2BzHeJZ9KfycmystRpbOImx9HcFrhnSy2OgVglxhTG59W7eCTDKnSvakK9ZgSRRgs%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Github &#8211; SHERlocked93\/blog<\/a> \u7cfb\u5217\u6587\u7ae0\u4e2d\uff0c\u5171\u540c\u8fdb\u6b65\uff0c\u4e00\u8d77\u52a0\u6cb9~<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046509596\">https:\/\/segmentfault.com\/a\/1190000046509596<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u7528 VS \u505a\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u9879\u76ee\u7684\u89e3\u51b3\u65b9\u6848\u7684\u9879\u76ee\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u591a\u4e2a\u9879\u76ee\u9700\u8981\u5f15\u5165\u76f8\u540c\u7684\u914d\u7f6e\u7684\u60c5\u51b5\uff0c\u5982 C++ \u7248\u672c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020787","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020787"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020787\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}