简体   繁体   English

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

[英]Compiling C code that uses R libraries in Netbeans

I've been having trouble debugging some C code that I'm writing as part of an R package. 我一直在调试作为R包的一部分编写的某些C代码时遇到麻烦。 The code compiles and executes when I use R CMD SHLIB from the Windows console (ie cmd.exe): 当我从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

The script also built correctly in Netbeans until I started using the functions R_alloc and C_alloc from the R libraries. 在我开始使用R库中的函数R_allocC_alloc之前,该脚本还在Netbeans中正确构建。 Now it doesn't seem to be able to find the definitions of a number of R-specific functions. 现在看来似乎无法找到许多R特定功能的定义。 When I attempt to build the project in Netbeans the console lists the following: 当我尝试在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

My script, a single .c file, contains the lines 我的脚本是一个.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>

Figuring that Netbeans is failing to point to the relevant libraries, I have tried adding and removing C:/Program Files/R/R-3.2.4revised/include and C:/Program Files/R/R-3.2.4revised/bin/x64 at File→Project Properties→General→Source folders , to no effect. 考虑到Netbeans无法指向相关库,我尝试添加和删除C:/Program Files/R/R-3.2.4revised/includeC:/Program Files/R/R-3.2.4revised/bin/x64文件→项目属性→常规→源文件夹下C:/Program Files/R/R-3.2.4revised/bin/x64 ,无效。

Under File→Project Properties→Build→C compiler , I have included C:/Program Files/R/R-3.2.4revised/include . 文件→项目属性→构建→C编译器下 ,我包含了C:/Program Files/R/R-3.2.4revised/include

When I add C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll to Build→Linker→Libraries→Libraries , via the Add Library... option, I receive the error c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lR , and the linker exits without (before?) complaining about the undefined references. 当我通过Add Library ...选项将C:/Program Files/R/R-3.2.4revised/bin/x64/R.dllBuild→Linker→Libraries→Libraries时 ,收到错误c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lR ,并且链接器在没有(before?)的情况下退出抱怨未定义的引用。

When I subsequently add "C:/Program Files/R/R-3.2.4revised/bin/x64/", which is already in by System PATH, to Build→Linker→Additional Library Directories , the compiler fails with the message C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll: file not recognized: File format not recognized 随后,当我将系统路径已包含的“ C:/ Program Files / R / R-3.2.4revised / bin / x64 /”添加到Build→Linker→Additional Library Directories时 ,编译器将失败,并显示消息C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll: file not recognized: File format not recognized

What am I missing... how can I point Netbeans to the relevant R libraries? 我缺少什么...如何将Netbeans指向相关的R库?

The File format not recognized error is encountered when a 32-bit compiler tries to load to a 64-bit .dll (or vice-versa). 当32位编译器尝试加载到64位.dll时遇到File format not recognized错误(反之亦然)。 Changing the path C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll to C:/Program Files/R/R-3.2.4revised/bin/i386/R.dll resolved the problem. 将路径C:/Program Files/R/R-3.2.4revised/bin/x64/R.dllC:/Program Files/R/R-3.2.4revised/bin/i386/R.dll解决了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM