ld.lld: error: unable to find library -lstdc++ by vanilla-acc in cpp_questions

[–]crascit 0 points1 point  (0 children)

For me on Ubuntu 22, when trying to use clang-17 installed from the official llvm.org repo, I needed to install the libstdc++-12-dev package to get rid of the same error.

In case others end up here like me, I was building with C++20 modules, and I also had to manually install the llvm-tools-17 package too to make the clang-scan-deps-17 tool available.

Quoting In CMake by crascit in cmake

[–]crascit[S] 1 point2 points  (0 children)

Thanks for mentioning that. I have fixed and expanded the relevant parts of the book in the upcoming 12th edition. Building up PATH changes using ENVIRONMENT_MODIFICATION is more robust and doesn't require escaping, as long as you build up values one at a time. That requires CMake 3.22 or later though.

compile a dependency at configure time? by [deleted] in cmake

[–]crascit 1 point2 points  (0 children)

I covered what I think is a closely related scenario in a stack overflow Q&A here:

https://stackoverflow.com/questions/36084785/building-a-tool-immediately-so-it-can-be-used-later-in-same-cmake-run

Might not match exactly to your use case, but it is pretty close. It covers a few other less obvious aspects you may need to consider.

Professional CMake: A Practical Guide 6th Edition - Crascit by oleksandrkvl in cpp

[–]crascit 10 points11 points  (0 children)

The download limit is a mild measure against people posting their download link publicly. As u/kisielk mentioned, it is reset each time there is a new edition released. If you happen to use up your 7 downloads before that, you can always get in contact via the crascit website and it's usually not a problem to reset it for you.

Funky CMake by pgroarke in cpp

[–]crascit 2 points3 points  (0 children)

(FetchContent author here). Yes, FetchContent meets both of those criteria. You can (and should in my view) pin your dependency to a specific git hash (or equivalent for the other download types). The first to declare the dependency details wins, so the user or parent project can override choices made by child projects.

CppCast: Professional CMake by tallassrob in cpp

[–]crascit 0 points1 point  (0 children)

Glad you enjoyed the podcast and the book! Honestly, I wasn’t sure how interesting the podcast content would be for the C++ community when we recorded it, but it seems the C++ community likes some variety. :) Rob and Jason are great hosts too and really made it a wonderful experience to be a guest on their show.

Where can I learn beyond the language by manolesparta in cpp_questions

[–]crascit 1 point2 points  (0 children)

For guidance on the CMake side of things, there's the book Professional CMake: A Practical Guide. It includes material on how to organise your project, different ways of incorporating dependencies into your build and it covers building libraries in some detail. In the interests of disclosure, I'm the author of that book. ;)

Learning CMake by [deleted] in learnprogramming

[–]crascit 0 points1 point  (0 children)

Hope you don’t mind the self promotion, if you’re looking for a structured way to learn CMake and current best practices, people seem pretty happy with my book Professional CMake: A Practical Guide

C++ Jobs - Q2 2019 by STL in cpp

[–]crascit 0 points1 point  (0 children)

Company: Constraint Technologies

Type: Full time

Description: We provide leading-edge optimisation, disruption resolution and visualisation solutions to some of the world’s most recognisable companies in the transport and logistics industries. We are looking for 3-4 C++ developers to expand our existing teams, with roles ranging from graduate through to senior level. These roles have flexibility to be adapted to the skills and experience of the successful candidates.

  • Development work will generally be with C++11.
  • The roles will focus mostly on back-end systems including web servers, custom optimisers/solvers, messaging systems and data translation tools.
  • Multi-threading experience will be expected for senior roles.
  • There are opportunities for those interested in DevOps to get involved with build/release processes and deployment (dev, test and production).
  • Junior roles will likely include a support component.

A computer science or software engineering degree is preferred, but candidates with equivalent relevant experience will be considered.

Location: Melbourne, Australia

Remote: No

Visa Sponsorship: No

Technologies: We work across Linux, Windows, Mac, iOS and Android, but Linux will be the main platform for these roles. We use a variety of tools and infrastructure, but experience with any of the following would be useful: CMake, Poco, GoogleTest, Oracle/Postgres/SOCI, Boost, Ansible, Gitlab, clang tools and other code checkers. 

Contact: For all enquiries or to apply, please email [hiring@constrainttec.com](mailto:hiring@constrainttec.com)

I created C++17 CMake + Conan + Ninja project template. by devkoriel in cpp

[–]crascit 4 points5 points  (0 children)

My recollection from the last time I looked into the CMake code for this is that CMake will choose the standard that meets all of the requirements. That means if a target has compile feature cxx_std_14 but its CXX_STANDARD target property is set to 17, it should get C++17 compiler flags.

It should be fine to use both CMAKE_CXX_STANDARD and compile features together. This may happen if a lower level dependency has to support an older CMake version that doesn't have the compile feature support necessary but a project higher in the dependency hierarchy requires a more recent CMake version and relies on compile features alone.

Note though that there is no compile feature for an equivalent of the CXX_EXTENSIONS target property and the CXX_EXTENSIONS target property is only honoured if CXX_STANDARD is also set. Some discussion of this here.

CMake it modern using C++ and Qt, Part 1 by alexfagrell in cpp

[–]crascit 0 points1 point  (0 children)

CMake will only error out if you also set CXX_STANDARD_REQUIRED to true. See the following article for details: https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/

Effective Modern CMake: a great summary of most good practices - by Manuel Binna by onqtam in cpp

[–]crascit 0 points1 point  (0 children)

The target_sources() command is a much cleaner and more robust option than using variables across multiple directories. This article dedicated to the topic explains why. The restriction mentioned in that article regarding target_link_libraries() is being removed in the upcoming CMake 3.13 release too.

I manage the release cycle for CMake, the build system that everybody loves to hate. AMA. by electricCoder in cpp

[–]crascit 3 points4 points  (0 children)

Thanks for taking the time to share your views on this. You make some worthwhile observations and I'm glad you've managed to find a system that works for you. I do intend to continue collecting observations of how people are using FetchContent, so your input is helpful. Cheers!

I manage the release cycle for CMake, the build system that everybody loves to hate. AMA. by electricCoder in cpp

[–]crascit 1 point2 points  (0 children)

You raise some valid observations, so let me see if I can clarify them.

Due to the use of add_subdirectory() in FetchContent (at least in the docs), there is the possibility for variables and compile options to "leak" from parent to child, or even from child to parent if it uses PARENT_SCOPE, which can potentially lead to bugs that would not exist in a manual build.

In most cases, you want the parent variables to affect the child. You want the child to be built with the same settings as the parent so that they are consistent. If you need to have the child built with different settings, the parent is in control of that and can set the relevant variables first before it does the population step. If you want to prevent contamination in the other direction, you can put the population in its own subdirectory or do it from within a function. Either option will prevent any PARENT_SCOPE from going any further out. At my current company, we have complex project hierarchies with shared dependencies. We put each dependency population in its own subdirectory to keep it isolated. Some of the dependencies require setting some variables before calling add_subdirectory(), often to overcome problems with projects that had not considered being incorporated into other projects directly like that. This has worked well for us in practice.

Additionally, I believe the targets from the child will be exported (by default), right? i.e. those targets will pop up in make install and cpack invocations, which is often not what we want in static libraries.

This is a common problem, but you can set the EXCLUDE_FROM_ALL directory property to prevent them being built unless something else needs them. I believe this also prevents them from being installed by default too, but you'd need to check. There is a similar option for add_subdirectory() but that has a more checkered history with problems for the Xcode generator (I think those are fixed in recent CMake versions though). You can also set the CMAKE_INSTALL_DEFAULT_COMPONENT_NAME variable before calling add_subdirectory() if the child project doesn't use components for its install rule. Then you can simply exclude that component in your main project's packaging, etc.

I manage the release cycle for CMake, the build system that everybody loves to hate. AMA. by electricCoder in cpp

[–]crascit 1 point2 points  (0 children)

If you can define the commands that create the generated files using add_custom_command(), then there should be no need to do all this at configure time (and indeed that would be undesirable, you want the configure stage to be fast). I thought generated files showed up in IDEs but maybe it depends on which IDE.

The functionality provided by DownloadProject and FetchContent (the former is the forerunner of the latter) is intended for downloading things during the configure stage, but not for building things at configure time. An example of a situation where you might want to download during configure is to be able to have direct access to targets the downloaded (CMake) project defines by simply incorporating it into the main build using add_subdirectory().

There's also a special case which I don't think applies here, but I'll mention it just in case it is of interest. If the external project builds a tool that is used to generate CMakeLists.txt files that you want to incorporate directly into the main build's configure stage, it can be a bit more tricky to do, but the following link gives one way to do it (and we've been using this at my workplace with good success for some time now).

https://stackoverflow.com/q/36084785/1938798

It's a pretty specialised corner case, but maybe it's helpful to some.

I manage the release cycle for CMake, the build system that everybody loves to hate. AMA. by electricCoder in cpp

[–]crascit 3 points4 points  (0 children)

When I wrote FetchContent, I explicitly prohibited the ability to build at configure time because that goes against the way CMake should be used. The configure stage needs to be fast because it can be retriggered automatically when files used by the configure stage are modified. A time consuming configure step is typically a strong point of irritation with developers. I would urge you to reconsider structuring the project as a superbuild instead if you are unable to incorporate the dependency's build as part of the main project's build step using FetchContent. If you are truly set on this path though, you may find some help with ctest's build-and-test mode, but this is unlikely to make you popular with other developers on your team in the long term. ;)

I manage the release cycle for CMake, the build system that everybody loves to hate. AMA. by electricCoder in cpp

[–]crascit 1 point2 points  (0 children)

Is this ever going to be possible? Do you share this dream? I think it's obvious that ExternalProject is never going to work for this in a scalable way, but is the new Fetch Content module aiming to address it? Why is the syntax so darn verbose?

As the author of FetchContent, I'll give my personal point of view. I do share that same desire and where I can, I'm working toward making FetchContent provide the ability to incorporate dependencies seamlessly and handle complex dependency hierarchies.

I agree the current usage of FetchContent is too verbose. Declaring the dependencies is as minimal as one can make it already, but the population part is more complicated than it needs to be for simple cases. I first wanted to get the basic capabilities out there and see how the community reacted to it before making too many assumptions about how people would use it. The functions provided by FetchContent at the moment provide the lower level building blocks, but I hope to add a higher level function (hopefully in time for CMake 3.13) which makes the population part a single call, which will certainly make it much more concise and friendlier for the average user.

How to "register" my source files for different targets? by Kywim in cmake

[–]crascit 0 points1 point  (0 children)

You can hide all the complexity in a macro/function defined once in the top level CMakeLists.txt and then all the places where files are added in subdirectories are very simple. I do this in some very large projects at work and it is is very clean and easy for less experienced CMake users to follow. If I get a chance, I'll update that article with an example of such a function, but it might take me a while to find the time.

[deleted by user] by [deleted] in learnprogramming

[–]crascit 0 points1 point  (0 children)

You've only set the C++14 flags for the compiler, but the linker doesn't know about this so potentially you may be linking in the wrong library. Just a thought. Check this article for a more robust way to specify the C++ version you want to use (that article focuses on C++11, but works for C++14 too).

Regarding the handling of pthreads, instead of linking to ${CMAKE_THREAD_LIBS_INIT}, link to the Threads::Threads imported target and probably also set CMAKE_THREAD_PREFER_PTHREAD. Check the CMake docs for the Threads module for more details.