Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange disconnect between Eclipse CDT, included system headers, and the underlying C build
    primarykey
    data
    text
    <p>I'm having a strange problem with include files and an apparent disconnect between Eclipse's build process and its error reporting. I'll give detailed steps to reproducing this problem, so we can narrow the causes down as quickly as possible.</p> <p>Eclipse 3.7.1 (Indigo SR1) for C/C++ Linux Developers, Ubuntu 10.10 64-bits</p> <p>It all started when I imported an existing project that "makes" just fine on its own: I thought Eclipse would help considerably in navigating the files and figuring out what does what. However, some of the <code>#include</code>d system headers seemed not to be having the correct effect in Eclipse's view. This was very puzzling, and in the course of investigating this, I managed to recreate the problem in a tiny sand box.</p> <p>Step one: Create a new C project (<code>File: New: C Project</code>) using the <code>Hello World ANSI C Project</code> sample. The parameters are <code>Executable: Hello World ANSI C Project/Linux GCC</code>, the remaining <code>Empty</code> projects set to <code>Linux GCC</code>, and <code>GNU Autotools</code> set to <code>Hello World ANSI C Autotools Project</code>. Call it "hello". Be sure to generate the makefile automatically (Advanced Settings, I believe it is the default).</p> <p>Step two: Adjust the include path. Using <code>Project: Properties: C/C++ General: Paths and Symbols: Includes: GNU C</code>, set the search path to <code>/usr/local/include</code>, <code>/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include</code>, <code>/usr/include</code>. The second path depends on the exact version of gcc you have installed. This doesn't matter too much, as long as the build path includes at least <code>/usr/include</code>.</p> <p>Now if you open <code>hello.c</code>, it looks very simple, and Eclipse is quite happy except for <code>return EXIT_SUCCESS;</code>, which cannot resolve <code>EXIT_SUCCESS</code>. Replace <code>EXIT_SUCCESS</code> with a zero (<code>0</code>) and Eclipse gives the all-clear. Select <code>Project: Build Project</code> to generate the executable.</p> <p>Open a command-line window and drill down to your Eclipse workspace folder's <code>hello/Debug</code> subfolder. Once there, you can run the executable with the line <code>./hello</code>.</p> <p>Now the fun begins. Modify <code>hello.c</code> to read in its latter part:</p> <pre><code>#include &lt;fcntl.h&gt; int main(void) { printf("Hello World!\n"); int zz = SPLICE_F_MOVE; printf("zz (SPLICE_F_MOVE) is '%d'\n", zz); printf("Bye World!\n"); return 0; } </code></pre> <p>You'll get an error on the <code>int zz...</code> line: <code>"Symbol 'SPLICE_F_MOVE' could not be resolved"</code>. If you Build the project, you'll get a similar error in the console view: <code>"error: 'SPLICE_F_MOVE' undeclared"</code>.</p> <p>Now if you change the preamble to:</p> <pre><code>#define _GNU_SOURCE #include &lt;fcntl.h&gt; </code></pre> <p>You <em>still</em> get the error on the <code>int zz</code> line (in the editor), but the project will Build correctly! You can confirm this by running the binary in the command-line window you opened earlier. This is really odd since examination of <code>/usr/include/fcntl.h</code> will show that it <code>#include</code>s <code>&lt;bits/fcntl.h&gt;</code>, and that latter header <code>#define</code>s <code>SPLICE_F_MOVE</code> (and a bunch of others) in a block guarded by <code>#ifdef __USE_GNU</code> (<code>__USE_GNU</code> gets <code>#define</code>d if <code>_GNU_SOURCE</code> is <code>#define</code>d). Why on Earth isn't our <code>#define _GNU_SOURCE</code> properly propagated in the workspace perspective?</p> <p>So this is my problem in a nutshell: why is it the editor (and all of Eclipse CDT) reports an error (apparently by refusing to process correctly an include), but that the underlying build succeeds?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload