Help compiling example
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?
With help from @mkitti I figured out how to compile the example.
- Download the repository
- Follow instructions at https://github.com/Blosc/c-blosc?tab=readme-ov-file#compiling-the-blosc-library
- Run
$ cd ../examples - Run
$ gcc -O3 -msse2 simple.c -I../blosc -o simple -Wl,-rpath=../build/blosc -L../build/blosc -lbloscNote the added-lbloscand-Wl,-rpath=../build/blosccompared 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!
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)
That doesn't work for me, but
$ gcc simple.c -I../blosc -o simple ../build/blosc/libblosc.a
does.