VSCode C++ IntelliSense/autocomplete is not working for OpenCV C++ - c++

OpenCV is installed from the source on my Linux (Ubuntu 18.04.6 LTS) machine. The path is a bit different i.e. /usr/local/<blah_blah> and the directory tree looks somewhat like this:
milan#my_machine:/usr/local/<blah_blah>$ tree -L 4
.
├── bin
│   ├── opencv_annotation
│   └── ...
├── include
│   └── opencv4
│   └── opencv2
│   ├── ...
│   ├── core
│   ├── core.hpp
│   ├── ...
│   └── ...
├── lib
│   ├── cmake
│   │   └── opencv4
│   │   ├── OpenCVConfig.cmake
│   │   └── ...
│   ├── ...
│   ├── libopencv_core.so -> libopencv_core.so.4.2
│   ├── libopencv_core.so.4.2 -> libopencv_core.so.4.2.0
│   ├── libopencv_core.so.4.2.0
│   ├── ...
│   ├── ...
│   ├── opencv4
│   │   └── 3rdparty
│   │   ├── ...
│   │   └── ...
│   ├── python2.7
│   │   └── dist-packages
│   │   └── cv2
│   └── python3.6
│   └── dist-packages
│   └── cv2
└── share
├── licenses
│   └── opencv4
│   ├── ...
│   └── ...
└── opencv4
├── ...
│   └── ...
├── ...
└── ...
I had a similar issue for PCL (Point Cloud Library) in the past and my answer/solution fixed that. So, I tried something similar:
In settings.json, I put:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4/opencv2/**",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core/*",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core/**"
],
and in the c_cpp_properties.json file, I put:
"includePath": [
"${workspaceFolder}/**",
"${default}"
],
However, doing this is not fixing the issue. C++ IntelliSense/autocomplete still does not work for OpenCV C++. So, how to fix this issue?
Sample Code:
Note1:
In cmake, /usr/local/<blah_blah>/include/opencv4 is used under include_directories.
Compilation and execution work fine.
Note2: the following questions/issues are different from mine:
VSCode autocomplete not working for OpenCV installed from source -- for OpenCV Python, not C++
cv2 (opencv-python) intellisense not working -- for OpenCV Python, not C++

It turned out that in my settings.json file, the includePaths were set like this:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4/opencv2/**",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core.hpp",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core",
.
.
],
However, in my code, the headers were included like:
#include <opencv2/core.hpp>
If the opencv2 folder needs to be included in the #include directive, the includePaths should look like this:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4",
.
.
],
So, the following includePaths configuration fixed the issue with IntelliSense/autocompletion for OpenCV:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4",
"/usr/local/<blah_blah>/include/opencv4/**",
],
For a detailed explanation, take a look into the issue (Issue 9900) I created on vscode-cpptools GitHub page, particularly this thread/reply.
Special thanks to vscode-cpptools and vscode-cmake-tools team!

Related

Calling the header file in the parent folder

I'm doing some experiments to learn CMake. So the commands stay in my mind. I created a project to test what I just learned. However, I have a problem.
The structure of my project is as follows:
├── bin
├── CMakeLists.txt
└── src
├── Configuration
│   ├── CMakeLists.txt
│   ├── Test
│   │   └── TestConfiguration.h
├── Array
│   └── Array.h
├── CMakeLists.txt
├── Test2
│   ├── CMakeLists.txt
│   ├── Test2.cpp
│   ├── Test2.h
│   └── Test2-1.h
├── Main
│   ├── CMakeLists.txt
│   ├── Config.h
│   └── Main.h
├── Test3
│   ├── CMakeLists.txt
│   ├── Time.h
│   ├── Timer 
│   │   ├── CMakeLists.txt
│   │   ├── Iterate.h
│   │   ├── Run.h
│   │   ├── Serial.cmpl.cpp
│   │   └── Serial.h
│   ├── Smart.h
│   ├── Counting.h
│   ├── Mute.h
│   └── MainTest.h
└── Utilities
├── CMakeLists.txt
├── Inform.h
├── Settings.h
├── Print.h
└── Const.h
But I didn't understand how I should make these CMakeLists.txt files. For example, the file src/Utilities/Inform.h uses the following header:
// src/Utilities/Inform.h
#include "Main/Config.h"
I've tried everything I've seen on the internet and stackoverflow to edit the src/Utilities/CMakeLists.txt file. But no matter what I do, it never sees the Main/Config.h file. I just need to do something like ../../Main/Config.h.
The same problem applies to other folders. What I want to learn here is to be able to navigate and call all files in the project with CMakeLists.txt. While doing this, I tried many of the following parameters:
add_library
target_include_directories
target_link_libraries
link_directories
link_libraries
I think there's something I'm missing or misunderstood. I would be glad if you help me in this regard. If you tell me how to edit the src/Utilities/CMakeLists.txt file, I will try to fill the others accordingly.
Additionally, there is something I'm curious about. Do I also need to edit the src/CMakeLists.txt file? Or is it enough if I just edit for example src/Utilities/CMakeLists.txt?
Also, I don't know if it will be needed additionally, but I'm using cmake version 3.16.3. My development environment is an x86_64 20.04.1 Ubuntu-based Elementary OS.
I've read the official documentation for CMake 3.16 and the answers from fellow developers on StackOverFlow. I want to use the header file in the parent folder in a header in subdirectories. But many ways I've tried are wrong. There is always an error in the include path I entered. I want to learn from experienced developers what I did wrong.

How to include wxWidgets headers in CMake project

I am trying to run wxWidget example using cmake but unable to include the headers of wxWidgets in my C++ project(CMakeLists.txt). If i run the program using the command
g++ main.cpp `wx-config --cppflags --libs` -o wxTest
the program works and display the window. But how can i do that using CMakeLists.txt file. For example, usually i create a separate folder called external-libs and then inside it create a folder with the name whateverlibraryname and then inside it create a header and src and lib folder where i place the header files, any source files and .so files respectively. But in the case of wxWidgets i have several static library files and also inside the header there are many separate folders and i don't know how to include them all. They produce the error:
fatal error: wx/wx.h: No such file or directory
#include <wx/wx.h>
I am using Ubuntu 18.04 and my project directory structure is as follows:
├── build
└── source
├── CMakeLists.txt
├── external-libraries
│   └── wxWidgets
│   ├── headers
│   │   ├── msvc
│   │   │   └── wx
│   │   └── wx
│   │   ├── android
│   │   ├── aui
│   │   ├── dfb
│   │   ├── generic
│   │   ├── gtk
│   │   ├── gtk1
│   │   ├── html
│   │   ├── meta
│   │   ├── motif
│   │   ├── msw
│   │   ├── osx
│   │   ├── persist
│   │   ├── private
│   │   ├── propgrid
│   │   ├── protocol
│   │   ├── qt
│   │   ├── ribbon
│   │   ├── richtext
│   │   ├── stc
│   │   ├── univ
│   │   ├── unix
│   │   ├── x11
│   │   ├── xml
│   │   └── xrc
│   ├── lib  
├── libwx_baseu-3.1.a
│   │   ├── libwx_baseu_net-3.1.a
│   │   ├── libwx_baseu_xml-3.1.a
│   │   ├── libwx_gtk3u_adv-3.1.a
│   │   ├── libwx_gtk3u_aui-3.1.a
│   │   ├── libwx_gtk3u_core-3.1.a
│   │   ├── libwx_gtk3u_gl-3.1.a
│   │   ├── libwx_gtk3u_html-3.1.a
│   │   ├── libwx_gtk3u_propgrid-3.1.a
│   │   ├── libwx_gtk3u_qa-3.1.a
│   │   ├── libwx_gtk3u_ribbon-3.1.a
│   │   ├── libwx_gtk3u_richtext-3.1.a
│   │   ├── libwx_gtk3u_stc-3.1.a
│   │   ├── libwx_gtk3u_xrc-3.1.a
│   │   ├── libwxjpeg-3.1.a
│   │   ├── libwxregexu-3.1.a
│   │   ├── libwxscintilla-3.1.a
│   │   └── libwxtiff-3.1.a
│   └── src
├── main.cpp
Main.cpp has #include<wx/wx.h> at the top. I am using VSCode and when i ran the program using g++(command described above) it works but doesn't workwhen i run the same program using CMake. That is how to include the header folder and use the lib folder that contains all the wxWidgets headers and library files. What should be the contents of the CMakeLists.txt files and what are the other necessary things that i have to do to make this work.
CMake has first-party support for wxWidgets, here's an example:
cmake_minimum_required(VERSION 3.20)
project(wxTest)
find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
include(${wxWidgets_USE_FILE})
add_executable(wxTest main.cpp)
target_link_libraries(wxTest PRIVATE ${wxWidgets_LIBRARIES})
It's a bit unfortunate how legacy this module is. The above code would be much better off using imported targets and not need to do this weird dance with include(${wxWidgets_USE_FILE}), but alas. At least it's documented.
There are various variables you can set to help it find your wxWidgets installation. See the documentation for more details: https://cmake.org/cmake/help/latest/module/FindwxWidgets.html

Virtualenv for a project with multiple modules

I am trying to build a project from scratch in python 2, it has structure shown below. In past I have created projects with a single hierarchy, so there would be single virtualenv, but this project has multiple subpackages, what is the best practice to be followed: there should be a single virtualenv inside project_root directory shared by all subpackages in it, or there should be separate virtualenv for each subpackage?
project_root/
├── commons
│   ├── hql_helper.py
│   ├── hql_helper.pyc
│   ├── __init__.py
│   └── sample_HQL.hql
├── fl_wtchr
│   ├── fl_wtchr_test.py
│   ├── fl_wtchr_test.pyc
│   ├── __init__.py
│   ├── meta_table.hql
│   ├── requirements.txt
│   ├── sftp_tmp
│   ├── sql_test.py
│   └── sql_test.pyc
├── qry_exec
│   ├── act_qry_exec_script.py
│   ├── hive_db.logs
│   ├── params.py
│   └── params.pyc
├── sqoop_a
│   ├── __init__.py
│   └── sqoop.py
└── test.py
A case could be made for creating separate virtual environments for each module; but fundamentally, you want and expect all this code to eventually be able to run without a virtualenv at all. All your modules should be able to run with whatever you install into the top-level virtual environment and so that's what you should primarily be testing against.

HTMLBars how to get started?

Is there any guide how to start with HTMLBars? I am following "building HTMLBars" section but finally I am stuck. I have run building tool and now I have files in my dist directory like this:
.
├── htmlbars-compiler.amd.js
├── htmlbars-runtime.amd.js
├── morph.amd.js
├── test
│   ├── htmlbars-compiler-tests.amd.js
│   ├── htmlbars-runtime-tests.amd.js
│   ├── index.html
│   ├── loader.js
│   ├── morph-tests.amd.js
│   ├── packages-config.js
│   ├── qunit.css
│   └── qunit.js
└── vendor
├── handlebars.amd.js
└── simple-html-tokenizer.amd.js
Which should I add to my ember project and is that all or have I to do something more? Is this library ready or it is still unusable for ember?
Not even close to ready yet, I'd love to give more info, but there really isn't any. Last I heard they wanted it as a beta in 1.9, but we'll see.

Cython / C++ any repos of good example?

Tried googling this morning - and found this
https://gist.github.com/cournape/1077528
But I ran python3 setup.py install - and that's not what I really wanted. I would like to wrap my c++ in python and not install locally.
So I see
├── build
│   ├── lib.linux-x86_64-3.4
│   │   ├── rectangle.cpython-34m.so
│   │   └── rect.cpython-34m.so
│   └── temp.linux-x86_64-3.4
│   ├── rectangle.o
│   ├── Rectangle.o
│   └── rect.o
├── rectangle.c
├── rectangle.cpp
├── Rectangle.cpp
├── Rectangle.h
├── rectangle.pyx
├── rect.cpp
├── rect.pyx
└── setup.py
Now I can use the module because it's installed - but how would I use it if it was compiled in place?