{"id":496,"date":"2013-12-26T23:51:02","date_gmt":"2013-12-27T04:51:02","guid":{"rendered":"http:\/\/zhanxw.com\/blog\/?p=496"},"modified":"2013-12-26T23:51:02","modified_gmt":"2013-12-27T04:51:02","slug":"gcc%e5%8f%82%e6%95%b0%e9%a1%ba%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/zhanxw.com\/blog\/2013\/12\/gcc%e5%8f%82%e6%95%b0%e9%a1%ba%e5%ba%8f\/","title":{"rendered":"gcc\u53c2\u6570\u987a\u5e8f"},"content":{"rendered":"<p>gcc\u53c2\u6570\u987a\u5e8f<br \/>\nOrdering of gcc parameters matters<\/p>\n<p>2013\u5e74\u6700\u540e\u4e00\u4e2a\u6708\u6700\u540e\u4e00\u4e2a\u661f\u671f\u8c08\u4e00\u4e2a\u5947\u602a\u7684bug\uff0c\u6211\u5728\u5c1d\u8bd5pinfo\u7684\u65f6\u5019\uff0cconfigure\u811a\u672c\u4f1a\u63d0\u793ancurses\u6709\u95ee\u9898\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nchecking location of curses.h file... \/usr\/include\/ncurses.h\r\nchecking if curses is usable... no\r\nconfigure: error: Curses not found. You need curses to compile pinfo\r\n<\/pre>\n<p>\u6253\u5f00config.log\u6587\u4ef6\uff0c\u53d1\u73b0\u8fd9\u4e2a\u63d0\u793a\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nconfigure:12563: checking if curses is usable\r\nconfigure:12587: gcc -o conftest -g -O2 -I\/usr\/include    -L\/usr\/lib -lncurses conftest.c  &gt;&amp;5\r\n\/tmp\/ccBLkSqd.o: In function `main':\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:38: undefined reference to `initscr'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:39: undefined reference to `printw'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:40: undefined reference to `stdscr'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:40: undefined reference to `wrefresh'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:41: undefined reference to `stdscr'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:41: undefined reference to `wgetch'\r\n\/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:42: undefined reference to `endwin'\r\ncollect2: ld returned 1 exit status\r\n<\/pre>\n<p>\u4ece\u8fd9\u4e2a\u547d\u4ee4\u884c\u6765\u770b\uff0ccurses\u5e93\u7684\u5934\u6587\u4ef6\u76ee\u5f55\u548c\u5e93\u6587\u4ef6\u76ee\u5f55\u90fd\u5bf9\uff0c\u4f46\u7f16\u8bd1\u7684\u65f6\u5019\uff08\u94fe\u63a5\/tmp\/ccBLkSqd.o\uff09\u5374\u627e\u4e0d\u5230\u51e0\u4e2a\u51fd\u6570\u7684\u5b9a\u4e49\uff08\u6bd4\u5982\uff1ainitscr\uff0cprintw\u7b49\u7b49\uff09\u3002\u4e3a\u4e86\u91cd\u73b0\u8fd9\u4e2a\u770b\u8d77\u6765\u4e0d\u8be5\u51fa\u73b0\u7684\u95ee\u9898\uff0c\u6211\u628aconftest.c\u521b\u5efa\u597d\uff0c\u7136\u540e\u7528\u76f8\u540c\u7684gcc\u547d\u4ee4\u884c\u7f16\u8bd1\u4ee3\u7801\uff0c\u7684\u786e\u662f\u53ef\u4ee5\u91cd\u73b0\u9519\u8bef\u3002<\/p>\n<p>\u66f4\u4ee4\u6211\u4e0d\u89e3\u7684\u662f\u5982\u679c\u628aconftest.c\u653e\u5230\u547d\u4ee4\u884c\u7684\u672b\u5c3e\uff0c\u8fd9\u4e2a\u7f16\u8bd1\u5c31\u80fd\u901a\u8fc7\u4e86\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# This does not work\r\ngcc -o conftest -g -O2 -I\/usr\/include    -L\/usr\/lib -lncurses conftest.c \r\n# This works\r\ngcc -o conftest conftest.c -g -O2 -I\/usr\/include    -L\/usr\/lib -lncurses  \r\n<\/pre>\n<p>\u4e3a\u4ec0\u4e48\u628aconftest.c\u79fb\u5230\u201c-L\/usr\/lib -lncurses\u201d\u524d\u9762\u5c31\u80fd\u89e3\u51b3\u95ee\u9898\uff1f<br \/>\n\u770b\u5230StackOverFlow\u4e0a\u7684\u4e00\u4e2a<a href=\"http:\/\/stackoverflow.com\/questions\/2632505\/argument-order-in-cygwin-gcc-4-3-matters-when-linking-with-glib-2-0\" title=\"argument order in cygwin gcc 4.3 matters when linking with glib-2.0\">\u5e16\u5b50<\/a>\uff1a<\/p>\n<p>\u8fd9\u4e2a\u5e16\u5b50\u8bb2\u5230gcc\u7f16\u8bd1\u548c\u94fe\u63a5\u4e00\u4e2a\u6e90\u7a0b\u5e8f\u65f6\uff0c\u4f1a\u4fdd\u7559\u53c2\u6570\u7684\u987a\u5e8f\uff0c\u4e5f\u5c31\u662f\u8bf4\u5728\u94fe\u63a5\u65f6\uff0c\u628aconftest.c\u653e\u5230\u524d\u9762\u548c\u540e\u9762\uff0c\u6548\u679c\u4e0d\u540c\u3002\u5177\u4f53\u6765\u8bb2\uff1a<\/p>\n<p>conftest.c \u653e\u5230\u540e\u9762<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ngcc -o conftest -g -O2 -I\/usr\/include    -L\/usr\/lib -lncurses conftest.c \r\n&lt;=&gt; \u7b49\u4ef7\u4e8e\r\ngcc -o conftest -g -O2 -L\/usr\/lib -lncurses tmporary_object_file.o\r\n<\/pre>\n<p>conftest.c \u653e\u5230\u524d\u9762<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ngcc -o conftest -g -O2 -I\/usr\/include conftest.c -L\/usr\/lib -lncurses \r\n&lt;=&gt; \u7b49\u4ef7\u4e8e\r\ngcc -o conftest -g -O2 tmporary_object_file.o -L\/usr\/lib -lncurses \r\n<\/pre>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0cgcc\u5728\u94fe\u63a5\u76ee\u6807\u6587\u4ef6\u65f6\uff0c\u4f1a\u4f9d\u7167\u547d\u4ee4\u884c\u7684\u987a\u5e8f\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5728\u524d\u9762\u76ee\u6807\u6587\u4ef6\u4e2d\u6ca1\u6709\u5b9a\u4e49\u7684\u51fd\u6570\uff0c\u90fd\u8bd5\u7740\u5728\u5176\u540e\u9762\u7684\u76ee\u6807\u6587\u4ef6\u627e\u627e\uff0c\u5982\u679c\u6700\u540e\u4e00\u4e2a\u76ee\u6807\u6587\u4ef6\u4e5f\u627e\u4e0d\u5230\uff0c\u5c31\u62a5\u9519\u3002\u56e0\u6b64\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u91cc\uff0ctmporary_object_file.o\u4e00\u5b9a\u8981\u653e\u5230-L\/usr\/lib -lncurses\u524d\u9762\u624d\u80fd\u6b63\u786e\u7f16\u8bd1\u3002<\/p>\n<p>\u56de\u5230\u672c\u6587\u6700\u5f00\u59cb\uff0c\u6211\u4eec\u5982\u4f55\u8ba9configure\u628aconftest.c\u653e\u5230\u201c-L\u201d\u524d\u9762\uff1f\u7b54\u6848\u4e0d\u662f\u6539\u52a8configure\uff0c\u800c\u662f\u4f7f\u7528LIBS\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nLIBS=&quot;-L\/usr\/lib -lncurses&quot; .\/configure\r\n<\/pre>\n<p>\u4e0eLIBS\u4e0d\u540c\uff0cLDFLAGS\u4f1a\u653e\u5230conftest.c\u524d\u9762\uff0c\u8fd9\u6837configure\u8fd8\u662f\u6ca1\u6cd5\u6b63\u786e\u7684\u4f7f\u7528configure\u3002<\/p>\n<p>\u5728\u672c\u6587\u6700\u540e\uff0c\u56de\u60f3\u6211\u4eec\u672c\u6765\u7684\u95ee\u9898\uff0c\u5c31\u662f\u8bf4gcc\u7684\u53c2\u6570\u6709\u4e00\u5b9a\u7684\u987a\u5e8f\u8981\u6c42\u3002\u4e5f\u8bb8gcc\u7684\u624b\u518c\u91cc\u5199\u4e86\u987a\u5e8f\u7684\u8981\u6c42\uff0c\u4f46\u662f\u5f88\u5c11\u6709\u4eba\u80fd\u591f\u770b\u5b8cgcc\u7684\u624b\u518c\u3002\u5982\u679c\u89c1\u5230\u7c7b\u4f3c\u95ee\u9898\uff0c\u5e94\u8be5\u600e\u4e48\u529e\u5462\uff1f\u6211\u89c9\u5f97\u53ef\u4ee5\u6709\u4e24\u4e2a\u601d\u8def\uff0c\u7b2c\u4e00\u4e2a\u5c31\u662f\u60f3\u60f3\u5199gcc\u8f6f\u4ef6\u7684\u4eba\u662f\u600e\u4e48\u60f3\u7684\u3002\u6bd4\u5982\u73b0\u5728gcc\u7684\u9009\u62e9\u5c31\u662f\u4e00\u4e2a\u5f88\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u5982\u679c\u5f53\u524d\u6ca1\u67d0\u4e2a\u51fd\u6570\u6ca1\u6709\u5b9a\u4e49\uff0c\u5c31\u5728\u4ed6\u540e\u9762\u5236\u5b9a\u7684\u76ee\u6807\u6587\u4ef6\u91cc\u627e\u627e\u3002\u5982\u679c\u8fd9\u4e2a\u8981\u6c42\u53cd\u8fc7\u6765\uff0c\u6216\u8005\u4efb\u4f55\u987a\u5e8f\u90fd\u652f\u6301\uff0c\u90a3\u4e48\u94fe\u63a5\u7684\u51fd\u6570\u5c31\u4f1a\u590d\u6742\uff08\u56e0\u4e3a\u94fe\u63a5\u7a0b\u5e8f\u9700\u8981\u5b58\u50a8\u6240\u6709\u5b9a\u4e49\u8fc7\u7684\u51fd\u6570\uff0c\u53c2\u89c1<a href=\"http:\/\/stackoverflow.com\/questions\/7826448\/linking-libraries-with-gcc-order-of-arguments\" title=\"Linking libraries with gcc: order of arguments\">\u94fe\u63a5<\/a>\uff09\uff1b\u7b2c\u4e8c\u4e2a\u5c31\u662f\u60f3\u60f3\u4f20\u7edf\u7684\uff08\u6216\u8005\u6807\u51c6\u7684\uff09\u5199\u6cd5\u662f\u4ec0\u4e48\uff0c\u628a\u5df2\u77e5\u7684\u7ecf\u9a8c\u548c\u8fd9\u4e2a\u9519\u8bef\u8054\u7cfb\u8d77\u6765\u3002\u6bd4\u5982configure\u7684\u9519\u8bef\u770b\u8d77\u6765\u5f88\u5947\u602a\uff0c\u4f46\u662f\u5148\u6309\u7167\u4f20\u7edf\u7684\u5199\u6cd5\u5148\u7f16\u8bd1\u540e\u94fe\u63a5\uff0c\u627e\u5230\u4e00\u4e2a\u80fd\u51d1\u5408\u5de5\u4f5c\u7684\u65b9\u6848\uff08\u628aconftest.c\u653e\u5230\u524d\u9762\uff09\uff0c\u518d\u9010\u6b65\u6539\u53d8\u5230\u51fa\u9519\u65f6\u7684\u547d\u4ee4\u884c\uff0c\u8fd9\u4e2a\u9010\u6b65\u7684\u8fc7\u7a0b\u53ef\u4ee5\u5e2e\u52a9\u67e5\u9519\u4e5f\u80fd\u5de9\u56fa\u4e00\u4e0b\u5df2\u6709\u7684\u77e5\u8bc6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>gcc\u53c2\u6570\u987a\u5e8f Ordering of gcc parameters matters 2013\u5e74\u6700\u540e\u4e00\u4e2a\u6708\u6700\u540e\u4e00\u4e2a\u661f\u671f\u8c08\u4e00\u4e2a\u5947\u602a\u7684bug\uff0c\u6211\u5728\u5c1d\u8bd5pinfo\u7684\u65f6\u5019\uff0cconfigure\u811a\u672c\u4f1a\u63d0\u793ancurses\u6709\u95ee\u9898\uff1a checking location of curses.h file&#8230; \/usr\/include\/ncurses.h checking if curses is usable&#8230; no configure: error: Curses not found. You need curses to compile pinfo \u6253\u5f00config.log\u6587\u4ef6\uff0c\u53d1\u73b0\u8fd9\u4e2a\u63d0\u793a\uff1a configure:12563: checking if curses is usable configure:12587: gcc -o conftest -g -O2 -I\/usr\/include -L\/usr\/lib -lncurses conftest.c &gt;&amp;5 \/tmp\/ccBLkSqd.o: In function `main&#8217;: \/net\/fantasia\/home\/zhanxw\/software\/pinfo-0.6.10\/conftest.c:38: undefined reference [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[74,14],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-sysadmin","tag-gcc","tag-linux"],"_links":{"self":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}