I have a c++ project that uses the OpenCV library. It takes a long time to build when I run make. How can I speed up the build time?
I did install OpenCV with GPU support and thought this might be the bottleneck (since it may be compiling for different GPU architectures?), so I tried using cmake -D WITH_CUDA=OFF .. to build my project. Unfortunately, this didn't do the trick... Any tips?
Note: I'm fine disabling the GPU if it speeds up compile time significantly.
This is what my CMakeLists.txt file looks like:
cmake_minimum_required(VERSION 3.10)
project(Cruisin VERSION 1.0)
find_package( OpenCV REQUIRED)
find_package (Threads)
include_directories(include)
include_directories( ${OpenCV_INCLUDE_DIRS} )
file(GLOB SOURCES src/*.cpp app/main.cpp)
add_executable(main ${SOURCES})
target_link_libraries( main ${CMAKE_THREAD_LIBS_INIT} ) # Add threading lib
target_link_libraries( main ${OpenCV_LIBS} )
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Other Details:
Compiler: gcc
OS: virtual Ubuntu 20.04 (WSL2 on Windows 10)
Project structure: there's one main cpp file in
ROOT/app/, 2 source files inROOT/src/with 2 corresponding headers inROOT/include/OpenCV and my project files are located on the regular Windows file system (accessed through
/mnt/directory), but CUDA and Make/CMake are in the virtual WSL
Edit: Solution
The issue seemed to be WSL being very slow with any I/O being done in the windows filesystem. In my case, I was using OpenCV installed somewhere in mnt/ (Windows filesystem). I rebuilt OpenCV in WSL somewhere in /, and moved my project there as well and it is so much faster.