Я тестирую Научную библиотеку GNU (GSL), и я хочу создать с ней разреженную матрицу. Это мой код, который поступает непосредственно от https://www.gnu.org/software/gsl/manual/html_node/Sparse-Matrix-Examples.html:редкие матрицы с GSL - ошибка компиляции
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_spmatrix.h>
int
main()
{
gsl_spmatrix *A = gsl_spmatrix_alloc(5, 4); /* triplet format */
gsl_spmatrix *C;
size_t i, j;
/* build the sparse matrix */
gsl_spmatrix_set(A, 0, 2, 3.1);
gsl_spmatrix_set(A, 0, 3, 4.6);
gsl_spmatrix_set(A, 1, 0, 1.0);
gsl_spmatrix_set(A, 1, 2, 7.2);
gsl_spmatrix_set(A, 3, 0, 2.1);
gsl_spmatrix_set(A, 3, 1, 2.9);
gsl_spmatrix_set(A, 3, 3, 8.5);
gsl_spmatrix_set(A, 4, 0, 4.1);
printf("printing all matrix elements:\n");
for (i = 0; i < 5; ++i)
for (j = 0; j < 4; ++j)
printf("A(%zu,%zu) = %g\n", i, j,
gsl_spmatrix_get(A, i, j));
/* print out elements in triplet format */
printf("matrix in triplet format (i,j,Aij):\n");
for (i = 0; i < A->nz; ++i)
printf("(%zu, %zu, %.1f)\n", A->i[i], A->p[i], A->data[i]);
/* convert to compressed column format */
C = gsl_spmatrix_compcol(A);
printf("matrix in compressed column format:\n");
printf("i = [ ");
for (i = 0; i < C->nz; ++i)
printf("%zu, ", C->i[i]);
printf("]\n");
printf("p = [ ");
for (i = 0; i < C->size2 + 1; ++i)
printf("%zu, ", C->p[i]);
printf("]\n");
printf("d = [ ");
for (i = 0; i < C->nz; ++i)
printf("%g, ", C->data[i]);
printf("]\n");
gsl_spmatrix_free(A);
gsl_spmatrix_free(C);
return 0;
}
Я составил этот код, используя следующую команду:
gcc test1.c -o test -lgsl -lgslcblas -lm
Результат был:
/tmp/ccyBfp0p.o: In function `main':
test1.c:(.text+0x13): undefined reference to `gsl_spmatrix_alloc'
test1.c:(.text+0x40): undefined reference to `gsl_spmatrix_set'
test1.c:(.text+0x69): undefined reference to `gsl_spmatrix_set'
test1.c:(.text+0x87): undefined reference to `gsl_spmatrix_set'
test1.c:(.text+0xb0): undefined reference to `gsl_spmatrix_set'
test1.c:(.text+0xd9): undefined reference to `gsl_spmatrix_set'
/tmp/ccyBfp0p.o:test1.c:(.text+0x102): more undefined references to `gsl_spmatrix_set' follow
/tmp/ccyBfp0p.o: In function `main':
test1.c:(.text+0x189): undefined reference to `gsl_spmatrix_get'
test1.c:(.text+0x25d): undefined reference to `gsl_spmatrix_compcol'
test1.c:(.text+0x39b): undefined reference to `gsl_spmatrix_free'
test1.c:(.text+0x3a7): undefined reference to `gsl_spmatrix_free'
collect2: error: ld returned 1 exit status
Затем я попытался использовать Следующий код для составления:
gcc -I/usr/local/include/gsl -L/usr/local/lib -o test test1.c -lgsl -lgslcblas -lm
Это компилируется код без ошибок, но когда я попытался запустить его произошла следующая ошибка:
./test: error while loading shared libraries: libgsl.so.19: cannot open shared object file: No such file or directory
Но когда я делаю:
ls /usr/local/lib
Я могу видеть результат:
libemon.a libgslcblas.so libgsl.so python2.7
libgsl.a libgslcblas.so.0 libgsl.so.19 python3.4
libgslcblas.a libgslcblas.so.0.0.0 libgsl.so.19.1.0 site_ruby
libgslcblas.la libgsl.la pkgconfig
У меня проблема с установкой GSL. Но проблема в том, что все остальные вычисления работают нормально! Эта редкая матрица дает мне эту проблему.
Вы уверены, что ваша установленная версия GSL поддерживает разреженные массивы? Какую версию GSL вы используете? (используйте макросы 'GSL_VERSION',' GSL_MAJOR_VERSION' и 'GSL_MINOR_VERSION') – alfC