0

I am trying to work with libcsv here. The header file csv.h is in /usr/include directory, and the shared library file libcsv.so in /usr/lib64 (Fedora 35).

For now, I was able to make the gem file work using the shell command:

gcc -c -fPIC rcsv.c -o rcsv.o
gcc -shared -lcsv rcsv.o -o rcsv.so

I have to manually move the .so file to lib/rcsv/, which is quite inconvenient, and is not favourable for installing gems.

I would like to write the same in code in Ruby format inside extconf.rb. How should I go about this?

extconf.rb

require 'mkmf'

have_header("csv.h")
have_library('libcsv.so')

create_makefile('rcsv/rcsv')

rake log

(in /home/<username>/Desktop/rcsv)
mkdir -p tmp/x86_64-linux/rcsv/3.0.3
cd tmp/x86_64-linux/rcsv/3.0.3
/home/<username>/.asdf/installs/ruby/3.0.3/bin/ruby -I. -r.rake-compiler-siteconf.rb ../../../../ext/rcsv/extconf.rb
checking for csv.h... yes
checking for -llibcsv.so... no
creating Makefile
cd -
cd tmp/x86_64-linux/rcsv/3.0.3
/usr/bin/gmake
compiling ../../../../ext/rcsv/rcsv.c
linking shared-object rcsv/rcsv.so
cd -
mkdir -p tmp/x86_64-linux/stage/lib/rcsv
/usr/bin/gmake install target_prefix=
/usr/bin/install -c -m 0755 rcsv.so /home/<username>/Desktop/rcsv/lib/rcsv
cp tmp/x86_64-linux/rcsv/3.0.3/rcsv.so tmp/x86_64-linux/stage/lib/rcsv/rcsv.so
Loaded suite /home/<username>/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_test_loader
Started
/home/<username>/.asdf/installs/ruby/3.0.3/bin/ruby: symbol lookup error: /home/<username>/Desktop/rcsv/lib/rcsv/rcsv.so: undefined symbol: csv_init
rake aborted!
Command failed with status (127)

Tasks: TOP => default => test
(See full trace by running task with --trace)
Ashvith Shetty
  • 90
  • 2
  • 11

1 Answers1

0

The above code in extconf.rb was proper, but not the string value inside the have_library('libcsv.so'), which should have been 'csv' instead of 'libcsv.so'.

So, overall, the extconf.rb file should look like:

require 'mkmf'

have_header("csv.h")
have_library('csv')

create_makefile('rcsv/rcsv')
Ashvith Shetty
  • 90
  • 2
  • 11