加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

包括gsl_type.h.文件未找到

发布时间:2020-12-16 09:55:23 所属栏目:百科 来源:网络整理
导读:这似乎是一个常见的问题,但我无法解决这个问题. 我有一些.c代码,我使用makefile编译.目标是创建一个共享对象(.so),以便我可以从R运行C代码. 这是我的makefile: obs = R_wrapper.o G.o develop.o utilities.oCFLAGS = -arch x86_64 -std=gnu99 -I/Library/Fr
这似乎是一个常见的问题,但我无法解决这个问题.

我有一些.c代码,我使用makefile编译.目标是创建一个共享对象(.so),以便我可以从R运行C代码.

这是我的makefile:

obs = R_wrapper.o G.o develop.o utilities.o
CFLAGS = -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -I/usr/local/include    -fPIC  -g -O3  -c
LFLAGS = -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -O3 -lgsl -lm -lgslcblas

R_wrapper : $(obs)
    $gcc $(LFLAGS) $(obs) -o R_wrapper.so

R_wrapper.o : R_wrapper.c constants.h develop.h G.h
    $gcc $(CFLAGS) R_wrapper.c

G.o : G.c G.h constants.h utilities.h develop.h 
    $gcc $(CFLAGS) G.c develop.c

develop.o : develop.c develop.h G.h constants.h
    $gcc $(CFLAGS) develop.c

utilities.o : utilities.c develop.h
    $gcc $(CFLAGS) utilities.c

它在我的实验室中的计算机上工作正常,但它在我的个人计算机上不起作用.导致此问题的原因是我的R_wrapper.c开头的这两行.

#include </opt/local/include/gsl/gsl_randist.h>
#include </opt/local/include/gsl/gsl_rng.h>

我试图移动这些文件并给出不同的路径,将gal_type.h文件中的文件放在与我的R_wrapper文件相同的目录中,我试图重命名我的目录,以便路径更传统,但操作系统没有给我权利重新命名选择usr(这可能显而易见).我没有创建makefile,也没有完全得到它.我想我需要在CFLAGS或LFLAGS中的-I参数之后修改路径.

编辑1

我在实验室计算机上更改了R_wrapper.c以摆脱#include< ...>中的整个路径.编辑失败,因为@Beta预测.然后,我更改了我的makefile,将-I / opt / local / include / gsl添加到CFLAGS.我不知道你的意思验证makefile仍然有效.我尝试在我的实验室计算机上使用我编辑的makefile进行编译,但是失败了.然后我重新编辑了我的makefile,将-I / opt / local / include / gsl更改为-I /usr/local/include / gsl,因为在我的实验室计算机上gsl文件夹位于/usr/local/include / gsl. -I / opt / local / include / gsl是我计算机上gsl文件夹的位置.所以我被困在你的程序中.

编辑2

我将gsl文件夹移动到我的计算机上,试图从不同的路径中包含它.一些有趣的事情发生了.例如,当我把我的gsl文件夹放在Users / remi / Documents / Biologie / programing / C /中并写入(在CFLAGS中)

-I/Users/remi/Documents/Biologie/programing/C/

我收到此错误:

R_wrapper.c:43:10: fatal error: 'gsl_randist.h' file not found
#include <gsl_randist.h> // goal.

当我写(在CFLAGS中)

Users/remi/Documents/Biologie/programing/C/gsl

我收到此错误消息:

"In file included from R_wrapper.c:43: /Users/remi/Documents/Biologie/programing/C/gsl/gsl_randist.h:22:10: fatal error: 
      'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>"

解决方法

将评论转移到答案

从编辑2中提到的没有找到gsl / gsl_rng.h的消息判断,你应该写

#include <gsl/gsl_randist.h>

(源代码中带有gsl /前面的gsl /前缀的路径前缀).这是一个常见的惯例.然后,在-I选项中指定包含gsl子目录的目录的名称,该子目录包含gsl _ * .h标头.在你的编辑2中,你说你把gsl目录放到/ Users / remi / Documents / Biologie / programing / C /中,这样你就可以使用了:

-I/Users/remi/Documents/Biologie/programing/C/

在您尝试的命令行上.

您应该阅读文档,如果它写了以下任何一个:

#include <gsl/gsl_randist.h>
#include "gsl/gsl_randist.h"

那么这就是你应该在你的代码中写的东西,因为(正如你已经发现的那样)如果不这样做,它将无法工作.

Beta的answer也说明了

In general it’s a bad idea to write paths into the #include statements unless you really have to; it causes just this kind of problem.

我同意,但会更强烈地说明:

>不要在#include语句中编写完整的路径.

如果你编写它们,它会从根本上限制代码的可移植性.您不能依赖其他人的计算机安装在与系统上安装的相同位置的计算机.如果你在开源软件中试过它,你就会被嘲笑.

警惕那些对../somedir/header.h感到可爱的人 – 见What are the benefits of a relative path such as “../include/header.h” for a header?.

我观察到GNU Scientific Library手册有一个example program开始:

#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>

而Compiling and Linking节则说:

The library header files are installed in their own gsl directory. You should write any preprocessor include statements with a gsl/ directory prefix thus,

06004

If the directory is not installed on the standard search path of your compiler you will also need to provide its location to the preprocessor as a command line flag. The default location of the gsl directory is /usr/local/include/gsl.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读