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

无法运行example里面的test yolox #14

Closed
gyy0592 opened this issue Aug 7, 2021 · 4 comments
Closed

无法运行example里面的test yolox #14

gyy0592 opened this issue Aug 7, 2021 · 4 comments
Labels
question Further information is requested Windows

Comments

@gyy0592
Copy link

gyy0592 commented Aug 7, 2021

报错了

错误 LNK2001 无法解析的外部符号 "public: void __cdecl ortcv::YoloX::detect(class cv::Mat const &,class std::vector<struct ortcv::types::BoundingBoxType<float,float>,class std::allocator<struct ortcv::types::BoundingBoxType<float,float> > > &,float,float,unsigned int,unsigned int)" (?detect@YoloX@ortcv@@QEAAXAEBVMat@cv@@aeav?$vector@U?$BoundingBoxType@MM@types@ortcv@@v?$allocator@U?$BoundingBoxType@MM@types@ortcv@@@std@@@std@@mmii@Z) gyy_ort_test D:\Download\lite.ai-main\gyy_test\gyy_ort_test\gyy_ort_test\source.obj 1
请问这种情况应该怎么解决啊

@DefTruth
Copy link
Owner

DefTruth commented Aug 7, 2021

这个是典型的链接错误,编译出来的example在运行时需要找到对应的动态库。我不太好定位你的问题出在哪里。我是用Mac+CLion+CMake开发的,编译器是clang。你可以尝试下Windows+CLion+CMake+MSVC来编译。 你可以看一下这个关于windows下跑lite.ai的讨论 #6

@DefTruth
Copy link
Owner

DefTruth commented Aug 7, 2021

关于如何链接编好的lite.ai动态库,CMakeLists的设置可以参考下:

cmake_minimum_required(VERSION 3.17)
project(lite.ai-release)

message(">>>> Current project is: ${CMAKE_SOURCE_DIR}")

set(CMAKE_CXX_STANDARD 11)

# link opencv.
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv/lib/cmake/opencv4)
find_package(OpenCV 4 REQUIRED)
if (OpenCV_FOUND)
    include_directories(${OpenCV_INCLUDE_DIRS})
    set(OpenCV_LIBS opencv_highgui opencv_core opencv_imgcodecs opencv_imgproc) # need only
    message("=================================================================================")
    message(STATUS "    OpenCV library status:")
    message(STATUS "    version: ${OpenCV_VERSION}")
    message(STATUS "    libraries: ${OpenCV_LIBS}")
    message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
    message("=================================================================================")
else ()
    message(FATAL_ERROR "OpenCV library not found")
endif()

# link onnxruntime.
set(ONNXRUNTIME_DIR ${CMAKE_SOURCE_DIR}/onnxruntime/)
set(ONNXRUNTIME_INCLUDE_DIR ${ONNXRUNTIME_DIR}/include)
set(ONNXRUNTIME_LIBRARY_DIR ${ONNXRUNTIME_DIR}/lib)
include_directories(${ONNXRUNTIME_INCLUDE_DIR})
link_directories(${ONNXRUNTIME_LIBRARY_DIR})

# link lite.ai.
set(LITEHUB_DIR ${CMAKE_SOURCE_DIR}/lite.ai)
set(LITEHUB_INCLUDE_DIR ${LITEHUB_DIR}/include)
set(LITEHUB_LIBRARY_DIR ${LITEHUB_DIR}/lib)
include_directories(${LITEHUB_INCLUDE_DIR})
link_directories(${LITEHUB_LIBRARY_DIR})

# add your executable
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/examples/build)

add_executable(lite_yolov5 examples/test_lite_yolov5.cpp)
target_link_libraries(lite_yolov5 lite.ai onnxruntime ${OpenCV_LIBS})  # link lite.ai

对应的动态库目录需要修成你自己的。一个在mac上的参考案例 lite.ai-release

@gyy0592
Copy link
Author

gyy0592 commented Aug 7, 2021

最后错误得以解决,是把所有文件都丢到根目录运行去找bug,然后发现是
ort_handler.cpp里面
#ifdef LITEHUB_WIN32
#include "ort_utils.h"
#endif
出现问题
手动引入ort_utils.h后解决

以及 onnx_path = _onnx_path.data();的类型错误
改为 onnx_path = (const wchar_t*)_onnx_path.data();成功解决 可能是编译器的问题(vs2019)

不太理解为什么, 是小白,不过还是把这个po出来把,最后非常感谢大佬

@DefTruth
Copy link
Owner

DefTruth commented Aug 7, 2021

最后错误得以解决,是把所有文件都丢到根目录运行去找bug,然后发现是
ort_handler.cpp里面
#ifdef LITEHUB_WIN32
#include "ort_utils.h"
#endif
出现问题
手动引入ort_utils.h后解决

以及 onnx_path = _onnx_path.data();的类型错误
改为 onnx_path = (const wchar_t*)_onnx_path.data();成功解决 可能是编译器的问题(vs2019)

不太理解为什么, 是小白,不过还是把这个po出来把,最后非常感谢大佬

赞👍🏻 ~, onnxruntime在windows下是用的宽字符,代码了应该已经处理,至于为什么还出现这个bug,emmmm......我也很迷 🤔

#ifdef LITE_WIN32
  std::wstring _w_onnx_path(ortcv::utils::to_wstring(_onnx_path));
  onnx_path = _w_onnx_path.data();
#else
  onnx_path = _onnx_path.data();
#endif
  initialize_handler();

在lite.ai.defs.h里边有做这个宏判断,你可以查下有没有生效。

#if (defined _WIN32 || defined WINCE || defined __CYGWIN__)
#  define LITE_WIN32
#elif defined __GNUC__ && __GNUC__ >= 4 && (defined(__APPLE__))
# define LITE_UNIX
#endif

你试下用最新的代码,旧版本的一些问题已经修复了。
补充下,确实有处宏判断写错了。在ort_handler.cpp原来的代码:

#ifdef LITEHUB_WIN32
#include "ort_utils.h"
#endif

需要修改成

#ifdef LITE_WIN32
#include "ort_utils.h"
#endif

@DefTruth DefTruth added Windows question Further information is requested labels Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Windows
Projects
None yet
Development

No branches or pull requests

2 participants