OpenCV CMake package version error

Problem

I was compiling OpenCV using CMake and it threw up this error:

CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
  CPACK_PACKAGE_VERSION does not match version provided by version.hpp
  header!
Call Stack (most recent call first):
  CMakeLists.txt:1105 (include)

Solution

Open cmake/OpenCVPackaging.cmake file and add the version of OpenCV using a line set(OPENCV_VCSVERSION "2.4.13"). Place the line anywhere above the first use of OPENCV_VCSVERSION.

Advertisements

OpenCV CUDA CMake error

Problem

I was building OpenCV using CMake and got this error:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
opencv_dep_CUDA_nppi_LIBRARY

Solution

The error was related to CUDA and probably some dependency on the NVIDIA Performance Primitives (NPP) library. Since, I needed neither, I rebuilt OpenCV without CUDA support as described here by setting WITH_CUDA=OFF.

OpenCV IlmImf linker error

Problem

I had compiled OpenCV and when I linked my application with OpenCV libraries, I got this error:

undefined reference to `Imf_2_2::globalThreadCount()'

Solution

The Imf in the symbol above seems to be from the IlmImf library that is used to read and write OpenEXR images. Since I had no need for OpenEXR, I recompiled OpenCV with the setting WITH_OPENEXR=OFF. Linking with the resulting OpenCV libraries worked fine.

Current working directory Poco error

Problem

I was trying to build the Poco library when I got this error:

/home/blah/someplace/poco-poco-1.4.6p4-release/build/rules/global:62: *** Current working directory not under $PROJECT_BASE.  Stop.
make[1]: Leaving directory

The same code had built successfully on another computer, so I knew there was nothing wrong.

Solution

Turns out that this error is actually caused if the path where you have unzipped Poco has a symlink in it. The someplace directory above was actually a symbolic link. Once I copied Poco to a path which had no symlink, it compiled fine.

Unrecognized relocation error

Problem

Building a large project that involved linking with many libraries, I got this linking error:

Linking CXX shared library ../../lib/libfoobar.so
/usr/bin/ld: /somepath/opencv-2.4/lib/libopencv_imgproc.a(clahe.cpp.o): unrecognized relocation (0x2a) in section `.text._ZN12_GLOBAL__N_1L15CLAHE_Impl_infoEv'
/usr/bin/ld: final link failed: Bad value

Solution

At first I suspected some problem with the symbol that you see the linker complaining about above. But using nm I found that the symbol was present and was defined in the archive library file.

Only after eliminating all other possibilities did I discover that the problem was the compiler version. The archive library file had been compiled using GCC 4.8. The linking was being done on a different computer where the compiler was GCC 5.x. The C++ ABI had changed along with the major version difference between the two compilers and this was causing the problem.

Once I rebuilt OpenCV with GCC 5.x and used its archive library file, the linking proceeded smoothly.

NVCC argument redefinition error

Problem

I was trying to build a CUDA project that worked on one computer on a second computer. Though this project built without problems on the first computer, nvcc gave an argument redefinition error on the second computer:

nvcc fatal   : redefinition of argument 'std'

Solution

At first, I thought that the compilation error was arising from the source code. Actually, the error is being reported about a compilation argument to nvcc. It is saying that a std argument has been provided more than once.

This project was using CMake, so the actual compilation commands invoked by make are hidden. I used the VERBOSE trick, described here, to view the actual commands issued to the C++ and CUDA compilers. Not surprisingly, I found that the -std=c++11 argument was being passed twice. But why?

I checked the CMakeLists.txt file and found that indeed the C++11 argument was being passed to the compiler twice by setting it in both CMAKE_CXX_FLAGS and CUDA_NVCC_FLAGS. How and why was this working fine on the first computer? Turns out that the older CMake used on the first computer would not pass the C++ flag to NVCC, so it had to be specifically redefined for CUDA compiler flags.

The second computer was using a newer version of Ubuntu, with newer version of CMake. This was intelligent enough to pass a C++ flag to the CUDA NVCC compiler too. But since the NVCC flag of the same name also existed, it was causing the argument redefinition error. Removing the flag from the CUDA flags made the problem go away.

How to broadcast using wall

There are times when you wan to send a message to the users logged in and using a server machine. The classic wall command is useful for that scenario. The message you send will appear at every interactive shell of every user on the machine. The best thing about this command is that no special chat or messenger client is required.

  • Wall is a classic Unix command and should be installed as part of the bsdutils package. In case you don’t have it:
$ sudo apt install bsdutils
  • Broadcasting a message is easy:
$ wall "hello folks, server will be shutdown at 1PM"

It would have been nice if this command could be used to address one specific user or a subset of users, but that is not possible.

How to discover type hierarchy in Python

Given any type in Python, you can easily discover its ancestor and descendant types. This ease of discovery of the internals of the language is one of my favorite features of Python.

  • Remember that all types are descended from the object type.

  • Even type is a type and it is a child of the object type.

  • The __base__ attribute of any type has a string value with the name of the parent type.

  • The __subclasses__ method of any type lists the child types.

  • To determine which are the standard types (or builtin types or builtins as they are called in Python), check the __module__ attribute of the type. If it is builtins in Python 3 or __builtin__ in Python 2, then that is a standard type.

  • If you start from object, you can actually list the entire type hierarchy tree. A script that does just that can be found here.

  • In Python 3.5.2, I found that there are 143 builtin types (most of them are just types of Exception) in the tree:

object
+-- type
+-- dict_values
    +-- odict_values
+-- tuple_iterator
+-- set
+-- fieldnameiterator
+-- frame
+-- dict_keyiterator
+-- PyCapsule
+-- coroutine
+-- bytearray
+-- NoneType
+-- list
+-- dict
+-- getset_descriptor
+-- method-wrapper
+-- method
+-- str_iterator
+-- formatteriterator
+-- str
+-- set_iterator
+-- range_iterator
+-- memoryview
+-- cell
+-- generator
+-- map
+-- list_iterator
+-- stderrprinter
+-- reversed
+-- method_descriptor
+-- code
+-- weakproxy
+-- int
    +-- bool
+-- ellipsis
+-- module
+-- dict_items
    +-- odict_items
+-- bytearray_iterator
+-- Struct
+-- moduledef
+-- filter
+-- staticmethod
+-- tuple
+-- frozenset
+-- managedbuffer
+-- coroutine_wrapper
+-- function
+-- builtin_function_or_method
+-- odict_iterator
+-- float
+-- range
+-- super
+-- dict_keys
    +-- odict_keys
+-- list_reverseiterator
+-- bytes_iterator
+-- member_descriptor
+-- wrapper_descriptor
+-- property
+-- instancemethod
+-- zip
+-- weakref
+-- slice
+-- longrange_iterator
+-- dict_valueiterator
+-- EncodingMap
+-- callable_iterator
+-- mappingproxy
+-- BaseException
    +-- Exception
        +-- TypeError
        +-- StopAsyncIteration
        +-- SyntaxError
            +-- IndentationError
                +-- TabError
        +-- AttributeError
        +-- AssertionError
        +-- StopIteration
        +-- MemoryError
        +-- BufferError
        +-- NameError
            +-- UnboundLocalError
        +-- LookupError
            +-- IndexError
            +-- KeyError
        +-- EOFError
        +-- ImportError
        +-- ValueError
            +-- UnicodeError
                +-- UnicodeEncodeError
                +-- UnicodeDecodeError
                +-- UnicodeTranslateError
        +-- RuntimeError
            +-- RecursionError
            +-- NotImplementedError
        +-- SystemError
        +-- Warning
            +-- UserWarning
            +-- DeprecationWarning
            +-- BytesWarning
            +-- SyntaxWarning
            +-- PendingDeprecationWarning
            +-- FutureWarning
            +-- ResourceWarning
            +-- ImportWarning
            +-- RuntimeWarning
            +-- UnicodeWarning
        +-- ReferenceError
        +-- OSError
            +-- ConnectionError
                +-- BrokenPipeError
                +-- ConnectionAbortedError
                +-- ConnectionRefusedError
                +-- ConnectionResetError
            +-- BlockingIOError
            +-- NotADirectoryError
            +-- PermissionError
            +-- FileExistsError
            +-- TimeoutError
            +-- IsADirectoryError
            +-- InterruptedError
            +-- ProcessLookupError
            +-- FileNotFoundError
            +-- ChildProcessError
        +-- ArithmeticError
            +-- FloatingPointError
            +-- OverflowError
            +-- ZeroDivisionError
    +-- GeneratorExit
    +-- KeyboardInterrupt
    +-- SystemExit
+-- dict_itemiterator
+-- classmethod
+-- NotImplementedType
+-- iterator
+-- bytes
+-- enumerate
+-- classmethod_descriptor
+-- complex
+-- traceback
+-- weakcallableproxy
  • Note how bool is a child type of the int type.

  • In Python 2.7.12, I found that there are 60 builtin types in the tree:

object
+-- type
+-- weakref
+-- weakcallableproxy
+-- weakproxy
+-- int
    +-- bool
+-- basestring
    +-- str
    +-- unicode
+-- bytearray
+-- list
+-- NoneType
+-- NotImplementedType
+-- traceback
+-- super
+-- xrange
+-- dict
+-- set
+-- slice
+-- staticmethod
+-- complex
+-- float
+-- buffer
+-- long
+-- frozenset
+-- property
+-- memoryview
+-- tuple
+-- enumerate
+-- reversed
+-- code
+-- frame
+-- builtin_function_or_method
+-- instancemethod
+-- function
+-- classobj
+-- dictproxy
+-- generator
+-- getset_descriptor
+-- wrapper_descriptor
+-- instance
+-- ellipsis
+-- member_descriptor
+-- file
+-- PyCapsule
+-- cell
+-- callable-iterator
+-- iterator
+-- EncodingMap
+-- fieldnameiterator
+-- formatteriterator
+-- module
+-- classmethod
+-- dict_keys
+-- dict_items
+-- dict_values
+-- deque_iterator
+-- deque_reverse_iterator
+-- Struct
  • Note how str and unicode are child types of the basestring type. Also observe how this differs from Python 3 builtin types.

  • Also notice how in Python 2 the exception types are not builtin types.

Gramps Genealogy Program

Gramps is a great open source tool to create, maintain and visualize your family tree. I had a great time asking around my family about our ancestors and exporting beautiful ancestor tree diagrams and descendant tree diagrams.

  • You can install an old version directly from Ubuntu repositories:
$ sudo apt install gramps
  • Or you can download the latest .deb file from here and install it:
$ sudo dpkg -i gramps_you_downloaded.deb
  • When you first open it, it asks you to create a family tree. This is the document inside which you can maintain one family tree. Give it any name you wish.

  • On the left are different views into your family tree. Out of these, I found that I can get by using just People, Relationships and Charts tabs.

  • Add a person: Start off by adding entry for one person (say your earliest ancestor or yourself) by going to the People tab and then choosing + (Add a new person) option in the topbar. You can enter Given Name, Surname and in the Events section at the bottom, add a Birthday. Get used to this dialog, you will be seeing it a lot when adding or editing people to your tree.

  • Add a relationship: Click a person’s entry in the People tab and then switch to the Relationship tab to add partners (spouse) and children. Choose Edit → Add a Partner to add a spouse and their details. At the bottom of that dialog, you can add one or more Child entries.

  • Charts: Switch to Charts view to see ancestor tree of a chosen person. The default side view is quite confusing to me. I like to change the chart view by choosing View → Configure and choosing Vertical ↑ as the Tree Direction. This ancestor tree view looks more intuitive to me. You can double-click any unfilled ancestor box to add that person to the tree.

  • Ancestor tree: A beautiful ancestor tree for any person (say you or your child) can be exported to PDF. Select the person in any view and choose Reports → Graphical Reports → Ancestor Tree. Note that there is an option in there to resize the PDF to fit the entire tree. You can later convert the PDF to PNG using ImageMagick tools, like described here.

  • Descendent tree: A beautiful descendant tree for any person (say your oldest ancestor) can be exported to PDF. Select the person in any view and choose Reports → Graphical Reports → Descendant Tree.

Tried with: Gramps 4.2.6 and Ubuntu 16.04