{"id":161,"date":"2016-02-01T08:26:18","date_gmt":"2016-02-01T08:26:18","guid":{"rendered":""},"modified":"2016-02-01T08:26:18","modified_gmt":"2016-02-01T08:26:18","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=161","title":{"rendered":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b"},"content":{"rendered":"<p>\n\t1.Python\/dynload_shlib.c:94: undefined reference to `dlsym&#8217;\n<\/p>\n<p>\n\tto solve the problems such as under Ubuntu:\n<\/p>\n<p>\n\t&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;\n<\/p>\n<p>\n\tPython\/dynload_shlib.c:94: undefined reference to `dlsym&#8217;<br \/>\ndynload_shlib.c:130: undefined reference to `dlopen&#8217;<br \/>\nPython\/dynload_shlib.c:141: undefined reference to `dlsym&#8217;<br \/>\nPython\/dynload_shlib.c:133: undefined reference to `dlerror&#8217;\n<\/p>\n<p>\n\t&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\n<\/p>\n<p>\n\tTo solve this linking problem, run &#8216;python-config &#8211;libs&#8217;, then you got the dynamic library list. Find where these libs are, and add their paths to LD_LIBRARY_PATH before &#8216;scons .\/build\/ARM\/gem5.opt&#8217;\n<\/p>\n<p>\n\tFinally, it works!\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t2.PyImport_Import() fail:<\/p>\n<tr style=\"box-sizing:border-box;widows:1;text-transform:none;background-color:#ffffff;text-indent:0px;font:12px\/15px 'Microsoft Yahei', Helvetica, Arial, sans-serif;white-space:normal;letter-spacing:normal;color:#3d4450;word-spacing:0px;-webkit-text-stroke-width:0px;\" class=\"crayon-row\">\n<td style=\"box-sizing:border-box;\" class=\"crayon-code\">\n<div style=\"box-sizing:border-box;line-height:15px !important;font-size:12px !important;\" class=\"crayon-pre\">\n<div style=\"box-sizing:border-box;\" id=\"crayon-56b1c4e8df7d0017647865-1\" class=\"crayon-line\">\n\t\t\t\t\t\t<span style=\"box-sizing:border-box;\" class=\"crayon-v\">ImportError<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">:<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-h\"><span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">usr<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">local<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">lib<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">python2<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-sy\">.<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-cn\">7<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">lib<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">&#8211;<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">dynload<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">\/<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">_socket<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-sy\">.<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">so<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">:<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-h\"><span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><span style=\"box-sizing:border-box;\" class=\"crayon-e\">undefined<span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">symbol<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-o\">:<\/span><span style=\"box-sizing:border-box;\" class=\"crayon-h\"><span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><span style=\"box-sizing:border-box;\" class=\"crayon-v\">PyExc_ValueError<\/span>\n\t\t\t\t\t<\/div>\n<\/p><\/div>\n<p>\n\t\t\t\t\t\u5982\u679cpython\u5728\u7f16\u8bd1\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u4f7f\u7528:<br \/>\n.\/configure &#8211;enable-shared<br \/>\n\u90a3\u4e48\u5c31\u4f1a\u9020\u6210\u5728\/usr\/local\/lib\/\u76ee\u5f55\u4e0b\u53ea\u6709libpython2.7.a\u800c\u6ca1\u6709libpython2.7.so\uff0c\u8fd9\u4e2a\u65f6\u5019\u9700\u8981\u7ed9makefile\u52a0\u4e00\u4e2a\u53c2\u6570:<br \/>\nC_FLAGS += -export-dynamic\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t\u6216\u8005\u91cd\u65b0\u4f7f\u7528.\/configure &#8211;enable-shared\u7f16\u8bd1Python.\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t&nbsp;\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t3.C\/C++\u591a\u7ebf\u7a0b\u8c03\u7528Python\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\tPython\u4e2d\u6709\u4e00\u4e2aGIL\uff0c\u5bfc\u81f4Python\u7ebf\u7a0b\u6548\u7387\u5f88\u4f4e\uff0c\u6b64\u5916\u82e5\u5728C\/C++\u4e2d\u521b\u5efa\u7ebf\u7a0b\u6765\u8c03\u7528Python\u89e3\u91ca\u5668\uff0c\u4f1a\u9020\u6210\u6bb5\u9519\u8bef\u3002\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t\u89e3\u51b3\u65b9\u5f0f\uff1a\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t\/\/\u4e3b\u7ebf\u7a0b\u4e2d\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\tPy_Initialize();\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\tPyEval_InitThreads();<br \/>\nPyEval_ReleaseLock();&nbsp;&nbsp; \/\/\u542f\u52a8\u5b50\u7ebf\u7a0b\u524d\u6267\u884c\uff0c\u4e3a\u4e86\u91ca\u653ePyEval_InitThreads\u83b7\u5f97\u7684\u5168\u5c40\u9501\uff0c\u5426\u5219\u5b50\u7ebf\u7a0b\u53ef\u80fd\u65e0\u6cd5\u83b7\u53d6\u5230\u5168\u5c40\u9501\u3002\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t&nbsp;\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t\/\/\u5b50\u7ebf\u7a0b\u4e2d\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\tPyGILState_STATE state = PyGILState_Ensure();\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t&#8230;..&nbsp;&nbsp;&nbsp; \/\/\u8c03\u7528Python\u4ee3\u7801\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\tPyGILState_Release(state);\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t&nbsp;\n\t\t\t\t<\/p>\n<p>\n\t\t\t\t\t\/\/\u4e3b\u7ebf\u7a0b\u4e2d\n\t\t\t\t<\/p>\n<p>\/\/\u4fdd\u8bc1\u5b50\u7ebf\u7a0b\u8c03\u7528\u90fd\u7ed3\u675f\u540e<br \/>\nPyGILState_Ensure();<br \/>\nPy_Finalize();<br \/>\n\/\/\u4e4b\u540e\u4e0d\u80fd\u518d\u8c03\u7528\u4efb\u4f55Python\u7684API<\/p>\n<p>\n\t\t\t\t\t&nbsp;\n\t\t\t\t<\/p>\n<\/td>\n<\/tr>\n","protected":false},"excerpt":{"rendered":"<p>\n\tto solve the problems such as under Ubuntu:\n<\/p>\n<p>\n\t&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;\n<\/p>\n<p>\n\tPython\/dynload_shlib.c:94: undefined reference to `dlsym&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[334],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=161\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"to solve the problems such as under Ubuntu:    ---------------------------------------------------------------------------------------    Python\/dynload_shlib.c:94: undefined reference to `dlsym...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=161\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-01T08:26:18+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"zinan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=161#webpage\",\"url\":\"http:\/\/weizn.net\/?p=161\",\"name\":\"C\/C++\\u8c03\\u7528Python\\u9519\\u8bef\\u6c47\\u603b - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"datePublished\":\"2016-02-01T08:26:18+00:00\",\"dateModified\":\"2016-02-01T08:26:18+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=161#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=161\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=161#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C\/C++\\u8c03\\u7528Python\\u9519\\u8bef\\u6c47\\u603b\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=161#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=161#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"C\/C++\\u8c03\\u7528Python\\u9519\\u8bef\\u6c47\\u603b\",\"datePublished\":\"2016-02-01T08:26:18+00:00\",\"dateModified\":\"2016-02-01T08:26:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=161#webpage\"},\"wordCount\":167,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"articleSection\":[\"Python\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=161#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b - Wayne&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/weizn.net\/?p=161","og_locale":"zh_CN","og_type":"article","og_title":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b - Wayne&#039;s Blog","og_description":"to solve the problems such as under Ubuntu:    ---------------------------------------------------------------------------------------    Python\/dynload_shlib.c:94: undefined reference to `dlsym...","og_url":"http:\/\/weizn.net\/?p=161","og_site_name":"Wayne&#039;s Blog","article_published_time":"2016-02-01T08:26:18+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=161#webpage","url":"http:\/\/weizn.net\/?p=161","name":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"datePublished":"2016-02-01T08:26:18+00:00","dateModified":"2016-02-01T08:26:18+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=161#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=161"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=161#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=161#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=161#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"C\/C++\u8c03\u7528Python\u9519\u8bef\u6c47\u603b","datePublished":"2016-02-01T08:26:18+00:00","dateModified":"2016-02-01T08:26:18+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=161#webpage"},"wordCount":167,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"articleSection":["Python"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=161#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}