I am building a C++ project with dependency on MUMPS (sparse linear solver) but during compilation I get the following error:
[build] /usr/bin/ld: /home/Thesis_project/installation/MUMPS_5.6.0/lib/libdmumps.a(dmumps_f77.o): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
The code which I use MUMPS:
# pragma once
#include <mpi.h>
#include <dmumps_c.h>
void solveLinearSystemMUMPS(double* matrix_values, int* row_indices, int* col_indices,
double* rhs_vector, double* solution, int matrix_size,
int num_nonzeros) {
// Initialize MPI
int argc = 0;
char** argv = NULL;
MPI_Init(&argc, &argv);
// Define MUMPS data structures
DMUMPS_STRUC_C mumps_data;
int INFO = 0;
// Initialize MUMPS structure
//dmumps_c(&mumps_data);
mumps_data.job = -1;
mumps_data.par = 1; // Set parallel flag (par=1)
// Set matrix size and nonzero structure
mumps_data.n = matrix_size;
mumps_data.nz = num_nonzeros;
mumps_data.irn = row_indices;
mumps_data.jcn = col_indices;
mumps_data.a = matrix_values;
// Set RHS vector
mumps_data.rhs = rhs_vector;
// Perform analysis
mumps_data.job = 1;
dmumps_c(&mumps_data);
// Perform factorization
mumps_data.job = 2;
dmumps_c(&mumps_data);
// Solve linear system
mumps_data.job = 3;
dmumps_c(&mumps_data);
// Access solution vector
double* sol = mumps_data.a;
for (int i = 0; i < matrix_size; ++i) {
solution[i] = sol[i];
}
// Finalize MUMPS
mumps_data.job = -2;
dmumps_c(&mumps_data);
// Finalize MPI
MPI_Finalize();
}
What have I tried so far:
Compile with gcc11 and clang14. Problem: there is no difference in the error.
Build MUMPS using -no-pie (following the compiler instructions). Problem: MUMPS is not built correctly (only part of the library's headers are installed).
Build my project using -no-pie. Problem: I get several undefined references in the MUMPS source file "dmumps_f77.F".
I was experimenting with the code to see which line gives me usch error, and it seems to be when I call "dmumps_c". For instance:
dmumps_c(&mumps_data)