Posts

Conan: Unknown MSVC compiler version

This error had been causing my team heartburn for a while.  Previously, we kicked the problem down the road using this in our main CMakeLists.txt: set(MSVC_VERSION 1919) But, finally, I ran into a situation which forced me to figure it out.  With the above workaround in place, I had started getting these errors from one of the Conan packages I was including: The C compiler identification is unknown The CXX compiler identification is unknown When I dug into the CMake error log, I got a bit more specificity: LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib' The offending bit of code in CMakeLists.txt turned out to be this: if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")    file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.9/conan.cmake"                  "${CMAKE_BINARY_DIR}/conan.cmake") endif() This code, copied from t

Designing a C interface for complex types

  Let’s say we are designing an interface to pass a complex type between C++ modules. If there is any possibility of the two modules being built by different compilers, different versions of the same compiler, or for different platforms, we’ll need to use C functions & structures for the interface.  The same is true of C++ to another language. As an example, let’s say our module houses a lookup we want to share: If we wanted to make this lookup available to another module, due to reasons previously stated, we can’t pass our nice C++ types. So, we would need something like this:     So, the implementation of the external-facing function could look something like this:       The code in the caller would look something like this     I don’t love this approach. To be honest, I’ve never liked returning values via parameter. Especially, in functions with several parameters, I think using return values is much clearer to the reader. In this case, it also puts a numbe

Fixing Conan Lock Issues

I've been implementing Conan as our C++ package manager, and I had the following issue cause me a fair amount of grief over the last couple days: [MyPackageName] is locked by another concurrent conan process, wait... If not the case, quit, and do 'conan remove --locks'  You would be forgiven for thinking conan remove --locks should do the trick, but alas, it does not.  After finding hints on several Conan Github issues, I finally figured out that manually removing the package folders in one or both of the following places will alleviate the issue: Windows : C:\Users\username\.conan\data\packagename WSL/Linux : /home/username/.conan/data/packagename

Writing C++ Shared Libraries for Linux

I've recently been getting an old Windows-only module cross compiling for Linux. One of the challenges has been figuring out how to make the consuming project find & properly open the .so file. Most posts suggest that you must put your libraries in a specific folder, but a developer friend with stronger Linux kung-fu than mine confirmed that you can simply drop the .so files in the same directory as your application, & consume them using dlopen. Here's a couple examples: first, a trivial hello world to show the basic consumption, and second, an example of what a reusable interface might look like. The latter shows how to use custom parameter & return types. I am new to designing C interfaces and deploying on Linux, so any comments are welcome. Hello World from a Linux shared library: Passing an interface from a Linux shared library:

With Great Power Comes Great Responsibility

We have failed society, and society has noticed.  Code now powers injustice around the world.... The New York Times recently published an interactive article titled " The Decade Tech Lost Its Way ".  The headline brought to mind a topic I've reflected on often over the past few years.  We have had a decade of headlines exposing aid of government oppression in China by Google, utter disregard for privacy from Facebook, profit-margins above human well-being at Amazon, and many more. The list is not limited to big tech either.  Praiseworthy investigative journalists brought us stories ranging from massive location data-sets collected by dozens of small, obscure companies , to human rights abuses using facial recognition & cell phone spyware by world powers - specifically China & India . (China has now moved people targeted by this technology into brainwashing camps .)  And, of course, abuses of power by my own government as well . These stories both sadden

Using Enums to Replace #define's with Strongly-typed Variables

C++ Map With Multiple Keys

I recently had need for a C++ collection which could be accessed with multiple keys.  Specifically, I had an object that I wanted to look up either by name or id (in O(1) time).  One way to do this is to create two unordered_maps – one keyed by id and another by name, but that is error-prone.  I ended up finding a boost class which will do this. It took me a while get it working, so I thought I would share the result.