我在调试一些我作为R包的一部分编写的C代码时遇到了问题。当我从Windows控制台使用R CMD SHLIB
(即cmd.exe)时,代码会编译并执行:
>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
该脚本也在Netbeans中正确构建,直到我开始使用R库中的函数R_alloc
和C_alloc
。现在它似乎无法找到许多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/include
和C:/Program Files/R/R-3.2.4revised/bin/x64
,没有效果。
在文件→项目属性→构建→C编译器下,我已添加C:/Program Files/R/R-3.2.4revised/include
。
当我将<{1}}添加到构建→链接器→库→库时,通过添加库... 选项,我收到错误{{1并且链接器退出时没有(在?之前)抱怨未定义的引用。
当我随后在系统路径中添加&#34; C:/ Program Files / R / R-3.2.4revised / bin / x64 /&#34;时, Build→Linker→其他库目录,编译器失败并显示消息C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll
我错过了什么......我如何将Netbeans指向相关的R库?
答案 0 :(得分:0)
当32位编译器尝试加载到64位.dll(或反之亦然)时,会遇到File format not recognized
错误。改变路径
C:/Program Files/R/R-3.2.4revised/bin/x64/R.dll
至
C:/Program Files/R/R-3.2.4revised/bin/i386/R.dll
解决了这个问题。