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)