首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TMB教程中的编译错误是什么?

TMB教程中的编译错误是什么?
EN

Stack Overflow用户
提问于 2017-03-13 04:28:26
回答 1查看 1.2K关注 0票数 0

我从TMB C++ 教程页复制了教程页代码。

代码语言:javascript
复制
#include <TMB.hpp>                                // Links in the TMB libraries

template<class Type>
Type objective_function<Type>::operator() ()
{
    DATA_VECTOR(x);                                 // Data vector transmitted from R
    PARAMETER(mu);                                  // Parameter value transmitted from R
    PARAMETER(sigma);                               //                 

    Type f;                                         // Declare the "objective function" (neg. log. likelihood)
    f = -sum(dnorm(x,mu,sigma,true));               // Use R-style call to normal density

    return f;
}

并将其保存为tutorial.cpp。然后我试着按照指令编译它,得到了:

代码语言:javascript
复制
> compile("tutorial.cpp")
Error in compile("tutorial.cpp") : Compilation failed
In addition: Warning messages:
1: In readLines(file) : incomplete final line found on 'tutorial.cpp'
2: running command 'make -f ".../R/R-33~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.2/share/make/winshlib.mk" -f "...\AppData\Local\Temp\RtmpqgV7xA\file2d987ade32f3" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="tutorial.dll" WIN=64 TCLBIN=64 OBJECTS="tutorial.o"' had status 127 

此外,在RStudio编辑器窗口中,我可以看到行Type objective_function<...旁边有一个交叉,在错误上方悬停:

代码语言:javascript
复制
Variable templates are a C++1y extension
expected ';' at end of declaration
expected unqualified-id

为了使教程函数编译,我应该做些什么来修复它?

会议信息:

代码语言:javascript
复制
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] TMB_1.7.8

loaded via a namespace (and not attached):
[1] Matrix_1.2-8     tools_3.3.2      grid_3.3.2    lattice_0.20-34 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-13 05:20:44

我现在已经解决了我的问题,它分为两部分。第一个是在Windows中没有安装Rtools。我是这里提到的

为什么在从CRAN安装TMB之后,我不能在Windows中构建和运行模型?Windows上的TMB需要Rtools。PATH环境变量应指向Rtools 'make‘和'gcc',而不应指向其他“make”或'gcc’的实例。

第二个问题是,在安装Rtools之后,我仍然找不到编译,尽管我验证了可以从这些指示后面的命令行使用它。

代码语言:javascript
复制
In some cases this PATH might be C:\RBuildTools... Further, we can check if g++ can be really called from R. For example, we can see the version of gcc in R as follows.

> system('g++ -v')
Using built-in specs.
COLLECT_GCC=c:\Rtools\GCC-46~1.3\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/rtools/gcc-46~1.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32 --build=x86_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --prefix=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --with-gmp=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpfr=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpc=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --disable-shared --enable-static --enable-targets=all --enable-languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions --enable-fully-dynamic-string --disable-nls --disable-werror --enable-checking=release --disable-win32-registry --disable-rpath --disable-werror CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
Thread model: win32
gcc version 4.6.3 20111208 (prerelease) (GCC)

> system('where make')
c:\Rtools\bin\make.exe

我收到的错误是:

代码语言:javascript
复制
> compile('tutorial.cpp')
c:/Rtools/mingw_64/bin/g++  
...
c:/Rtools/mingw_64/bin/g++: not found

这表明这条路在某个地方被硬编码了。按照使用可选gcc编译器的说明,我发现路径在位于:"C:\Program Files\R\R-3.3.2\etc\x64\Makeconf"Makeconf文件中进行了硬编码。

然后,我注释掉了旧行,并用正确的路径替换了它:

代码语言:javascript
复制
# BINPREF ?= c:/Rtools/mingw_64/bin/
BINPREF ?= C:/RBuildTools/3.4/mingw_64/bin/

在此之后,编译工作而不需要重新启动。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42756640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档