Missing Standard Library Components - c++

I'm currently working on a project with C++17 and I have trying to make use of certain libraries (such as variant and optional). However, my IDE cannot find these (I'm using CLion). What would be the best way to debug this issue? I want to know if I truly do not have these installed (although they are part of the STD Library so I would think this unlikely) or if there is an issue with my editor...

Related

Find the correct version of libraries

I'm trying to do a static build for an open-source project and I'm getting lots of errors while I try to build it.
How do I find the correct version of a library that the project is using?
I also tried to read the Makefile but I couldn't understand much from it. So is there any workaround or anything like that which makes the work easier?
AFAIK there is no way to find it out. It's not just the version. Many libraries can be built with different flags. You have to know the supported versions and necessary flags. For this purpose package managers were invented. Each package has meta information describing the dependencies.
Someone wrote a code using a library. If you want to use the code you have to use a compatible library. You can't find it out from the code. You can ask the developer, read the documentation or look into the package description. If you can't find a documentation of the dependencies you can try different versions and flags. This can cause crashes, undefined behavior or it works if you're lucky and you found a compatible version.

Possible to create a DYLIB from a C++ DLL project?

I have a C++ project that was used to create a DLL. Is it possible to take that C++ code and create a DYLIB file? I have only done a tiny bit of work with C++, so I am not sure if this can easily be done. Basically, I have an app that I rewrote in Python so I could run it on Windows or macOS. The Windows version of the app is able to use the DLL without a problem. Now, I would like to use the library with the macOS version of the app.
In general, of course, it is possible. However, whether it will be an easy job or not depends on whether how the library was written.
In the best case: you only need to recompile the library in macOS following its build instructions (e.g. typically explained in the documentation or in a README-style file in the root of the project).
In the worst case: the library is not portable at all (e.g. depends on the Windows API) and you won't be able to use it without rewriting it.
A side question is whether you really need the library: it is possible that you can find a Python library to fulfill the same job.

Conditionally compile if boost is present

I want to conditionally compile some c++ code that uses boost, and make it so it doesn't try to compile the boost dependent code if boost is not present.
Does boost have any global macro that will be defined, like __BOOST__, that I can check for?
EDIT: It's clear to me now that I have to achieve this on the makefile level. I am working on OSX lion. Using gnu make
The TYPICAL way that this is done is to use a "configuration script" or similar, that detects if the required/optional component(s) is/are present, and then selectively sets some -D options to the build system.
Obviously, if it's just your own project or a small distribution, you could do the same thing manually.
You probably also need a couple of ifdef type of choices in the Makefile if there are library files that you need.
One of the easier ways to determine if a part of boost that you need is installed is to try to compile it. If there are errors, the likely cause is that that part of boost isn't present (this obviously doesn't work if there are more important parts missing - for example, not having a compiler or standard library installed will ALSO cause a compile to fail. This is why nearly all configure type tools "start with the most basic features, and work their way up the tree of dependencies").

Using Boost Pre-build package

I want to use Boost.Thread library in a C++ software that I'm developing.
Since I'm a complete newbie in C++, I would like to know if there are any differences between:
Downloading and building Boost manually for MSVC9-x64
Using a pre-built package: http://boost.teeks99.com/
Option 1 seems so painful...
As far as I can tell, these are the default builds and not from patched or tweaked sources or anything.
If you take care to use the correct version of binaries for your application target and version of VC (including service packs) and link against the correct libraries (shared, static CRT, debug, etc.) you should be absolutely fine.
Also, since it seems that these packages don't contain Boost headers, you must take care to get and use the correct version of headers.
Concerning the "differences". Boost is a large and complex collection of libraries. For a software of that size, it has a quite simple and straightforward build process, but still, there are many options and customizations you can do when building Boost (e.g. you can build Boost.Iostreams with or without zlib and bzip2 support, build Boost.Regex with or without Unicode support, build Boost.Python against different versions of Python, and much more.) When you build Boost, you have control over these options.
The defaults work for most people, but some people may need certain customizations. You might want a specific version of a specific optional dependency, or a certain library built a certain way. For that, you probably will need to build Boost yourself and maintain the build throughout your project. This is not a scary task!
If you don't have any special requirements, then a generic build would most probably be fine for you.

How can I learn to include and link to libraries?

I'm trying to teach myself C++ programming. The C++ is the easy part. Some patience and good reference material goes a long way. Including and linking against libraries is the hard part. The instructions provided usually assume some knowledge which I don't have and don't know how to aquire without painfully slow trial and error.
The latest concrete example is http://cpp-netlib.org/
I've spent the whole afternoon trying to get it to work and I still don't even an idea why it's not working.
How can I learn this skill from the ground up?
Is it it normal to have such enormous difficulties learning how to do this?
Well, the principle is pretty much always the same for any C++ compiler (the option flags mentioned are quite standard but might differ for particular compilers):
Install a library you want to use in your system (this may include a step to compile this library with your particular compiler toolchain).
Setup the include paths to be used for this library using the -I option
Use the headers of the library API in your code (#include <libheader.h>)
Setup the library paths to be used for this library using the -L option, tell the linker which libraries to link using -l<extra>, where extra should refer to some file named lib<extra>.a or lib<extra>.lib
Things to note:
Third party libraries might depend on further libraries you'd also need to install (compile with the same toolchain as your target uses)
On Windows using the MS Visual Studio (Express) toolchain you'll need to take care choosing the right library versions that are compliant with the 'threading model' and in general 'debug' / 'non-debug' library versions.
An (appropriate and useful) IDE will usually let you choose the toolchain (MinGW GCC, MS VS compiler, LLVM, etc.) on project setup, and offer some properties dialog to set these options.
What's necessary to setup for the toolchain, 3rd party libraries, IDE and OS you're using is a bit different learning curve and depends on what you want to use in particular.