Ncnn: cmake vs2015编译报错

Created on 5 Mar 2018  ·  10Comments  ·  Source: Tencent/ncnn

我参照https://github.com/Tencent/ncnn/wiki/cmake-VS2017-%E7%BC%96%E8%AF%91 用vs2015编译时,在nmake 命令后benchmark处出现错误,有人遇到吗?下面是错误代码:

[  1%] Building CXX object src/CMakeFiles/ncnn.dir/benchmark.cpp.obj
benchmark.cpp
d:\workspace\fld\ncnn-master\src\mat.h(333): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(150): error C3861: “_InterlockedIncrement”: 找 不到标识符
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(155): error C3861: “_InterlockedDecrement”: 找 不到标识符
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(50): error C2079: “tp”使用未定义的 struct“ncnn::get_current_time::timeval”
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(52): error C2228: “.tv_sec”的左边必须有类/结构/联合
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(52): note: 类型是“int”
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(53): error C2228: “.tv_usec”的左边必须有类/结构/联合
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(53): note: 类型是“int”
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(55): error C2065: “tv”: 未声明的标识符
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(55): error C2228: “.tv_sec”的左边必须有类/结构/联合
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(55): note: 类型是“unknown-type”
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(55): error C2228: “.tv_usec”的左边必须有类/结构/联合
D:\workspace\FLD\ncnn-master\src\benchmark.cpp(55): note: 类型是“unknown-type”
NMAKE : fatal error U1077: “C:\PROGRA~2\MICROS~4.0\VC\bin\amd64\cl.exe”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"”: 返回代码“0x2”
Stop.

Most helpful comment

我验证了下,和 #include<string> #include "mat.h"的顺序有关,索性我就把 string 加到mat.h 里面就可以解决了。具体不知道啥原因。

File:mat.h

#ifndef NCNN_MAT_H
#define NCNN_MAT_H
#include <stdlib.h>
#include <string>
//#include <string.h>
#if __ARM_NEON
#include <arm_neon.h>
#endif

All 10 comments

benchmark.cpp 的windows实现似乎有些问题。timeval未定义,几个变量似乎应该用的tp但写的tv。用vs2015编译应该是想用model转换工具吧。把benchmark.cpp整个文件暂时注释掉其实就行了,我这么编译过了。完整的修改等作者修改吧。。。。。。。。

更新代码还是没有编译过

emmmm,还有问题...

非常感谢@nihui@egg532
第二次更新后解决了“tp未定义的问题”,还出现了这个错误:

[  2%] Building CXX object src/CMakeFiles/ncnn.dir/benchmark.cpp.obj
benchmark.cpp
d:\workspace\fld\ncnn-master\src\mat.h(333): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(150): error C3861: “_InterlockedIncrement”: 找 不到标识符
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(155): error C3861: “_InterlockedDecrement”: 找 不到标识符
NMAKE : fatal error U1077: “C:\PROGRA~2\MICROS~4.0\VC\bin\amd64\cl.exe”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"”: 返回代码“0x2”
Stop.

我参照https://msdn.microsoft.com/en-us/library/windows/desktop/ms683614(v=vs.85).aspx 在benchmark.h 添加了 #include ,编译通过。 不知道这是不是解决办法

benchmark.cpp做如下修改可以编译通过

原来的

#include "benchmark.h"

#if NCNN_BENCHMARK
#include <stdio.h>
#include "layer/convolution.h"
#endif // NCNN_BENCHMARK

#ifdef _WIN32

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdint.h> // portable: uint64_t   MSVC: __int64
#else // _WIN32
#include <sys/time.h>
#endif // _WIN32

修改后

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdint.h> // portable: uint64_t   MSVC: __int64
#else // _WIN32
#include <sys/time.h>
#endif // _WIN32

#include "benchmark.h"

#if NCNN_BENCHMARK
#include <stdio.h>
#include "layer/convolution.h"
#endif // NCNN_BENCHMARK

我验证了下,和 #include<string> #include "mat.h"的顺序有关,索性我就把 string 加到mat.h 里面就可以解决了。具体不知道啥原因。

File:mat.h

#ifndef NCNN_MAT_H
#define NCNN_MAT_H
#include <stdlib.h>
#include <string>
//#include <string.h>
#if __ARM_NEON
#include <arm_neon.h>
#endif

编译通过,但是使用ncnn.lib的过程中还是报相同的错误!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Abel119 picture Abel119  ·  4Comments

varbegin picture varbegin  ·  3Comments

lovehuanhuan picture lovehuanhuan  ·  3Comments

AlexeyAB picture AlexeyAB  ·  3Comments

jinfagang picture jinfagang  ·  4Comments