Thank you!  Works great!

On Mon, Jul 28, 2025 at 7:34 PM Richard L. Hamilton <[email protected]> wrote:
>
> Haven't tried but I'll guess that clang++ won't find the library unless you 
> tell it to, adding options like
>
> -L/opt/local/lib -lprimesieve
>
> Kind of surprised if it found primesieve.hpp without a
>
> -I/opt/local/include
> (that was an upper case i, not a lower case L; hard to tell apart with the 
> font I'm using)
>
> Now maybe your clang++ build has those paths built into it; but it surely 
> would not know about the library without being told.
>
>
> > On Jul 28, 2025, at 18:55, Kenneth Wolcott <[email protected]> wrote:
> >
> > Hi;
> >
> > Unable to compile a C++ program from Rosetta Code that uses Primesieve
> >
> > https://rosettacode.org/wiki/Anaprimes
> >
> > port installed | grep primesieve
> >  primesieve @12.4_0 (active)
> >
> > Am I missing something critical like an environment variable that
> > specifies /opt/local/lib, or something like that?
> >
> > Do I need a link command with my clang++ command?
> >
> > clang++ -o ./anaprimes ./anaprimes.cpp
> >
> > Undefined symbols for architecture arm64:
> >  "primesieve::iterator::generate_next_primes()", referenced from:
> >      primesieve::iterator::next_prime() in anaprimes-0a28a6.o
> >  "primesieve::iterator::iterator()", referenced from:
> >      _main in anaprimes-0a28a6.o
> >  "primesieve::iterator::~iterator()", referenced from:
> >      _main in anaprimes-0a28a6.o
> >      _main in anaprimes-0a28a6.o
> > ld: symbol(s) not found for architecture arm64
> > clang++: error: linker command failed with exit code 1 (use -v to see
> > invocation)
> >
> > cat -n ./anaprimes.cpp
> >     1 #include <array>
> >     2 #include <iostream>
> >     3 #include <map>
> >     4 #include <vector>
> >     5
> >     6 #include <primesieve.hpp>
> >     7
> >     8 using digit_set = std::array<int, 10>;
> >     9
> >    10 digit_set get_digits(uint64_t n) {
> >    11    digit_set result = {};
> >    12    for (; n > 0; n /= 10)
> >    13        ++result[n % 10];
> >    14    return result;
> >    15 }
> >    16
> >    17 int main() {
> >    18    std::cout.imbue(std::locale(""));
> >    19    primesieve::iterator pi;
> >    20    using map_type =
> >    21        std::map<digit_set, std::vector<uint64_t>,
> > std::greater<digit_set>>;
> >    22    map_type anaprimes;
> >    23    for (uint64_t limit = 1000; limit <= 10000000000;) {
> >    24        uint64_t prime = pi.next_prime();
> >    25        if (prime > limit) {
> >    26            size_t max_length = 0;
> >    27            std::vector<map_type::iterator> groups;
> >    28            for (auto i = anaprimes.begin(); i != anaprimes.end(); 
> > ++i) {
> >    29                if (i->second.size() > max_length) {
> >    30                    groups.clear();
> >    31                    max_length = i->second.size();
> >    32                }
> >    33                if (max_length == i->second.size())
> >    34                    groups.push_back(i);
> >    35            }
> >    36            std::cout << "Largest group(s) of anaprimes before " << 
> > limit
> >    37                      << ": " << max_length << " members:\n";
> >    38            for (auto i : groups) {
> >    39                std::cout << "  First: " << i->second.front()
> >    40                          << "  Last: " << i->second.back() << '\n';
> >    41            }
> >    42            std::cout << '\n';
> >    43            anaprimes.clear();
> >    44            limit *= 10;
> >    45        }
> >    46        anaprimes[get_digits(prime)].push_back(prime);
> >    47    }
> >    48 }
> >
> > Thanks in advance for the help.
> >
> > Ken Wolcott
> >
>

Reply via email to