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

Linux Build Error #271

Closed
AthanatiusC opened this issue Apr 5, 2022 · 13 comments
Closed

Linux Build Error #271

AthanatiusC opened this issue Apr 5, 2022 · 13 comments

Comments

@AthanatiusC
Copy link

I got this error while building in Linux:

/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgproc
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_video
/usr/bin/ld: cannot find -lopencv_videoio
/usr/bin/ld: cannot find -lonnxruntime
collect2: error: ld returned 1 exit status

Please help! thanks!

@DefTruth
Copy link
Owner

DefTruth commented Apr 5, 2022

you need to prepare all the third party deps libs your self, such as opencv with ffmpeg, onnxruntime, also need NCNN/MNN/TNN if you want to build lite.ai.toolkit with NCNN/MNN/TNN support. please check README for more details. In fact, I have already provided some prebuilt libs of lite.ai.toolkit for linux with onnxruntime support.

@DefTruth DefTruth closed this as completed Apr 5, 2022
@DefTruth
Copy link
Owner

DefTruth commented Apr 5, 2022

Linux and Windows.

⚠️ Lite.Ai.ToolKit is not directly support Linux and Windows now. For Linux and Windows, you need to build or download(if have official builts) the shared libs of OpenCVONNXRuntime and any other Engines(like MNN, NCNN, TNN) firstly, then put the headers into the specific directories or just let these directories unchange(use the headers offer by this repo, the header file of the dependent library of this project is directly copied from the corresponding official library). However, the dynamic libraries under different operating systems need to be recompiled or downloaded. MacOS users can directly use the dynamic libraries of each dependent library provided by this project:

  • lite.ai.toolkit/opencv2
      cp -r you-path-to-downloaded-or-built-opencv/include/opencv4/opencv2 lite.ai.toolkit/opencv2
  • lite.ai.toolkit/onnxruntime
      cp -r you-path-to-downloaded-or-built-onnxruntime/include/onnxruntime lite.ai.toolkit/onnxruntime
  • lite.ai.toolkit/MNN
      cp -r you-path-to-downloaded-or-built-MNN/include/MNN lite.ai.toolkit/MNN
  • lite.ai.toolkit/ncnn
      cp -r you-path-to-downloaded-or-built-ncnn/include/ncnn lite.ai.toolkit/ncnn
  • lite.ai.toolkit/tnn
      cp -r you-path-to-downloaded-or-built-TNN/include/tnn lite.ai.toolkit/tnn

and put the libs into lite.ai.toolkit/lib/(linux|windows) directory. Please reference the build-docs1 for third_party.

  • lite.ai.toolkit/lib/(linux|windows)
      cp you-path-to-downloaded-or-built-opencv/lib/*opencv* lite.ai.toolkit/lib/(linux|windows)/
      cp you-path-to-downloaded-or-built-onnxruntime/lib/*onnxruntime* lite.ai.toolkit/lib/(linux|windows)/
      cp you-path-to-downloaded-or-built-MNN/lib/*MNN* lite.ai.toolkit/lib/(linux|windows)/
      cp you-path-to-downloaded-or-built-ncnn/lib/*ncnn* lite.ai.toolkit/lib/(linux|windows)/
      cp you-path-to-downloaded-or-built-TNN/lib/*TNN* lite.ai.toolkit/lib/(linux|windows)/

Note, your also need to install ffmpeg(<=4.2.2) in Linux to support the opencv videoio module. See issue#203. In MacOS, ffmpeg4.2.2 was been package into lite.ai.toolkit, thus, no installation need in OSX. In Windows, ffmpeg was been package into opencv dll prebuilt by the team of opencv. Please make sure -DWITH_FFMPEG=ON and check the configuration info when building opencv.

  • first, build ffmpeg(<=4.2.2) from source.
git clone --depth=1 https://git.ffmpeg.org/ffmpeg.git -b n4.2.2
cd ffmpeg
./configure --enable-shared --disable-x86asm --prefix=/usr/local/opt/ffmpeg --disable-static
make -j8
make install
  • then, build opencv with -DWITH_FFMPEG=ON, just like
#!/bin/bash

mkdir build
cd build

cmake .. \
  -D CMAKE_BUILD_TYPE=Release \
  -D CMAKE_INSTALL_PREFIX=your-path-to-custom-dir \
  -D BUILD_TESTS=OFF \
  -D BUILD_PERF_TESTS=OFF \
  -D BUILD_opencv_python3=OFF \
  -D BUILD_opencv_python2=OFF \
  -D BUILD_SHARED_LIBS=ON \
  -D BUILD_opencv_apps=OFF \
  -D WITH_FFMPEG=ON 
  
make -j8
make install
cd ..

after built opencv, you can follow the steps to build lite.ai.toolkit.

  • Windows: You can reference to issue#6

  • Linux: The Docs and Docker image for Linux will be coming soon ~ issue#2

  • Happy News !!! : 🚀 You can download the latest ONNXRuntime official built libs of Windows, Linux, MacOS and Arm !!! Both CPU and GPU versions are available. No more attentions needed pay to build it from source. Download the official built libs from v1.8.1. I have used version 1.7.0 for Lite.Ai.ToolKit now, you can download it from v1.7.0, but version 1.8.1 should also work, I guess ~ 🙃🤪🍀. For OpenCV, try to build from source(Linux) or down load the official built(Windows) from OpenCV 4.5.3. Then put the includes and libs into specific directory of Lite.Ai.ToolKit.

  • GPU Compatibility for Windows: See issue#10.

  • GPU Compatibility for Linux: See issue#97.

@DefTruth
Copy link
Owner

DefTruth commented Apr 5, 2022

also, you can download the linux prebuilt libs from releases, and, then, reuse the opencv, ffpmeg and onnxruntime prebuilt libs provided by lite.ai.toolkit

@AthanatiusC
Copy link
Author

AthanatiusC commented Apr 5, 2022

hello, i have already built the minimal dependency like OpenCV and OnnxRuntime, copied all the libs and turned off NCNN/MNN/TNN support in CMAKE (e.g enable ncnn engine), i also have tried copy the prebuult libs and copied them into lite.ai.toolkit libs. Do i also need to build NCNN MNN and TNN even though i turned them off?

I dont know why but it seems like CMAKE does not link lite.ai.toolkit/libs when building..

Thank you for the answer!

@DefTruth
Copy link
Owner

DefTruth commented Apr 5, 2022

hi~ you may need to put the libs into lite.ai.toolkit/lib/linux directory, not lite.ai.toolkit/lib. the CMakeLists.txt provided by lite.ai.toolkit will auto detect your linux os and the point the library link to lite.ai.toolkit/lib/linux dir.

@AthanatiusC
Copy link
Author

Ah i see!! Thank you very much!! I will try to rebuilt it.

@AthanatiusC
Copy link
Author

Thank you very much! I was able to successfully build the toolkit!! :D

@AthanatiusC
Copy link
Author

Hello, i am sorry for re commenting on closed issue, but can i please ask for help?
i got error while building the example project, the lite.ai.toolkit is already successfully built but i still got this error:

[build]      Creating library E:/Work/c++/fafnir/build/Debug/lite_yolov5.lib and object E:/Work/c++/fafnir/build/Debug/lite_yolov5.exp
[build] MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) [E:\Work\c++\fafnir\build\lite_yolov5.vcxproj]
[build] E:\Work\c++\fafnir\build\Debug\lite_yolov5.exe : fatal error LNK1120: 1 unresolved externals [E:\Work\c++\fafnir\build\lite_yolov5.vcxproj]

My cmake :

set(LITE_AI_DIR E:/Work/c++/lite.ai.toolkit/build/lite.ai.toolkit)
include_directories(${LITE_AI_DIR}/include)
link_directories(${LITE_AI_DIR}/lib/MinSizeRel)
link_directories(E:/Work/c++/lite.ai.toolkit/lib/windows)
set(TOOLKIT_LIBS lite.ai.toolkit onnxruntime)
set(OpenCV_LIBS opencv_core455 opencv_imgcodecs455 opencv_imgproc455 opencv_video455 opencv_videoio455)

add_executable(lite_yolov5 test.cpp)
target_link_libraries(lite_yolov5 ${TOOLKIT_LIBS} ${OpenCV_LIBS})

@DefTruth
Copy link
Owner

DefTruth commented Apr 9, 2022

opencv in windows is a singleton lib, not have split libs like opencv in mac and linux.

@AthanatiusC
Copy link
Author

which means, i have to combine all the libs into single folder?

@DefTruth
Copy link
Owner

DefTruth commented Apr 9, 2022

not sure. opencv lib in windows is named like opencv_worldxxx.dll ? you may need to link this dll. I'm not familiar with Windows OS.

@DefTruth
Copy link
Owner

DefTruth commented Apr 9, 2022

@AthanatiusC
Copy link
Author

Ah i see!
thank you i will try it again!

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