LLNL / zfp

Compressed numerical arrays that support high-speed random access
http://zfp.llnl.gov
BSD 3-Clause "New" or "Revised" License
754 stars 152 forks source link

How to run zfp as a c code with gcc #206

Closed mearcla closed 9 months ago

mearcla commented 1 year ago

Hello, I am trying to use zfp on windows to compressed my dataset so I started from the simple.c file that compressed 3D array, I am trying to run this code by using this command gcc -o a simple.c is that correct ?

I got on these errors:

Please can you help me how to use zfp on windows ? Where can I found these functions please?

simple.c: In function 'compress':
simple.c:39:12: warning: implicit declaration of function 'stream_open'; did you mean 'zfp_stream_open'? [-Wimplicit-function-declaration]
   stream = stream_open(buffer, bufsize);
            ^~~~~~~~~~~
            zfp_stream_open
simple.c:39:10: warning: assignment to 'bitstream *' {aka 'struct bitstream *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
   stream = stream_open(buffer, bufsize);
          ^
simple.c:66:3: warning: implicit declaration of function 'stream_close'; did you mean 'zfp_stream_close'? [-Wimplicit-function-declaration]
   stream_close(stream);
   ^~~~~~~~~~~~
   zfp_stream_close
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x43): undefined reference to `zfp_field_3d'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x51): undefined reference to `zfp_stream_open'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x70): undefined reference to `zfp_stream_set_accuracy'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x80): undefined reference to `zfp_stream_maximum_size'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0xa4): undefined reference to `stream_open'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0xba): undefined reference to `zfp_stream_set_bit_stream'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0xc6): undefined reference to `zfp_stream_rewind'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x10c): undefined reference to `zfp_decompress'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x155): undefined reference to `zfp_compress'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x1c9): undefined reference to `zfp_field_free'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x1d5): undefined reference to `zfp_stream_close'
C:\Users\hp\AppData\Local\Temp\cceazl20.o:simple.c:(.text+0x1e1): undefined reference to `stream_close'
collect2.exe: error: ld returned 1 exit status
lindstro commented 1 year ago

You need to tell gcc where to find the zfp headers and library. Assuming you're in the examples directory and have already built the zfp library, add -I../include -L../lib -lzfp to the compile line. If you're using GNU make, then you could also build the examples just by typing make BUILD_EXAMPLES=1 in the top-level zfp directory.

mearcla commented 1 year ago

Thanks for your answer, I use this command \ZFP-master\examples>g++ -I../include -L../lib -lzfp simple.c -o a

And I got on this errors!


simple.c: In function 'int compress(double*, int, int, int, double, int)':
simple.c:47:12: error: 'stream_open' was not declared in this scope
   stream = stream_open(buffer, bufsize);
            ^~~~~~~~~~~
simple.c:47:12: note: suggested alternative: 'zfp_stream_open'
   stream = stream_open(buffer, bufsize);
            ^~~~~~~~~~~
            zfp_stream_open
simple.c:74:3: error: 'stream_close' was not declared in this scope
   stream_close(stream);
   ^~~~~~~~~~~~
simple.c:74:3: note: suggested alternative: 'zfp_stream_close'
   stream_close(stream);
   ^~~~~~~~~~~~
   zfp_stream_close
simple.c: In function 'int main(int, char**)':
simple.c:90:25: error: invalid conversion from 'void*' to 'double*' [-fpermissive]
   double* array = malloc(nx * ny * nz * sizeof(double));
                   ~~~
```~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lindstro commented 1 year ago

This is C, not C++ code. Try compiling with gcc instead of g++.

lindstro commented 1 year ago

They're all declared in include/zfp.h and defined in src/zfp.c (except stream_open() and stream_close(), which you'll find in include/zfp/bitstream.inl).

Did you try compiling with gcc (not g++)? Some linkers require that libraries appear at the end. Try gcc -I../include -L../lib simple.c -o a -lzfp.

lindstro commented 10 months ago

@mearcla Are you still having issues? If not, I'd like to go ahead and close this issue.

GarrettDMorrison commented 9 months ago

@mearcla I'm going to go ahead and close this issue for now. If you are still having problems feel free to reopen.