gpt4 book ai didi

在 Netbeans 中编译使用 R 库的 C 代码

转载 作者:行者123 更新时间:2023-11-30 16:57:48 26 4
gpt4 key购买 nike

我在调试作为 R 包的一部分编写的一些 C 代码时遇到了问题。当我从 Windows 控制台(即 cmd.exe)使用 R CMD SHLIB 时,代码会编译并执行:

>R CMD SHLIB MaximumAgreementForest.c
gcc -m64 -I"C:/PROGRA~1/R/R-32~1.4RE/include" -DNDEBUG -I"d:/RCompile/r-compiling/local/local323/include" -O2 -Wall -std=gnu99 -mtune=core2 -c MaximumAgreementForest.c -o MaximumAgreementForest.o
gcc -m64 -shared -s -static-libgcc -o MaximumAgreementForest.dll tmp.def MaximumAgreementForest.o -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -LC:/PROGRA~1/R/R-32~1.4RE/bin/x64 -lR

在我开始使用 R 库中的函数 R_allocC_alloc 之前,该脚本也在 Netbeans 中正确构建。现在似乎无法找到一些 R 特定函数的定义。当我尝试在 Netbeans 中构建项目时,控制台列出以下内容:

cd 'C:\Work\Fun\implied_weight\MAF'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Work/Fun/implied_weight/MAF'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/libMAF.dll
make.exe[2]: Entering directory `/c/Work/Fun/implied_weight/MAF'
mkdir -p build/Debug/MinGW-Windows/_ext/5c0
rm -f "build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o.d"
gcc -DDEBUG -O2 -Wall -mtune=core2 -c -g -Wall -I/C/Program\ Files/R/R-3.2.4revised/include -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o.d" -o build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o ../MaximumAgreementForest.c
mkdir -p dist/Debug/MinGW-Windows
gcc -DDEBUG -O2 -Wall -mtune=core2 -o dist/Debug/MinGW-Windows/libMAF.dll build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o -L/C/Program\ Files/R -L/C/Program\ Files/R/R-3.2.4revised/library -shared
build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o: In function `forest_new':
C:\Work\Fun\implied_weight\MAF/../MaximumAgreementForest.c:37: undefined reference to `R_alloc'
build/Debug/MinGW-Windows/_ext/5c0/MaximumAgreementForest.o: In function `forest_plant':
C:\Work\Fun\implied_weight\MAF/../MaximumAgreementForest.c:55: undefined reference to `S_alloc'
[...]
C:\Work\Fun\implied_weight\MAF/../MaximumAgreementForest.c:515: undefined reference to `R_chk_free'
collect2.exe: error: ld returned 1 exit status

我的脚本是一个 .c 文件,包含以下行

#define USE_RINTERNALS
#include <R.h> // which itself #includes R_ext/Memory, R_ext Printf
#include <R_ext/Print.h>
#include <R_ext/Memory.h>
#include <Rinternals.h>

考虑到 Netbeans 无法指向相关库,我尝试添加和删除 C:/Program Files/R/R-3.2.4revised/includeC:/Program Files/R/R-3.2.4revised/bin/x64 位于文件→项目属性→常规→源文件夹,无效。

文件→项目属性→构建→C 编译器下,我已包含C:/Program Files/R/R-3.2.4revised/include

当我将C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll添加到构建→链接器→库→库时,通过添加库...选项,我收到错误c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../。 ./../mingw32/bin/ld.exe:找不到-lR,链接器退出时没有(之前?)提示 undefined reference 。

当我随后将系统路径中已存在的“C:/Program Files/R/R-3.2.4revised/bin/x64/”添加到构建→链接器→其他库目录,编译器失败并显示消息 C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll: file not recognize: File format not recognize

我缺少什么...我如何将 Netbeans 指向相关的 R 库?

最佳答案

File format not recognized当 32 位编译器尝试加载到 64 位 .dll 时会遇到错误(反之亦然)。改变路径 C:/Program Files/R/R-3.2.4revised/bin/x64/R.dllC:/Program Files/R/R-3.2.4revised/bin/i386/R.dll解决了问题。

关于在 Netbeans 中编译使用 R 库的 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39333042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com