Well, somewhere you have to put the nlopt library to link with.
Try to run mex --help or something similar to discover how to give it a library.
BTW I never used Matlab
Hope it helps
mario

On 02-Dec-11 13:11, Pattabhi Ramaiah wrote:
Hellow,
Can some one tell me in detail how to compile and execute the nlopt_optimize-mex.c file in matlab, I have been struggling with this. I am using Linux with Fedora 13.

Matlab produced the bellow errors when I excuted with mex command

>> mex nlopt_optimize-mex.c

nlopt_optimize-mex.o: In function `make_opt':
nlopt_optimize-mex.c:(.text+0x3d3): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x3dd): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x40e): undefined reference to `nlopt_create'
nlopt_optimize-mex.c:(.text+0x428): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x432): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x481): undefined reference to `nlopt_set_lower_bounds' nlopt_optimize-mex.c:(.text+0x4b4): undefined reference to `nlopt_set_upper_bounds' nlopt_optimize-mex.c:(.text+0x4d4): undefined reference to `nlopt_set_stopval' nlopt_optimize-mex.c:(.text+0x4ef): undefined reference to `nlopt_set_ftol_rel' nlopt_optimize-mex.c:(.text+0x50a): undefined reference to `nlopt_set_ftol_abs' nlopt_optimize-mex.c:(.text+0x525): undefined reference to `nlopt_set_xtol_rel' nlopt_optimize-mex.c:(.text+0x554): undefined reference to `nlopt_set_xtol_abs' nlopt_optimize-mex.c:(.text+0x597): undefined reference to `nlopt_set_maxeval' nlopt_optimize-mex.c:(.text+0x5b2): undefined reference to `nlopt_set_maxtime' nlopt_optimize-mex.c:(.text+0x5d2): undefined reference to `nlopt_set_population' nlopt_optimize-mex.c:(.text+0x5f2): undefined reference to `nlopt_set_vector_storage' nlopt_optimize-mex.c:(.text+0x630): undefined reference to `nlopt_set_initial_step'
nlopt_optimize-mex.c:(.text+0x680): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x68a): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x6c1): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x6cb): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x6ea): undefined reference to `nlopt_set_local_optimizer'
nlopt_optimize-mex.c:(.text+0x6f2): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.o: In function `mexFunction':
nlopt_optimize-mex.c:(.text+0x75c): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x799): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x829): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0x8ad): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.o:nlopt_optimize-mex.c:(.text+0x939): more undefined references to `nlopt_destroy' follow
nlopt_optimize-mex.o: In function `mexFunction':
nlopt_optimize-mex.c:(.text+0xa17): undefined reference to `nlopt_set_min_objective' nlopt_optimize-mex.c:(.text+0xa2f): undefined reference to `nlopt_set_max_objective'
nlopt_optimize-mex.c:(.text+0xa91): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xb5e): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xba8): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xc65): undefined reference to `nlopt_add_inequality_constraint'
nlopt_optimize-mex.c:(.text+0xc87): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xd0b): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xdda): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xe26): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xee3): undefined reference to `nlopt_add_equality_constraint'
nlopt_optimize-mex.c:(.text+0xf07): undefined reference to `nlopt_destroy'
nlopt_optimize-mex.c:(.text+0xf8c): undefined reference to `nlopt_optimize'
nlopt_optimize-mex.c:(.text+0xfbc): undefined reference to `nlopt_destroy'
collect2: ld returned 1 exit status

mex: link of ' "nlopt_optimize-mex.mexa64"' failed.

??? Error using ==> mex at 221
Unable to complete successfully.

Any suggestions will be greatful.

Best
Pattabhi

On Thu, Dec 1, 2011 at 11:22 AM, Pattabhi Ramaiah <[email protected] <mailto:[email protected]>> wrote:

    Dear All,
    This question may look trivial, but I am facing problem.

    I am working with nlopt-2.2.4, linux version and my interest is in
    linking nlopt with MATLAB. I think I am able to install correctly
    using

    ./configure MEX=/data/ab/cd/ef/gh/nlopt-2.2.4/octave
    make
    make install

    after this the an executable for dummy.c is generated and it
    prints Hellow world. So I assume my compilation of nlopt is correct.

    But when I tried to compile nlopt_optimize-mex.c using matlab mex,
    like *mex nlopt_optimize-mex.c *in the matlab command window,
    matlab printed the following errors

    nlopt_optimize-mex.c:31:19: error: nlopt.h: No such file or directory
    nlopt_optimize-mex.c:122: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
    ‘__attribute__’ before ‘make_opt’
    nlopt_optimize-mex.c: In function ‘mexFunction’:
    nlopt_optimize-mex.c:181: error: ‘nlopt_result’ undeclared (first
    use in this function)
    nlopt_optimize-mex.c:181: error: (Each undeclared identifier is
    reported only once
    nlopt_optimize-mex.c:181: error: for each function it appears in.)
    nlopt_optimize-mex.c:181: error: expected ‘;’ before ‘ret’
    nlopt_optimize-mex.c:184: error: ‘nlopt_opt’ undeclared (first use
    in this function)
    nlopt_optimize-mex.c:184: error: expected ‘;’ before ‘opt’
    nlopt_optimize-mex.c:186: error: ‘opt’ undeclared (first use in
    this function)
    nlopt_optimize-mex.c:302: error: ‘ret’ undeclared (first use in
    this function)

    I could compile all the example mex files in matlab mex folder, so
    I assume my matlab mex is working fine.

    Also I am not successful in compiling *nlopt_optimize-mex.c *on
    the unix terminal.

    I also tried to change the configure file to matlab root folder as
    given below and reinstall nlopt

    ./configure MEX=/opt/matlabR2009b/extern/examples/mex
    make
    make install

    but still not successful in compiling the *mex nlopt_optimize-mex.c.*
    *
    *
    Apart from that, I tried to work on the example problem given in
    the tutorial
    *
    *
    myfunc.m
    function [val, gradient] = myfunc(x)
    val = sqrt(x(2));
    if (nargout > 1)
    gradient = [0, 0.5 / val];
    end

    myconstraint.m
    function [val, gradient] = myconstraint(x,a,b)
    val = (a*x(1) + b)^3 - x(2);
    if (nargout > 1)
    gradient = [3*a*(a*x(1) + b)^2, -1];
    end

    and test.m

    opt.algorithm = NLOPT_LD_MMA
    opt.lower_bounds = [-inf, 0]
    opt.min_objective = @myfunc
    opt.fc = { (@(x) myconstraint(x,2,0)), (@(x) myconstraint(x,-1,1)) }
    opt.fc_tol = [1e-8, 1e-8];
    opt.xtol_rel = 1e-4

    [xopt, fmin, retcode] = nlopt_optimize(opt, [1.234 5.678])

    but matlab says: *Attempt to execute SCRIPT nlopt_optimize as a
    function:*
    *
    *
    Any thoughts would be appreciated. Thanks in advance.

    Best regards
    Pattabhi




_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

--
Ing. Mario Valle
Data Analysis and Visualization Group            | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82


_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to