未定义对nlopt

编程入门 行业动态 更新时间:2024-10-23 17:34:32
本文介绍了未定义对nlopt _...符号的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Fortran还是很陌生,这听起来像是一个愚蠢的问题.在编译作为示例发布在NLOPT Wiki中的Fortran代码时,我遇到错误.

I am fairly new to Fortran and this may sound like a silly question. I encounter an error when compiling the Fortran code that is posted as an example in the NLOPT Wiki.

我使用以下命令在Ubuntu 18.04 LTS中进行编译:

I compile in Ubuntu 18.04 LTS using the following command:

gfortran example-nlopt.f90 -o example-nlopt -I/usr/local/include/

在终端中产生以下错误:

The following error is produced in the terminal:

/tmp/ccbAim6b.o: In function `MAIN__': example-nlopt.f90:(.text+0x26): undefined reference to `nlo_create_' example-nlopt.f90:(.text+0x42): undefined reference to `nlo_get_lower_bounds_' example-nlopt.f90:(.text+0x67): undefined reference to `nlo_set_lower_bounds_' example-nlopt.f90:(.text+0x8a): undefined reference to `nlo_set_min_objective_' example-nlopt.f90:(.text+0xca): undefined reference to `nlo_add_inequality_constraint_' example-nlopt.f90:(.text+0x10e): undefined reference to `nlo_add_inequality_constraint_' example-nlopt.f90:(.text+0x12d): undefined reference to `nlo_set_xtol_rel_' example-nlopt.f90:(.text+0x164): undefined reference to `nlo_optimize_' example-nlopt.f90:(.text+0x305): undefined reference to `nlo_destroy_' collect2: error: ld returned 1 exit status

推荐答案

基于我在nlopt文档中看到的内容( nlopt.readthedocs.io/en/latest/NLopt_Installation/#changing-the-installation-directory ),看起来您只需要指定要链接的库.也许试试这个:

Based on what I saw in nlopt's documentation (nlopt.readthedocs.io/en/latest/NLopt_Installation/#changing-the-installation-directory) it looks like you just need to specify the library to link against. Maybe try this:

gfortran -I/usr/local/include/ -L/usr/local/lib example-nlopt.f90 -o example-nlopt -lnlopt -lm

这假定您在/usr/local/lib中有libnlopt.so,如果没有,则使用-L选项指向它的位置.

This assumes you have the libnlopt.so in /usr/local/lib, if not then point to its location with the -L option.

更多推荐

未定义对nlopt

本文发布于:2023-11-12 20:36:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   nlopt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!