如何将C++11程序链接到Adept库



Adept(http://www.met.reading.ac.uk/clouds/adept/)是一个用于自动区分的C++库。以下示例位于名为home_page.cpp的文件中,取自库的主页:

#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;
}

我可以使用g++ -Wall -O2 home_page.cpp -ladept -llapack -lblas -o home_page在我的Mac上编译这个。

然而,如果我尝试使用C++11标准,使用g++ -Wall -O2 -std=c++11 home_page.cpp -ladept -llapack -lblas -o home_page进行编译,我会收到一条长错误消息:

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)

使用C++11标准时,如何将程序链接到Adept?

谢谢。

正如Adept库文档中所提到的,您应该将此行添加到包含main()函数的主源文件中:

#include <adept_source.h>

此外,对于代码的每个其他源文件,您可以包括adept.hadept_arrays.h

相关内容

  • 没有找到相关文章

最新更新