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

CImg: cv.h not found #422

Open
2 of 8 tasks
Zacrain opened this issue Aug 14, 2024 · 4 comments
Open
2 of 8 tasks

CImg: cv.h not found #422

Zacrain opened this issue Aug 14, 2024 · 4 comments

Comments

@Zacrain
Copy link
Contributor

Zacrain commented Aug 14, 2024

Bug category

  • bug - compilation error
  • bug - compilation warning
  • bug - runtime error
  • bug - runtime warning
  • bug - logic error

Matplot++ Version
1.2.0

Describe the bug
I've added Matplot++ via CPM on two Ubuntu machines. I have no issues on one of them. The other, however, can not compile due to cv.h not being found which is required by the 3rd party library CImg.

In CImg.h I've tried changing the included headers to opencv2/opencv.hpp and opencv2/highgui.hpp as OpenCV 4.8.1 is installed. This, understandably, led to a bunch of errors. And removing the CImg library seems not to be a solution either as Matplot++ obviously relies on it in several ways.

Steps to Reproduce

mkdir build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -S<redacted_project_path> -B<redacted_project_path>/build -G "Unix Makefiles" -D ENABLE_MATPLOT=ON
make -j8

(ENABLE_MATPLOT is an option I set in my project's CMake configuration to enable/disable some components which rely on Matplot. I can build my project without Matplot++ features if I want to, so you don't need to worry about that option.)

Output

In file included from <redacted_project_path>/build/_deps/matplotplusplus-src/source/matplot/util/common.cpp:23:
<redacted_project_path>/_deps/matplotplusplus-src/source/3rd_party/cimg/CImg.h:419:10: fatal error: cv.h: No such file or directory
  419 | #include "cv.h"
      |          ^~~~~~

Platform

  • cross-platform issue - linux
  • cross-platform issue - windows
  • cross-platform issue - macos

Environment Details:

  • OS: Ubuntu
  • OS Version: 20.04.6 LTS
  • Compiler: GCC/G++
  • Compiler version: 9.4.0

Additional context
CPM command used to add Matplot++ and the corresponding section in the specific CMake file:

    CPMAddPackage("gh:alandefreitas/[email protected]")
    target_link_libraries(${TARGET_NAME} matplot)
@Zacrain
Copy link
Contributor Author

Zacrain commented Sep 10, 2024

After upgrading CMake from 3.16.3 to 3.30.02 I now encounter the same issue on both machines. Both have newer CMake versions now. Therefore I wonder whether this issue is related to that.

@HosameldinMohamed
Copy link

I'm having the same issue while trying to add Matplot++ using CMake's FetchContent

FetchContent_Declare(
  matplotplusplus
  GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus.git
  GIT_TAG                   v1.2.0
)
FetchContent_MakeAvailable(matplotplusplus)

target_link_libraries(tests PRIVATE matplot)

I'm using CMake 3.30.3

@acolazo
Copy link

acolazo commented Dec 20, 2024

I also have this issue on Ubuntu 22.

@Zacrain
Copy link
Contributor Author

Zacrain commented Feb 7, 2025

A colleague of mine has helped to find a workaround for this issue.

It helps to disable line 120 in source/3rd_party/CMakeLists.txt:
https://github.com/alandefreitas/matplotplusplus/blob/6f8c26beee9a121f92ca6c856acd4520c1efd0e5/source/3rd_party/CMakeLists.txt#L120C5-L120C63

I have added a CMake option MATPLOTPP_WITH_OPENCV which disables this automatically and created a pull request. PR 448

In a CMake project you can now just add another parameter to the cmake command. For example:

cmake -B build -DMATPLOTPP_WITH_OPENCV=OFF

If you would like to disable it programatically in a CMake script, e.g., if you've added it via CPM, you can set the option to OFF like this:

set(MATPLOTPP_WITH_OPENCV OFF CACHE BOOL "Disable use of OpenCV in CImg of Matplot++" FORCE)

In case you've added Matplot++ via CPM, make sure to set the option before calling CPM. Otherwise the option is not effective, as CPM already triggers a configuration of the package.

Example:

# Set Matplot++ compile options.
set(MATPLOTPP_WITH_OPENCV OFF CACHE BOOL "Disable use of OpenCV in CImg of Matplot++" FORCE)

CPMAddPackage(
  NAME matplotplusplus
  GITHUB_REPOSITORY Zacrain/matplotplusplus
  GIT_TAG cimg-optional-compilation
)

Note, that this is not a fix, just a workaround.
Until the PR is merged or the issue resolved otherwise, this might help in your cases as well.

@alandefreitas alandefreitas linked a pull request Feb 7, 2025 that will close this issue
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

3 participants