gpt4 book ai didi

c++ - 编译简单的 Opt++ 示例 : Undefined reference to dswap_

转载 作者:行者123 更新时间:2023-11-28 02:05:01 25 4
gpt4 key购买 nike

我下载了Opt++ .我做了 basic install :

1. cd optpp-2.4
2. ./configure
3. make >& make.log
4. make check >& makecheck.log
5. make install

我复制了Example 1: Unconstrained Quasi-Newton Without Derivatives在下面的代码中。但是当我尝试编译时,即

g++ run_rosen.cpp rosen.cpp -Wno-write-strings -DHAVE_NAMESPACES -I/usr/local/include -I/usr/local/lib -lopt -lnewmat

我收到以下错误。我还认为引用我的下载目录很奇怪。

//usr/local/lib/libopt.a(dqrdc.o): In function dqrdc:
/home/a/downloads/optpp-2.4/src/PDS/dqrdc.c: 156: undefind reference to dswap_
/home/a/downloads/optpp-2.4/src/PDS/dqrdc.c: 182: undefind reference to dswap_
...
//usr/local/lib/libopt.a(pdsdone.o): In function pdsdone:
/home/a/downloads/optpp-2.4/src/PDS/pdsdone.c: 128: undefind reference to dnrm2_
...

代码:

run_rosen.cpp

#include <fstream>
#include "rosen.h"
#include "NLF.h"
#include "OptQNewton.h"


using namespace OPTPP;

int main()
{
int ndim = 2;
FDNLF1 nlp (ndim, rosen, init_rosen);
OptQNewton objfcn(&nlp);

objfcn.setSearchStrategy(TrustRegion);
objfcn.setMaxFeval(200);
objfcn.setFcnTol(1.e-4);

if (!objfcn.setOutputFile("rosen.out", 0))
{
cerr << "main: output file open failed" << endl;
}

objfcn.optimize();
objfcn.printStatus("Solution from quasi-newton");
objfcn.cleanup();
}

罗森.h

#ifndef ROSEN_H
#define ROSEN_H

#include "NLF.h"
#include "OptNewton.h"

void init_rosen(int ndim, NEWMAT::ColumnVector& x);

void rosen(int ndim, const NEWMAT::ColumnVector& x, double& fx, int& result);

#endif // ROSEN_H

罗森.cpp

#include "rosen.h"

void init_rosen(int ndim, NEWMAT::ColumnVector& x)
{
if (ndim != 2)
{
exit(1);
}

x(1) = 1.2;
x(2) = 1.0;
}

void rosen(int ndim, const NEWMAT::ColumnVector& x, double& fx, int& result)
{

if (ndim != 2)
{
exit(1);
}

double f1, f2;
f1 = (x(2) - x(1) * x(1));
f2 = 1. - x(1);
fx = 100. * f1 * f1 + f2 * f2;
result = OPTPP::NLPFunction;
}

最佳答案

您需要链接到 BLAS 库。尝试将此添加到构建命令的末尾:

-lblas

关于c++ - 编译简单的 Opt++ 示例 : Undefined reference to dswap_,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com