3

I am on Arch Linux. I have tried gcc and cc.

I have quite a strange problem. I have a file included from /usr/include (installed from an Arch package) in a C program like so.

// prog.c
#include <foobar/foobar.h>

When I change it, nothing happens. Let me explain. It includes some C code.

// foobar/foobar.h
int baz = 1, qux = 2;

Recently, it has been updated.

// foobar/foobar.h
int baz = 1, qux = 2, norf = 3;

My test program looks something like what follows.

// prog.c
#include <foobar/foobar.h>
printf ("%d %d %d\n", baz, qux, norf);

output:

error: ‘norf’ undeclared (first use in this function)

I can duplicate the file in the same directory, name it foobar2.h, and then include that file instead and it outputs:

1 2 3

So the path is not incorrect. I can make a link to the folder, name it foobar2, and include foobar2/foobar.h and it outputs:

1 2 3

So the file is not incorrect.

To confirm that it is not registering changes, I can destroy the foobar folder entirely and try to print just the 2 variables that were originally inside the header. This outputs:

1 2

Clearly something is not updating. The same behaviour is displayed when I try updating the file with enums, functions, or new values for existing items in the file, and include them as the only lines in the file. None of the changes register. The same activity is displayed with gcc and cc. This has been going on a few months now and it still has not resolved itself.

13
  • If you believe that this has something to do with the library itself, I have some details here: pastebin.com/Mhj4jfFr
    – rbong
    Nov 24, 2014 at 1:18
  • 1
    I would try including this file using quotation marks. Maybe your system caches library includes for faster compilation.
    – Anonymous
    Nov 24, 2014 at 1:18
  • 1
    You need to build each time before you link? Nov 24, 2014 at 1:20
  • 1
    Ok, I'd also try to disable precompiled header usage during compilation, can you do that?
    – Anonymous
    Nov 24, 2014 at 1:38
  • 1
    If you're using gcc, use gcc -H to print the list of header files being included. You will find that the foobar/foobar.h that is actually being included is not the one you edited or thought was being included. Nov 24, 2014 at 3:19

2 Answers 2

2

When a file does not seem to be updating, it is a good idea to check other places on your system where your compilers search for libraries for identically named folders. In this case, it was in /usr/local/include, where I had a version that I compiled and forgot about entirely.

2
  • Newbie here -- is there any order of precedence with the system default search paths? Was the older version in a folder that was getting searched first?
    – Andy J
    Nov 24, 2014 at 2:41
  • 1
    According to the gcc manual section 3.19, include paths specified with -B, -I, -L, and other command line options take precedence over include paths specified using environment variables, which take precedence over include paths set by gcc configuration. In An Introduction to GCC section 3.1, it says that the order of searching for headers is /usr/local/include then /usr/include, and the order for libraries is /usr/local/lib then /usr/lib.
    – rbong
    Nov 24, 2014 at 16:10
0

This can be mainly due to the include directory path mismatch. Check out the environment variable that can affect the behavior like C_INCLUDE_PATH , CPATH. Another option would be to check with gcc -I/src/directory foobar.h while compilation that can lead you closer to the problem or use #include "foobar.h" in the code.

In case if there are multiple copies of the program in your system, it is possible that completely different file is used for compilation and execution which can also lead to changes not getting reflected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.