Blosc / c-blosc

A blocking, shuffling and loss-less compression library that can be faster than `memcpy()`.
https://www.blosc.org
Other
983 stars 157 forks source link

Help compiling example #379

Closed nhz2 closed 2 months ago

nhz2 commented 3 months ago

Hello,

I am trying to run the example: "examples/simple.c" but I am having compiler errors.

I am new to using C libraries with gcc so I am probably missing something obvious.

Here are the commands I ran.

(base) nathan@p3070:~/github$ git clone git@github.com:Blosc/c-blosc.git
Cloning into 'c-blosc'...
remote: Enumerating objects: 9333, done.
remote: Counting objects: 100% (1586/1586), done.
remote: Compressing objects: 100% (813/813), done.
remote: Total 9333 (delta 900), reused 1407 (delta 759), pack-reused 7747
Receiving objects: 100% (9333/9333), 8.44 MiB | 40.58 MiB/s, done.
Resolving deltas: 100% (6117/6117), done.

(base) nathan@p3070:~/github$ cd c-blosc/examples/

(base) nathan@p3070:~/github/c-blosc/examples$ gcc -O3 -msse2 simple.c -I../blosc -o simple -L../build/blosc
/usr/bin/ld: /tmp/ccyHg8k8.o: in function `main':
simple.c:(.text.startup+0x6a): undefined reference to `blosc_init'
/usr/bin/ld: simple.c:(.text.startup+0x9a): undefined reference to `blosc_compress'
/usr/bin/ld: simple.c:(.text.startup+0xfc): undefined reference to `blosc_decompress'
/usr/bin/ld: simple.c:(.text.startup+0x114): undefined reference to `blosc_destroy'
collect2: error: ld returned 1 exit status

I am trying to run the command in https://github.com/Blosc/c-blosc/blob/4f8541c8885bcba7d141ac1a270a9b5a6afe97d3/examples/simple.c#L12-L14

Is there a step I missed?

nhz2 commented 3 months ago

With help from @mkitti I figured out how to compile the example.

  1. Download the repository
  2. Follow instructions at https://github.com/Blosc/c-blosc?tab=readme-ov-file#compiling-the-blosc-library
  3. Run $ cd ../examples
  4. Run $ gcc -O3 -msse2 simple.c -I../blosc -o simple -Wl,-rpath=../build/blosc -L../build/blosc -lblosc Note the added -lblosc and -Wl,-rpath=../build/blosc compared to the instructions in "simple.c"

After these steps I get the expected output:

$ ./simple
Blosc version info: 1.21.7.dev ($Date:: 2024-06-24 #$)
Compression: 4000000 -> 36321 (110.1x)
Decompression successful!
Successful roundtrip!
kalvdans commented 3 months ago

A simpler variant, not using shared libraries, is

$ gcc simple.c -I../blosc -o simple ../build/libblosc.a

I also removed the unnecessary optimization flags in this example.

(The -Wl,rpath variant will pick up the system-wide installed libblosc.so for me)

nhz2 commented 3 months ago

That doesn't work for me, but

$ gcc simple.c -I../blosc -o simple ../build/blosc/libblosc.a

does.