help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dynamically loaded functions -- Using C++ associative arrays


From: E. Joshua Rigler
Subject: Dynamically loaded functions -- Using C++ associative arrays
Date: Tue, 24 Jul 2001 13:42:09 -0600

First, please excuse my lack of C++ expertise, this is all fairly new to
me.

I am attempting to implement an associative array using the std::map<>
class.  It took me a while, but I think I finally figured it out, and
even got a simple test function to compile with mkoctfile.  However, I
get an undefined symbol error when I try to use the function in octave,
and octave crashes.

I've attached my short test program, along with the error I get when I
attempt to call it from octave.  Do I need to link to a special library
when I compile?  What's going on here?

Thanks,

-EJR


////////
//
// Test function for simple associative array
// 
// test_map.cc
//
////////

#include <octave/oct.h>
#include <map>

DEFUN_DLD (test_map, args, nargout,"...")
{

  octave_value retval;

  static std::map<std::string,int> m1;
  static std::map<std::string,int>::iterator p;

  m1["test1"] = 1;
  m1["test2"] = 2;
  m1["test10"] = 10;

  // Is there a matching key in our associative array?
  p = m1.find(args(0).string_value () );
  if (p != m1.end() ) 
    {
      // If there's a match, return its value
      cout << m1[args(0).string_value ()];
      retval = 1.0;
    }

  return retval;

}


////////
//
// Test output from test_map.oct
//
////////

1092 <~/src/octave/oct> octave
GNU Octave, version 2.1.33 (i686-pc-linux-gnu).
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.

octave:1> test_map ("test1")
octave: error while loading shared libraries:
/home/jrigler/src/octave/oct/test_map.oct: undefined symbol:
lower_bound__t8_Rb_tree5Zt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0Zt4pair2ZCt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0ZiZt10_Select1st1Zt4pair2ZCt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0ZiZt4less1Zt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0Zt9allocator1ZiRCt12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]