jllodra / ncdump-json

Modified ncdump to output data in json format
85 stars 28 forks source link

Errors compiling on OSX (using Apple's LLVM clang) #5

Closed NamrataM closed 8 years ago

NamrataM commented 8 years ago

In the instructions it said that on $make warning would come up. I got 4 warnings and 7 errors. Here's what I got: Scanning dependencies of target ncdump-json [ 16%] Building C object CMakeFiles/ncdump-json.dir/src/dumplib.c.o In file included from /Users/malarout/Desktop/ncdump-json/src/dumplib.c:24: /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: error: expected parameter declarator extern size_t strlcat(char dst, const char src, size_t siz); ^ /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                         ^

/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'

define _USE_FORTIFY_LEVEL 2

                           ^

In file included from /Users/malarout/Desktop/ncdump-json/src/dumplib.c:24: /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: error: expected ')' /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                         ^

/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'

define _USE_FORTIFY_LEVEL 2

                           ^

/Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: note: to match this '(' /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:53: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                ^

In file included from /Users/malarout/Desktop/ncdump-json/src/dumplib.c:24: /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] extern size_t strlcat(char _dst, const char *src, size_t siz); ^ /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:31: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                          ^

In file included from /Users/malarout/Desktop/ncdump-json/src/dumplib.c:24: /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: error: conflicting types for 'builtin_strlcat_chk' /usr/include/secure/_string.h:111:3: note: expanded from macro 'strlcat' builtin_strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: note: '_builtinstrlcat_chk' is a builtin with type 'unsigned long (char , const char , unsigned long, unsigned long)' /usr/include/secure/_string.h:111:3: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: error: expected parameter declarator strlcat(char dst, const char src, size_t siz) { ^ /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                         ^

/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'

define _USE_FORTIFY_LEVEL 2

                           ^

/Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: error: expected ')' /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                         ^

/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL'

define _USE_FORTIFY_LEVEL 2

                           ^

/Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: note: to match this '(' /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:53: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                                                ^

/Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] strlcat(char dst, const char src, size_t siz) { ^ /usr/include/secure/_string.h:111:44: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /usr/include/secure/_common.h:39:31: note: expanded from macro '__darwin_obsz'

define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > ...

                          ^

/Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: error: conflicting types for 'builtin_strlcat_chk' /usr/include/secure/_string.h:111:3: note: expanded from macro 'strlcat' builtin_strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /Users/malarout/Desktop/ncdump-json/src/dumplib.h:53:15: note: '_builtinstrlcat_chk' is a builtin with type 'unsigned long (char , const char , unsigned long, unsigned long)' extern size_t strlcat(char dst, const char src, size_t siz); ^ /usr/include/secure/_string.h:111:3: note: expanded from macro 'strlcat' builtin___strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /Users/malarout/Desktop/ncdump-json/src/dumplib.c:165:1: error: definition of builtin function 'builtin___strlcat_chk' strlcat(char dst, const char src, size_t siz) { ^ /usr/include/secure/_string.h:111:3: note: expanded from macro 'strlcat' builtin_strlcat_chk (dest, src, len, darwin_obsz (dest)) ^ /Users/malarout/Desktop/ncdump-json/src/dumplib.c:820:40: warning: data argument not used by format string [-Wformat-extra-args] snprintf(sout, PRIM_LEN, "null", NCDL_NANF);


/Users/malarout/Desktop/ncdump-json/src/dumplib.c:807:19: note: expanded from macro
      'NCDL_NANF'
#define NCDL_NANF "NaNf"
                  ^
/usr/include/secure/_stdio.h:57:62: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
                                                             ^
/Users/malarout/Desktop/ncdump-json/src/dumplib.c:998:28: warning: format string is not a
      string literal (potentially insecure) [-Wformat-security]
  snprintf(sp, prelen + 1, prefix);
                           ^~~~~~
/usr/include/secure/_stdio.h:57:62: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
                                                             ^
4 warnings and 7 errors generated.
make[2]: *_\* [CMakeFiles/ncdump-json.dir/src/dumplib.c.o] Error 1
make[1]: **\* [CMakeFiles/ncdump-json.dir/all] Error 2
make: **\* [all] Error 2

Can someone please help me out with this?
jllodra commented 8 years ago

Hi @NamrataM,

you're welcome, what is your osx version and compiler name+version?

Last time I built it on mac, I used gcc-4.9 and edited CMakeLists.txt adding the line: set(CMAKE_C_COMPILER "gcc-4.9")

Best

NamrataM commented 8 years ago

Hi @jllodra, Thanks for the quick response. I am using OS X Yosemite version 10.10.3. This is my compiler information: $ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.3.0 Thread model: posix

Thanks

jllodra commented 8 years ago

Hi @NamrataM,

Ok, thanks for the feedback, now let me tell you the steps to follow:

1) First of all we need to install the GNU GCC compiler. To do this I recommend installing Homebrew: 1.1) Head to http://brew.sh and do the install procedure (it's only copy/pasting a line, don't do it as root). Installing Homebrew is very straightforward, here's more info: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Installation.md#installation 2) Now we have Homebrew installed, on the terminal run, as a regular user: 2.1) brew install gcc (you need to have xcode installed with command-line tools xcode-select --install) 2.2) run gcc-5 -v (Homebrew will install the GNU GCC as gcc-5, currently on version 5).

Output:

josep@MacBook-Pro:~/Dropbox/Code/ncdump-json [git:master]
08-09-15 22:28:33> gcc-5 -v
Using built-in specs.
COLLECT_GCC=gcc-5
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/5.2.0/libexec/gcc/x86_64-apple-darwin14.4.0/5.2.0/lto-wrapper
Target: x86_64-apple-darwin14.4.0
Configured with: ../configure --build=x86_64-apple-darwin14.4.0 --prefix=/usr/local/Cellar/gcc/5.2.0 --libdir=/usr/local/Cellar/gcc/5.2.0/lib/gcc/5 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-5 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 5.2.0' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 5.2.0 (Homebrew gcc 5.2.0)

3) Install the netcdf library if you didn't before, let's do this with Homebrew too: 3.1) brew install homebrew/science/netcdf

4) We can also install cmake with Homebrew if it's not yet installed: 4.1) brew install cmake 4.2) brew install pkg-config

5) Now we need to modify the CMakeLists.txt file: 5.1) Edit the file and uncomment line 12: https://github.com/jllodra/ncdump-json/blob/master/CMakeLists.txt#L12 5.2) Change gcc-4.9 to gcc-5 (or whatever the version Homebrew installed!)

6) Delete the files CMakeFiles, cmake_install.cmake, Makefile and CMakeCache.txt if exist. This is just to be on the safe-side, but do it. Do NOT delete CMakeLists.txt by mistake.

7) Run cmake . again, et voilà :smile:

8) Try ndump-json.

josep@MacBook-Pro:~/Dropbox/Code/ncdump-json [git:master]
08-09-15 22:36:53> ./ncdump-json
./ncdump-json [-c|-h] [-v ...] [[-b|-f] [c|f]] [-l len] [-n name] [-p n[,n]] [-k] [-x] [-j] [-s] [-t] [-w] file
  [-c]             Coordinate variable data and header information
  [-h]             Header information only, no data
  [-v var1[,...]]  Data for variable(s) <var1>,... only
  [-b [c|f]]       Brief annotations for C or Fortran indices in data
  [-f [c|f]]       Full annotations for C or Fortran indices in data
  [-l len]         Line length maximum in data section (default 80)
  [-n name]        Name for netCDF (default derived from file name)
  [-p n[,n]]       Display floating-point values with less precision
  [-k]             Output kind of netCDF file
  [-x]             Output XML (NcML) instead of CDL
  [-j]             Output JSON (Javascript object notation) instead of CDL
  [-s]             Output special (virtual) attributes
  [-t]             Output time data as date-time strings
  [-w]             Without client-side caching of variables for DAP URLs
  file             Name of netCDF file
netcdf library version 4.3.3.1 of Apr  9 2015 00:56:35 $

Please, report if this is working for you so it could help future users.

Best

NamrataM commented 8 years ago

Hi @jllodra , Thanks a lot for your help. It worked perfectly. Cheers, Namrata

jllodra commented 8 years ago

Wonderful!

Closing the issue now...

NamrataM commented 8 years ago

Hi @jllodra , I executed the same command as the example, this is my output: ncdump-json malarout$ ncdump-json tests/socib-buoy.nc -h -j ncdump-json [-c|-h] [-v ...] [[-b|-f] [c|f]] [-l len] [-n name] [-p n[,n]] [-k] [-x] [-j] [-s] [-t] [-w] file [-c] Coordinate variable data and header information [-h] Header information only, no data [-v var1[,...]] Data for variable(s) ,... only [-b [c|f]] Brief annotations for C or Fortran indices in data [-f [c|f]] Full annotations for C or Fortran indices in data [-l len] Line length maximum in data section (default 80) [-n name] Name for netCDF (default derived from file name) [-p n[,n]] Display floating-point values with less precision [-k] Output kind of netCDF file [-x] Output XML (NcML) instead of CDL [-j] Output JSON (Javascript object notation) instead of CDL [-s] Output special (virtual) attributes [-t] Output time data as date-time strings [-w] Without client-side caching of variables for DAP URLs file Name of netCDF file netcdf library version 4.3.3.1 of Sep 3 2015 12:19:38 $

Is this normal?

jllodra commented 8 years ago

Ops, flags first please:

./ncdump-json -h -j tests/socib-buoy.nc

It's not even supposed to work with flags at the end, I should update the README.md.

NamrataM commented 8 years ago

That's awesome. It worked. Thanks!

jllodra commented 8 years ago

You're welcome.