Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmake sometimes may fail saying "name return code 0x2" #2498

Closed
zchrissirhcz opened this issue Dec 24, 2020 · 3 comments
Closed

nmake sometimes may fail saying "name return code 0x2" #2498

zchrissirhcz opened this issue Dec 24, 2020 · 3 comments

Comments

@zchrissirhcz
Copy link
Contributor

zchrissirhcz commented Dec 24, 2020

在群里讨论,vs2019,nmake方式,编译ncnn的最后有报错:

@B@ 9C)6~%CFORQD V%OKXT

本人按照 ncnn wiki(也即是doc目录下的 how-to-build/build-for-VS2017.zh.md)方式实践了下,可以成功编译,这里贴一下过程:

软件准备

vs2019,用的是16.8.2版本。通常小版本的差异不影响编译。
cmake,用的是3.19.1,通常来说>=3.15就没问题的。

开始编译

在开始菜单选择vs2019 x64 native的cmd窗口

ncnn_vs2019_build_1

下载了 protobuf 3.4.0 的源码:https://github.com/google/protobuf/archive/v3.4.0.zip

创建了 E:\dbg\cnn-deploy 目录,把protobuf-3.4.0.zip放过去了,等下ncnn源码也放在这个目录下

接下来就是命令行操作了:

e:
mkdir dbg
cd dbg
mkdir cnn-deploy
cd cnn-deploy


cd protobuf-3.4.0
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install ^
    -Dprotobuf_BUILD_TESTS=OFF ^
    -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
cd ..
cd ..


git clone https://github.com/Tencent/ncnn.git
cd ncnn
git submodule update --init
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install ^
    -DProtobuf_INCLUDE_DIR=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/include ^
    -DProtobuf_LIBRARIES=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/lib/libprotobuf.lib ^
    -DProtobuf_PROTOC_EXECUTABLE=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/bin/protoc.exe ^
	-DOpenCV_DIR=E:/lib/opencv/4.5.0 ..
nmake
nmake install
cd ..
cd ..

这里相对于原始 ncnn wik 里的做法,我的修改:

  • 修改路径
  • 拉取了submodule (glslang)
  • 指定了OpenCV_DIR变量,这个变量指向包含 OpenCVConfig.cmake 的目录。

额外:vs2019编译opencv

对于VS2019来说,OpenCV官方没给VS2019的预编译版本,我是自行编译的。编译过程用命令行的方式来记录,是这样的:

cd e:
cd dbg
cd cnn-deploy
git clone https://gitee.com/mirrors/opencv -b 4.5.0 opencv-4.5.0
cd opencv-4.5.0
mkdir build-vs2019
cd build-vs2019

cmake ../.. ^
    -G "Visual Studio 16 2019" -A x64 ^
    -D CMAKE_BUILD_TYPE=Debug ^
    -D CMAKE_INSTALL_PREFIX=E:/lib/opencv/4.5.0 ^
    -D BUILD_TESTS=OFF ^
    -D BUILD_PERF_TESTS=OFF ^
    -D WITH_CUDA=OFF ^
    -D WITH_VTK=OFF ^
    -D WITH_MATLAB=OFF ^
    -D BUILD_DOCS=OFF ^
    -D BUILD_opencv_python3=OFF ^
    -D BUILD_opencv_python2=OFF ^
    -D WITH_IPP=OFF
cmake --build . --target INSTALL --config Debug
cmake --build . --target INSTALL --config Release
cd ..
cd ..
@zchrissirhcz
Copy link
Contributor Author

zchrissirhcz commented Dec 24, 2020

经过排查,该群友发现是cmake命令多写了一个-导致的namke 返回0x2错误码,去掉后编译成功了。

@zchrissirhcz
Copy link
Contributor Author

P.S. 指定 Protobuf_LIBRARIES 的时候,如果用了相对路径,也会导致nmake产生0x2错误码。

具体说,cmake时用的是:

cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install ^
    -DProtobuf_INCLUDE_DIR=../../protobuf-3.4.0/build-vs2019/install/include ^
    -DProtobuf_LIBRARIES=../../protobuf-3.4.0/build-vs2019/install/lib/libprotobuf.lib ^
    -DProtobuf_PROTOC_EXECUTABLE=../../protobuf-3.4.0/build-vs2019/install/bin/protoc.exe ^
    -DNCNN_VULKAN=OFF ^
    -DOpenCV_DIR=E:/lib/opencv/4.5.0 ..

报错类似:

image

需要把 Protobuf_LIBRARIES 等变量,换成绝对路径,来解决问题

@wizVR-zhangjun
Copy link

在群里讨论,vs2019,nmake方式,编译ncnn的最后有报错:

@B@ 9C)6~%CFORQD V%OKXT

本人按照 ncnn wiki(也即是doc目录下的 how-to-build/build-for-VS2017.zh.md)方式实践了下,可以成功编译,这里贴一下过程:

软件准备

vs2019,用的是16.8.2版本。通常小版本的差异不影响编译。 cmake,用的是3.19.1,通常来说>=3.15就没问题的。

开始编译

在开始菜单选择vs2019 x64 native的cmd窗口

ncnn_vs2019_build_1

下载了 protobuf 3.4.0 的源码:https://github.com/google/protobuf/archive/v3.4.0.zip

创建了 E:\dbg\cnn-deploy 目录,把protobuf-3.4.0.zip放过去了,等下ncnn源码也放在这个目录下

接下来就是命令行操作了:

e:
mkdir dbg
cd dbg
mkdir cnn-deploy
cd cnn-deploy


cd protobuf-3.4.0
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install ^
    -Dprotobuf_BUILD_TESTS=OFF ^
    -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
cd ..
cd ..


git clone https://github.com/Tencent/ncnn.git
cd ncnn
git submodule update --init
mkdir build-vs2019
cd build-vs2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install ^
    -DProtobuf_INCLUDE_DIR=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/include ^
    -DProtobuf_LIBRARIES=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/lib/libprotobuf.lib ^
    -DProtobuf_PROTOC_EXECUTABLE=E:/dbg/cnn-deploy/protobuf-3.4.0/build-vs2019/install/bin/protoc.exe ^
	-DOpenCV_DIR=E:/lib/opencv/4.5.0 ..
nmake
nmake install
cd ..
cd ..

这里相对于原始 ncnn wik 里的做法,我的修改:

  • 修改路径
  • 拉取了submodule (glslang)
  • 指定了OpenCV_DIR变量,这个变量指向包含 OpenCVConfig.cmake 的目录。

额外:vs2019编译opencv

对于VS2019来说,OpenCV官方没给VS2019的预编译版本,我是自行编译的。编译过程用命令行的方式来记录,是这样的:

cd e:
cd dbg
cd cnn-deploy
git clone https://gitee.com/mirrors/opencv -b 4.5.0 opencv-4.5.0
cd opencv-4.5.0
mkdir build-vs2019
cd build-vs2019

cmake ../.. ^
    -G "Visual Studio 16 2019" -A x64 ^
    -D CMAKE_BUILD_TYPE=Debug ^
    -D CMAKE_INSTALL_PREFIX=E:/lib/opencv/4.5.0 ^
    -D BUILD_TESTS=OFF ^
    -D BUILD_PERF_TESTS=OFF ^
    -D WITH_CUDA=OFF ^
    -D WITH_VTK=OFF ^
    -D WITH_MATLAB=OFF ^
    -D BUILD_DOCS=OFF ^
    -D BUILD_opencv_python3=OFF ^
    -D BUILD_opencv_python2=OFF ^
    -D WITH_IPP=OFF
cmake --build . --target INSTALL --config Debug
cmake --build . --target INSTALL --config Release
cd ..
cd ..

@zchrissirhcz vs2019 编译 opencv4.5.0 不成功
E:\dbg\cnn-deploy\opencv-4.5.0\build-vs2019>cmake ../.. ^
More? -G "Visual Studio 16 2019" -A x64 ^
More? -D CMAKE_BUILD_TYPE=Debug ^
More? -D CMAKE_INSTALL_PREFIX=E:/lib/opencv/4.5.0 ^
More? -D BUILD_TESTS=OFF ^
More? -D BUILD_PERF_TESTS=OFF ^
More? -D WITH_CUDA=OFF ^
More? -D WITH_VTK=OFF ^
More? -D WITH_MATLAB=OFF ^
More? -D BUILD_DOCS=OFF ^
More? -D BUILD_opencv_python3=OFF ^
More? -D BUILD_opencv_python2=OFF ^
More? -D WITH_IPP=OFF
CMake Warning:
Ignoring extra path from command line:

"../.."

CMake Error: The source directory "E:/dbg/cnn-deploy" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
这个是上面的步骤执行的 不知问题在什么地方

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants