How to compile & run Ruby c (/c++) extension with OpenMP (undefined symbol error)

33 views Asked by At

I'm trying to do a simple parfor loop in a Ruby c/c++ extension using openmp

#pragma omp parallel for
for (int j = 0; j < 100; j++) {
}

extconf.rb:

require 'mkmf'
extension_name = 'stridx'
$CFLAGS << " -Wall -fopenmp "
$CXXFLAGS << " -Wall -O1 -g -fopenmp"
have_library( 'stdc++', 'gomp' );
dir_config(extension_name)
create_makefile(extension_name)

The extension compiles fine, but when I run a script that uses it, I get the following error: undefined symbol: GOMP_parallel ruby: symbol lookup error: ... ext/stridx/stridx.so: undefined symbol: GOMP_parallel

Running the script with following LD_PRELOAD fixes the issue:

LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/12/libgomp.so ./test.rb

However, this seems like a hack and would complicate the redistribution of the gem. Is there a proper way to solve this?

0

There are 0 answers