Skip to content

Build instructions - CMake updates #310

@pr0g

Description

@pr0g

Hi there,

I had a quick look at getting the sample application listed here working, but ran into a couple of issues on macOS with the CMakeLists.txt file in its current form.

After building and installing the BDE libraries (to a local folder), I can configure correctly with the following command.

cmake -B build -G "Ninja Multi-Config" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=../bde/bde_install

However, when I invoke cmake --build build from my test project folder, I hit the following warnings and errors:

ld: warning: ignoring duplicate libraries: '/path/to/bde/bde_install/lib/libbdl.a', '/path/to/bde/bde_install/lib/libbsl.a'
ld: library 'rt' not found

As the library bal appears to depend on bsl and bdl, explicit references to them can both be removed (this stops the warning about duplicate libraries showing up), and from what I can tell rt is a Linux only library, so can be removed on macOS (and maybe a comment or a generator expression to only include that library on Linux can be added if needed).

This simplifies the CMakeLists.txt to the following...

cmake_minimum_required(VERSION 3.15)
project(ball_init)

find_package(Threads REQUIRED)
find_package(bal REQUIRED)

add_executable(ball_init main.cpp)
target_link_libraries(ball_init PRIVATE bal Threads::Threads)

However with this, when I build, I hit the following error:

Undefined symbols for architecture arm64:
  "BloombergLP::bsls_libraryfeatures_CPP14_ABI", referenced from:
      BloombergLP::dummyAcCeSsbsls_libraryfeatures_assertion() in ball_init.cpp.o
  "BloombergLP::ball::Log_Stream::Log_Stream(BloombergLP::ball::Category const*, bsl::basic_string_view<char, std::__1::char_traits<char>> const&, int, int)", referenced from:
      _main in ball_init.cpp.o
  "BloombergLP::ball::BroadcastObserver::registerObserver(bsl::shared_ptr<BloombergLP::ball::Observer> const&, bsl::basic_string_view<char, std::__1::char_traits<char>> const&)", referenced from:
      BloombergLP::ball::LoggerManager::registerObserver(bsl::shared_ptr<BloombergLP::ball::Observer> const&, bsl::basic_string_view<char, std::__1::char_traits<char>> const&) in ball_init.cpp.o
ld: symbol(s) not found for architecture arm64
c++: error: linker command failed with exit code 1 (use -v to see invocation)

The reason for this appears to be we're not explicitly setting the C++ version to match that of the one used when building the BDE libraries (it looks like on my machine at least, CMake defaults to C++14). To resolve this, the version of C++ needs to be specified with target_compile_features.

If for example, eval bbs_build_env -u opt_64_cpp20 was used, then cxx_std_20 would need to be set, if eval bbs_build_env -u opt_64_cpp17 was used, then cxx_std_17 would need to be set.

So the final CMakeLists.txt file looks like this:

cmake_minimum_required(VERSION 3.15)
project(ball_init)

find_package(bal REQUIRED)

add_executable(ball_init ball_init.cpp)
target_link_libraries(ball_init PRIVATE bal)
target_compile_features(ball_init PRIVATE cxx_std_20)

I removed Threads as it also does not seem to be required for this example, and added the target_compile_features line. I also added the usage requirement (PRIVATE) to the target_link_libraries command that was missing before (this is a legacy CMake thing unfortunately, all newer target... commands enforce providing a usage requirement, be that PRIVATE, PUBLIC, or INTERFACE, but because target_link_libraries is really old it doesn't, as it predates the usage requirements).

If it's possible to update the documentation page with the content from the CMakeLists.txt file above that would be awesome. I would make a PR, but I'm not sure how to contribute changes to the documentation site. I'm afraid I haven't tested these changes on Linux, so it's possible rt and Threads::Threads are still needed there, but I think the other changes are still worthwhile adding.

Thanks very much for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions