0

gcc apparently cannot find the include file in the specified place. It does work if I use

#include "fullpath/stdint.h"

I can't get it to work using

#include < stdint.h >

I tried compiling a package using gcc on Mac OS. No success. I nailed the problem to the include file stdint.h.

I wrote the following test code:

// 1 #include <stdint.h>
// 2 #include "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdint.h"
// 3 typedef unsigned long long uint64_t;

#include <stdio.h>
int main()
{
uint64_t x ;

x = 10 ;

printf("x = %lld\n",x);
}

If I uncomment the first commented out line, labeled as "1", it won't work.

I tried compiling with:

> gcc -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ test.c
test.c:8:9: error: expected ';' after expression
uint64_t x ;
        ^
        ;
test.c:8:1: error: use of undeclared identifier 'uint64_t'
uint64_t x ;
^

I also tried setting the GCC_INCLUDE_DIR and C_INCLUDE_DIR environment variables to no avail:

> env | grep INCLUDE C_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/
GCC_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/
> gcc test.c
test.c:8:9: error: expected ';' after expression
uint64_t x ;
        ^
        ;
test.c:8:1: error: use of undeclared identifier 'uint64_t'
uint64_t x ;

Now, if I use either the 2 or 3 commented out lines the program compiles and runs just fine.

So it must be some problem finding the stdint.h file. Is there something wrong with my use of -I? I re-read this line a thousand times, added a space after -I, took the space out, nothing seems to help. The same happens with the environment variables.

gcc and Mac OS versions:

> uname -a
Darwin Antonios-MacBook-Pro.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

> gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Adding the include `#include ` it works and gives the result `x = 10` on macOS Mojave. Any special configuration you are using? – Stephan Schlecht Jun 25 '19 at 18:35
  • Thanks Stephan, well, I use yadr/zsh, but in principle using gcc - I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ should overcome anything funny yadr/zsh does. Also, I have tried compiling under csh as well as bash, it is always the same :-( – Antonio Kanaan Jun 28 '19 at 14:51
  • Perhaps the following link is useful? https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave – Stephan Schlecht Jun 30 '19 at 12:06
  • YESSS! really useful. Thanks very much. – Antonio Kanaan Jul 03 '19 at 14:00

0 Answers0