{"id":925,"date":"2023-09-26T21:16:33","date_gmt":"2023-09-27T04:16:33","guid":{"rendered":"https:\/\/porkrind.org\/missives\/?p=925"},"modified":"2024-08-18T12:42:32","modified_gmt":"2024-08-18T19:42:32","slug":"bizarre-error-while-compiling-a-rust-program","status":"publish","type":"post","link":"https:\/\/porkrind.org\/missives\/bizarre-error-while-compiling-a-rust-program\/","title":{"rendered":"Bizarre Error while compiling a Rust program"},"content":{"rendered":"<p>I was trying to compile a third party Rust crate today on a Debian box and I was getting a weird error I&#8217;d never seen:<\/p>\n<pre><code>  = note: cc: fatal error: cannot read spec file '.\/specs': Is a directory\n          compilation terminated.\n<\/code><\/pre>\n<p>I&#8217;ve done a bunch of embedded C stuff in the past so I knew what a specs file was\u2014but why couldn&#8217;t gcc open its specs file? The first clue was that this particular crate had a directory at its top level called &#8220;specs&#8221;. I moved it away and the error went away. Ok. But <em>why<\/em> is gcc looking for a specs file in my cwd??<\/p>\n<p>Rust printed out the linker command it was using to invoke gcc with so I could look through that but there was nothing referencing a spec file there.<\/p>\n<p>I figured it might be something set up incorrectly on my local machine but there&#8217;s practically no documentation about where gcc looks for specs files. I ended up downloading the gcc source (thank heavens for <code>apt source<\/code>!) and grepping it for &#8220;cannot read spec file&#8221;, which lead me to the <a href=\"https:\/\/github.com\/gcc-mirror\/gcc\/blob\/fc41263061808a8539ba7ee1f607920a54e7b265\/gcc\/gcc.cc#L2303\"><code>load_specs()<\/code> function in <code>gcc\/gcc.c<\/code><\/a>. Ok. So I poked around that file, following the thread of function calls around and just sort of looking for anything. I eventually noticed <a href=\"https:\/\/github.com\/gcc-mirror\/gcc\/blob\/fc41263061808a8539ba7ee1f607920a54e7b265\/gcc\/gcc.cc#L1578\"><code>startfile_prefixes<\/code><\/a> which appeared to be where they searched for specs. Searching around the file led me to <a href=\"https:\/\/github.com\/gcc-mirror\/gcc\/blob\/fc41263061808a8539ba7ee1f607920a54e7b265\/gcc\/gcc.cc#L4900\">a section where it looped over <code>LIBRARY_PATH<\/code> and added each component to <code>startfile_prefixes<\/code><\/a>. This stuck out to me because I had <code>LIBRARY_PATH<\/code> set in my env.<\/p>\n<p>I looked at it more closely and noticed it was<\/p>\n<pre><code>LIBRARY_PATH=\/usr\/local\/lib:\n<\/code><\/pre>\n<p>Hmm. Why does it have a stray <code>:<\/code> on the end? Maybe that&#8217;s it. I tested it with:<\/p>\n<pre><code>LIBRARY_PATH=\/usr\/local\/lib cargo build\n<\/code><\/pre>\n<p>And everything built just fine! Yay!<\/p>\n<p>So it was my fault after all\u2026 Sigh. I checked my <code>.bashrc<\/code> and found a bug in one of my path construction functions which was putting the extra <code>:<\/code> on the end. Then I spent some time relearning a bunch of excruciating shell details and getting everything fixed. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was trying to compile a third party Rust crate today on a Debian box and I was getting a weird error I&#8217;d never seen: = note: cc: fatal error: cannot read spec file &#8216;.\/specs&#8217;: Is a directory compilation terminated. I&#8217;ve done a bunch of embedded C stuff in the past so I knew what &hellip; <a href=\"https:\/\/porkrind.org\/missives\/bizarre-error-while-compiling-a-rust-program\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bizarre Error while compiling a Rust program<\/span><\/a><\/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":[1],"tags":[],"class_list":["post-925","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/comments?post=925"}],"version-history":[{"count":10,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/925\/revisions"}],"predecessor-version":[{"id":950,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/posts\/925\/revisions\/950"}],"wp:attachment":[{"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/media?parent=925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/categories?post=925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/porkrind.org\/missives\/wp-json\/wp\/v2\/tags?post=925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}