Path error when building with Conan and CMake

I recently encountered a mysterious path error when attempting to build a C++ project on Windows using Conan and CMake. The main error message wasn’t particularly helpful though:

 ERROR: (my-project/1.0@None/None): Error in build() method, line 71
        ConanException: Error 1 while executing cd C:\path\to\repo\build && cmake -G "Visual Studio 15 2017 Win64" ...
20190718 15:00:46 : ERROR : Problem: conan_build: 1
20190718 15:00:46 : ERROR : Exit: 1

I’ve edited the message for brevity and to avoid sharing details of exactly which project it was. The main point is that Conan encountered the error when it was trying to run a shell command. The shell command was attempting to enter a build directory and invoke CMake. I tried to run the command manually and it worked correctly so something strange was going on behind the scenes.

Read more Path error when building with Conan and CMake

Workaround for nvcc pthread issue

I recently upgraded various pieces of software on my work PC. Afterwards, I found that our C++/CUDA projects wouldn’t build. The following error was reported:

nvcc fatal   : Unknown option 'pthread'

I was attempting to build it in CLion 2018.2.5 using the bundled CMake 3.12.2. My OS is Ubuntu 18.04 and I’m using CUDA 9.1.

So far, I haven’t been able to find a proper solution. However, I have found a simple workaround. If you know of a better solution then please let me know in the comments!

Read more Workaround for nvcc pthread issue

Decimal places in a floating point number

Floating point numbers are a mainstay of programming in areas such as games, graphics, and simulation. On the whole, they are easy and intuitive to use. However, they have certain quirks and issues to be aware of. For example, their representation is inherently flexible and often approximate. This means there’s no definitive answer to the question of how many decimal places they can hold.

By looking at the way floating point numbers are stored, it’s possible to understand why this happens, and what precision is likely to be available. Hypothetically, it’s possible under certain circumstances to get up to about 45 decimal places in a C++ float, and 324 in a double. However, as we’ll see in this post, it depends on context.
Read more Decimal places in a floating point number

C++ constexpr functions

I’ve been very excited to see that Visual Studio 2015 supports the constexpr keyword in C++. It was introduced in the C++11 standard, and is being taken further in upcoming revisions.

There are a number of uses for the keyword, but the one which excites me the most is using it for writing functions which can be executed during compilation, potentially saving a lot of runtime overhead. In this post, I’ll show a couple of quick examples.
Read more C++ constexpr functions

Using C++ templates for size-based type selection

The standardisation of size-specific integer types in C/C++ is extremely useful for portability. That is, when you use types like uint16_t and int32_t, you know exactly what size of data type you’re getting (assuming your compiler supports it, which is usually the case unless you’re working with very specialist/embedded systems). This isn’t the case with the more traditional types like short and int whose sizes can vary from one compiler to another. However, the size is obviously part of the type name, meaning you need to alter declarations directly if you want to use a type of a different size.

Using the std::conditional template from C++11 lets you change this. Instead, you can have a template parameter which specifies the size you want (e.g. in bytes). The corresponding type declaration can be automatically deduced from there.
Read more Using C++ templates for size-based type selection

Order of parameter evaluation in C++

The low-level details of how data gets passed into a function are often overlooked by programmers. We obviously care about passing parameters by value vs. reference, and perhaps also by copy vs. move, but it’s easy to ignore anything deeper than that.

With C++ in particular, this can cause an unexpected problem regarding the order in which things actually happen. In this post, we’ll look at what can go wrong, and how to deal with it.
Read more Order of parameter evaluation in C++

Tagged with