• Uncategorized

About c : include-–-build-fails-after-switching-from-to

Question Detail

A commit in the C implementation of the Nokogumbo gem is causing the build to fail on Gentoo Linux, however, the modification is minor and shouldn’t cause any trouble. Unfortunately, I know next to zilch about C.

Here’s the commit:

https://github.com/rubys/nokogumbo/commit/8b4446847dea5c614759684ebcae4c580c47f4ad

It simply replaces the <> with "":

-#include <gumbo.h>
-#include <error.h>
-#include <parser.h>
+#include "gumbo.h"
+#include "error.h"
+#include "parser.h"

According to the GCC docs this shouldn’t cause any trouble since it falls back to the previous behaviour:

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option.

Unfortunately, while it compiles just fine with <>, the build fails with "":

compiling nokogumbo.c
nokogumbo.c:24:20: fatal error: parser.h: No such file or directory
#include "parser.h"

I’m wondering to what degree the way <> and "" behaves depends on the toolchain, environment and other settings.

Thanks a lot for your hints!

Question Answer

Re-installing “gumbo” on the Gentoo box has fixed the problem. Apparently, a local installation mess has produced this weird behaviour.

I checked your git repository and I noticed that you compile code with --std=c99. I think this may cause the problem, Because I found this in C99 draft:

The named source file is searched for in an implementation-defined
manner .If this search is not supported, or if the search fails, the
directive is reprocessed as if it read

#include <header>

So it means process is first implementation defined, and if not supported it uses #include<> mode. But this means if it defines that #include"" searches current directory, it will stop searching like #include<>.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.