这是GNU Scientific Library 2.4版的测试。这是文档中的示例9.9(2017年6月14日):
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_permutation.h>
int
main (void)
{
const size_t N = 10;
const gsl_rng_type * T;
gsl_rng * r;
gsl_permutation * p = gsl_permutation_alloc (N);
gsl_permutation * q = gsl_permutation_alloc (N);
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
printf ("initial permutation:");
gsl_permutation_init (p);
gsl_permutation_fprintf (stdout, p, " %u");
printf ("\n");
printf (" random permutation:");
gsl_ran_shuffle (r, p->data, N, sizeof(size_t));
gsl_permutation_fprintf (stdout, p, " %u");
printf ("\n");
printf ("inverse permutation:");
gsl_permutation_inverse (q, p);
gsl_permutation_fprintf (stdout, q, " %u");
printf ("\n");
gsl_permutation_free (p);
gsl_permutation_free (q);
gsl_rng_free (r);
return 0;
}
构建日志:
-------------- Build: Debug in example (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -I../../../../usr/include/gsl -c /home/lucas/Desktop/example/main.cpp -o obj/Debug/home/lucas/Desktop/example/main.o
g++ -o bin/Debug/example obj/Debug/home/lucas/Desktop/example/main.o ../../../../usr/include/gsl/gsl_permutation.h ../../../../usr/include/gsl/gsl_randist.h ../../../../usr/include/gsl/gsl_rng.h
obj/Debug/home/lucas/Desktop/example/main.o: In function `main':
/home/lucas/Desktop/example/main.cpp:13: undefined reference to `gsl_permutation_alloc'
/home/lucas/Desktop/example/main.cpp:14: undefined reference to `gsl_permutation_alloc'
/home/lucas/Desktop/example/main.cpp:16: undefined reference to `gsl_rng_env_setup'
/home/lucas/Desktop/example/main.cpp:17: undefined reference to `gsl_rng_default'
/home/lucas/Desktop/example/main.cpp:18: undefined reference to `gsl_rng_alloc'
/home/lucas/Desktop/example/main.cpp:21: undefined reference to `gsl_permutation_init'
/home/lucas/Desktop/example/main.cpp:22: undefined reference to `gsl_permutation_fprintf'
/home/lucas/Desktop/example/main.cpp:26: undefined reference to `gsl_ran_shuffle'
/home/lucas/Desktop/example/main.cpp:27: undefined reference to `gsl_permutation_fprintf'
/home/lucas/Desktop/example/main.cpp:31: undefined reference to `gsl_permutation_inverse'
/home/lucas/Desktop/example/main.cpp:32: undefined reference to `gsl_permutation_fprintf'
/home/lucas/Desktop/example/main.cpp:35: undefined reference to `gsl_permutation_free'
/home/lucas/Desktop/example/main.cpp:36: undefined reference to `gsl_permutation_free'
/home/lucas/Desktop/example/main.cpp:37: undefined reference to `gsl_rng_free'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
15 error(s), 0 warning(s) (0 minute(s), 0 second(s))
有没有办法追踪此错误?这是链接库,搜索目录,编译器配置,项目标题的问题吗?我正在使用Code :: Blocks 16.01