0

After installing Boost via HomeBrew and writing the following code :


#include "Common.hpp"

/* ----- B00ST ----- */
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>

void Common::generate_random_password(std::string* password, int length) {
    /*
     * INPUTS :
     *      Pointer to store the generated password
     *
     * OUTPUTS :
     *      None
     *
     * RAISES :
     *      None
     */

    std::string chars(
            "abcdefghijklmnopqrstuvwxyz"
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            "1234567890"
            "!@#$%^&*()"
            "`~-_=+[{]}\\|;:'\",<.>/? ");
    boost::random::random_device rng;
    boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);

    for (int i = 0; i < length; ++i)
        password->append(&chars[index_dist(rng)]);


} // generate_random_password(const std::string* password)

CLion's coming up with this error :

Undefined symbols for architecture arm64:
  "boost::random::random_device::random_device()", referenced from:
      Common::generate_random_password(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, int) in Common.cpp.o
  "boost::random::random_device::~random_device()", referenced from:
      Common::generate_random_password(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, int) in Common.cpp.o
  "boost::random::random_device::operator()()", referenced from:
      int boost::random::detail::generate_uniform_int<boost::random::random_device, int>(boost::random::random_device&, int, int, boost::integral_constant<bool, true>) in Common.cpp.o
      unsigned int boost::random::detail::generate_uniform_int<boost::random::random_device, unsigned int>(boost::random::random_device&, unsigned int, unsigned int, boost::integral_constant<bool, true>) in Common.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

I've tried to reinstall Boost, double checked my CMake file but I see nothing wrong with my actual building configuration...

In case, here's my CMakeLists.txt file :

cmake_minimum_required(VERSION 3.23)
project(Banko)

set(CMAKE_CXX_STANDARD 23)
add_executable(Banko main.cpp Common.cpp Common.hpp)
find_package(Boost 1.80.0 COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(Banko ${Boost_LIBRARIES})

Thanks for your time !

Unguest

Unguest
  • 21
  • 4
  • Not that it solves the linking problem, but can't you use `std::random_device` and `std::uniform_int_distribution`? – Ted Lyngmo Dec 05 '22 at 22:00
  • Note: Using `random_device` as a generator may be slow. `random_device` is often used to seed a PRNG and use that to generate pseudo random numbers instead. – Ted Lyngmo Dec 05 '22 at 22:02
  • 1
    Homebrew puts include-files in /usr/local/include on Intel-based macs and /opt/homebrew/include om ARM-based macs. That might be an issue. – kometen Dec 05 '22 at 22:02
  • Meant library-files. – kometen Dec 06 '22 at 11:14

1 Answers1

0

Maybe the binaries you used was build for x86_64 architecture only. You can check the architecture of build binaries using this command:

lipo -info /usr/lib/libName.dylib
lipo -info /usr/lib/libName.a

You can build universal libraries and check again.

Here is how you build universal binaries.

If you are using Xcode you can also exclude arm64 architecture if that fulfils your requirement.