0

Adept (http://www.met.reading.ac.uk/clouds/adept/) is a C++ library for automatic differentiation. The following example, placed in a file called home_page.cpp is taken from the home page for the library:

#include <iostream>
#include <adept_arrays.h>

int main(int argc, const char** argv)
{
    using namespace adept;
    
    Stack stack;
    aVector x(3);
    x << 1.0, 2.0, 3.0;
    stack.new_recording();
    aReal J = cbrt(sum(abs(x*x*x)));
    J.set_gradient(1.0);
    stack.reverse();
    std::cout << "dJ/dx = "
              << x.get_gradient() << "\n";
    
    return 0;
}

I can compile this on my Mac using g++ -Wall -O2 home_page.cpp -ladept -llapack -lblas -o home_page.

However, if I try to compile using the C++11 standard, using g++ -Wall -O2 -std=c++11 home_page.cpp -ladept -llapack -lblas -o home_page, I get a long error message:

Undefined symbols for architecture x86_64:
  "thread-local wrapper routine for adept::_stack_current_thread", referenced from:
      _main in home_page-758c45.o
      adept::internal::Allocator<1, adept::Array<1, double, true> > adept::operator<<<1, double, true, double>(adept::Array<1, double, true>&, double const&) in home_page-758c45.o
      adept::Active<double>::~Active() in home_page-758c45.o
      adept::Array<1, double, true>::resize(int const*, bool) in home_page-758c45.o
      adept::Storage<double>::remove_link() in home_page-758c45.o
      void adept::internal::reduce_active<adept::internal::Sum<double>, double, adept::internal::UnaryOperation<double, adept::internal::Abs, adept::internal::BinaryOperation<double, adept::internal::BinaryOperation<double, adept::Array<1, double, true>, adept::internal::Multiply, adept::Array<1, double, true> >, adept::internal::Multiply, adept::Array<1, double, true> > > >(adept::Expression<double, adept::internal::UnaryOperation<double, adept::internal::Abs, adept::internal::BinaryOperation<double, adept::internal::BinaryOperation<double, adept::Array<1, double, true>, adept::internal::Multiply, adept::Array<1, double, true> >, adept::internal::Multiply, adept::Array<1, double, true> > > > const&, adept::Active<double>&) in home_page-758c45.o
      adept::Active<double>::Active<double, adept::internal::UnaryOperation<double, adept::internal::Cbrt, adept::Active<double> > >(adept::Expression<double, adept::internal::UnaryOperation<double, adept::internal::Cbrt, adept::Active<double> > > const&, adept::internal::enable_if<((adept::internal::UnaryOperation<double, adept::internal::Cbrt, adept::Active<double> >::rank) == (0)) && (adept::internal::UnaryOperation<double, adept::internal::Cbrt, adept::Active<double> >::is_active), void>::type*) in home_page-758c45.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I link a program to Adept when using the C++11 standard?

Thanks.

  • You may want to ask at the github site: [https://github.com/rjhogan/Adept-2/issues](https://github.com/rjhogan/Adept-2/issues) – drescherjm Aug 11 '22 at 13:18
  • Have you checked the documentation in [this link](http://www.met.reading.ac.uk/clouds/adept/adept_documentation.pdf)? Section 1.2.2. has some nice information about linking issues. – TonySalimi Aug 11 '22 at 15:10
  • Thanks for your help! I am now able to compile using the method described in Section 1.2.2 of the documentation. That is, by using `#include `. – Hector McKimm Aug 11 '22 at 16:50
  • @HectorMcKimm Just added my remark as an answer. You can accept it as the correct answer, so the next SO users that face the same issue can have a solution then. – TonySalimi Aug 12 '22 at 08:26

1 Answers1

1

As has mentioned in the Adept library documentation, you should add this line to your main source file that includes the main() function:

#include <adept_source.h>

In addition, for every other source file of your code, you may include either adept.h or adept_arrays.h.

TonySalimi
  • 8,257
  • 4
  • 33
  • 62