[英]Using Caffe in C++; Unable to pass caffe::SolverParameter to function without error
我正在尝试编译以下给出的“ Hello World XOR” C ++示例:
https://medium.com/@shiyan/caffe-c-helloworld-example-with-memorydata-input-20c692a82a22
硬件:EX50-UD3R主板GT-640 NVidia卡(2卡)英特尔980(6核)16Gig(4x4)DDR3 RAM
环境:Ubuntu 16.04.2 LTS内核:4.4.0-78-通用Eclipse Neon3 R4.6.3 CUDA 8.0 Caffe:我在06/04/2017从Berkley下载的任何版本
我遵循了在Ubuntu 16.04中安装Caffe的安装说明: https : //github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide
并且所有make命令都成功。
但是,当我尝试在简单的cpp程序中使用库时:
#include <memory>
#include <cstdlib> // Provides NULL, rand, size_t;
#include <stdio.h> // For printf
#include <cstring> // For string
#include "/home/caffe-master/include/caffe/layers/memory_data_layer.hpp"
#include "/home/caffe-master-path>/include/caffe/caffe.hpp"
void blah( caffe::SolverParameter *sp);
int main()
{
... standard c++ code to generate random data deleted for brevity...
caffe::SolverParameter solver_param; // No errors given here for this declaration
blah( solver_param); // Simple function created to test error, same error appears here
caffe::ReadSolverParamsFromTextFileOrDie( path, &solver_param); // Actual function from XOR example, same error
caffe::ReadSolverParamsFromTextFileOrDie("./solver.prototxt", &solver_param); // This also gives same error
boost::shared_ptr<caffe::Solver<float> > solver(caffe::SolverRegistry<float>::CreateSolver(solver_param)); // Same error here
... code that would of passed random data to caffe deleted ...
return 0;
}
void blah( caffe::SolverParameter *sp)
{
std::cout << "BLAH: " << sp->rms_decay_;
return;
}
在Eclipse Neon中,对于包含变量solver_param的任何行,都会出现以下错误,包括在其中创建简单函数blah的行,该行接受一个caffe :: SolverParameter类型的参数*
无效的参数'候选对象是:void ReadSolverParamsFromTextFileOrDie(const std :: __ cxx11 :: basic_string,std :: allocator>&,?*)'caffe_hellow.cpp / caffe第47行语义错误
我尝试在include路径中设置完整路径,并且摆脱了一些错误,我在eclipse中添加了libpath来包含caffe和boost,而摆脱了更多的错误,现在仅保留此错误。 我一直在寻找解决方案,查看.hpp caffe文件以尝试理解它们,并尝试在eclipse中使用不同的设置来摆脱此错误,但没有任何效果。 投放也不起作用。
由于某种原因,它无法将任何声明为SolverParameter类型的变量识别为需要它的函数的兼容参数。 错误消息给出“?*”作为参数类型。 这意味着什么? 你能帮我吗? 谢谢。
您需要包括
#include "caffe/proto/caffe.pb.h"
对于所有与caffe.proto相关的声明
我现在可以编译。 这是使用IDE的菜鸟的结果。 我必须在Project-> Properties-> GCC C ++ Linker-> Libraries(-l)中添加这些库:caffe boost_system glog ...这可能不是必需的... cuda
我还需要为上述内容添加-L路径。 然后,我需要更新/ etc / environment或.bashrc以在LD_LIBRARY_PATH变量中包含caffe和cuda的路径,否则我将收到无法链接的二进制错误。 同样,可能不需要cuda来解决此错误,而其他三个人肯定需要。 我计划使用Cuda-C访问GPU处理器。 谢谢Shai对protoc项的答复,它使我对包括库在内的其他评论成为可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.