c - GSL 和环境变量

标签 c environment-variables gsl

构建后:

$ gcc generator.c -lm  -lgsl -lgslcblas -lm

代码:

#include <stdio.h>
#include <gsl/gsl_rng.h>
gsl_rng * r;
/* global generator */
int main (void)
{
    const gsl_rng_type * T;
    gsl_rng_env_setup();
    T = gsl_rng_default;
    r = gsl_rng_alloc (T);
    printf ("generator type: %s\n", gsl_rng_name (r));
    printf ("seed = %lu\n", gsl_rng_default_seed);
    printf ("first value = %lu\n", gsl_rng_get (r));
    gsl_rng_free (r);
    return 0;
}

然后按照以下方式运行:

$ ./a.out

我得到:

generator type: mt19937
seed = 0
first value = 4293858116

如果我这样做:

$ GSL_RNG_SEED=1  GSL_RNG_TYPE="taus" ./a.out

我得到:

GSL_RNG_TYPE=taus
GSL_RNG_SEED=1
generator type: taus
seed = 1
first value = 802792108

但是做完之后:

$ GSL_RNG_SEED=1
$ GSL_RNG_TYPE="taus"
$ ./a.out

我得到与第一次相同的输出:

generator type: mt19937
seed = 0
first value = 4293858116

为什么可执行文件无法以最后一种方式获取环境变量值(GSL_RNG_SEED=1 和 GSL_RNG_TYPE="taus")?

最佳答案

您应该使用导出来设置环境变量。所以 导出 GSL_RNG_SEED=1 导出 GSL_RNG_TYPE="taus"

关于c - GSL 和环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966622/

相关文章:

c - 使用 GSL 计算矩阵的克罗内克积的有效方法

c - 传递 argv 语句的不同答案

c - 关于 GDT 和流程

makefile - 通过automake检查make中的环境变量

python - 如何在 python 中执行 os.environ 连接?

gsl - GNU GSL 在哪里可以找到源代码?

c++ - gsl_histogram : Value being equal to an edge between two bins, 值会分配给哪个bin?

c - 我该如何解释 << 和 |在C中

c - struct.field 返回另一个值,为什么?

powershell - PowerShell 中名称中带有点 (.) 的环境变量