c-blosc icon indicating copy to clipboard operation
c-blosc copied to clipboard

Help compiling example

Open nhz2 opened this issue 1 year ago • 3 comments

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 [email protected]: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 avatar Jun 25 '24 14:06 nhz2

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!

nhz2 avatar Jun 25 '24 16:06 nhz2

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)

kalvdans avatar Jul 01 '24 06:07 kalvdans

That doesn't work for me, but

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

does.

nhz2 avatar Jul 04 '24 02:07 nhz2