AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Bazel vs cmake3/21/2023 The shared objects themselves do not specify their dependencies. The executable does not link against shared objects. $ readelf -a bazel-bin/libf2.so | grep -e NEEDED -e RUNPATH $ readelf -a bazel-bin/libf1.so | grep -e NEEDED -e RUNPATH $ readelf -a bazel-bin/main_test | grep -e NEEDED -e RUNPATH However, if we look closely we will see that few things are missing $ readelf -a bazel-bin/main | grep -e NEEDED -e RUNPATH The above setup can be replicated with a simple BUILD file using Bazel: cc_library(Īs a result we will see both static and shared libraries created: $ tree -L 1 bazel-bin/ The result is similar to what can be achived with manual steps: $ tree -L 1 build-cmake/ Using public will result in the executable having both f1 and f2 specified in NEEDED tags.Īdditionally the VERSION and SOVERSION properties are set for the library targets, so that they have a proper shared object name and symlinks are automatically created.ĬMake by default does not build shared libraries and needs to be instructed to do so: $ cmake -B build-cmake. This will prevent CMake from transitively forwarding the dependencies of f1 to all targets that depend on f1. Notice the usage of PRIVATE keyword for f1 dependencies. Additionally by using target_link_libraries, the dependency chain is created. Standard command add_library and add_executable are needed. The manual process above can be reproduced using CMake: cmake_minimum_required(VERSION 3.22) $ readelf -d build/f1/libf1.so.0.1 | grep -e NEEDED -e RUNPATHĠx000000000000001d (RUNPATH) Library runpath: Building shared libraries with CMake However, looking at dynamic tags, it is clear that the f2 dependency comes directly form f1. So both libraries, f1 and f2 are correctly found. Linking an executable, to library f1 will result in the following output from ldd: $ ldd build/main In both cases the SONAME of the dependency will be embedded into the resulting library's DT_NEEDED tag. First, the object files need to be created: "$/build/f2" -lf2 \ ![]() Passed 0.A shared library is a collection of object files that contain usable symbols, which are loaded by the dynamic linker when running an executable. my_project/buildġ/1 Test #1: HelloTest.BasicAssertions. The CXX compiler identification is GNU 10.2.1 The C compiler identification is GNU 10.2.1 Now you can build and run your test: my_project$ cmake -S. Last two lines enable CMake’s test runner to discover the tests included in the You want to build ( hello_test), and links it to GoogleTest ( gtest_main). The above configuration enables testing in CMake, declares the C test binary ) include (GoogleTest ) gtest_discover_tests (hello_test ) With GoogleTest declared as a dependency, you can use GoogleTest code withinĪs an example, create a file named hello_ in your my_project Hash often to point to the latest version.įor more information about how to create CMakeLists.txt files, see the The Git commit hash of the GoogleTest version to use we recommend updating the The above configuration declares a dependency on GoogleTest which is downloadedįrom GitHub. ) # For Windows: Prevent overriding the parent project's compiler/linker settings set (gtest_force_shared_crt ON CACHE BOOL "" FORCE ) FetchContent_MakeAvailable (googletest ) You’ll use this file to set up your project and declare a dependency onįirst, create a directory for your project:Ĭmake_minimum_required (VERSION 3.14 ) project (my_project ) # GoogleTest requires at least C 14 set (CMAKE_CXX_STANDARD 14 ) include (FetchContent ) FetchContent_Declare ( Set up a projectĬMake uses a file named CMakeLists.txt to configure the build system for a Note: The terminal commands in this tutorial show a Unix shell prompt, but theĬommands work on the Windows command line as well. If you don’t already have CMake installed, see the See Supported Platforms for more information about platforms ![]() CMake and a compatible build tool for building the. ![]()
0 Comments
Read More
Leave a Reply. |