It was relatively easy. Hacked up below. Any idea why run-program with
:output :stream waits forever requiring the hack below.
CMU Common Lisp 18e-pre, built 2003-01-26
;;; from libiberty.a
(def-alien-routine "cplus_demangle" c-string (mangled c-string) (options
integer))
(defparameter *mangles* (make-hash-table :test 'equal))
(defun add-to-mangle-hash (filename &optional (hash *mangles*))
"Adds [demangled mangled] symbols from FILENAME to HASH."
(with-input-from-string
(str (with-output-to-string (out)
(let ((prog (ext:run-program "/usr/bin/nm" (list "--defined-only"
filename) :output out :wait t))))))
(do ((line (read-line str nil) (read-line str nil)))
((null line))
(destructuring-bind (loc code name) (split-string line '(#\Space))
(setf (gethash (cplus-demangle name 0) hash) name)))))
(defun mangle (name &optional (hash *mangles*))
(let ((hit (gethash name hash)))
(if hit hit
(warn "mangle symbol not found: ~a" name))))
(defmacro def-alien-variable-cpp (name &rest rest)
(if (consp name)
`(def-alien-variable (,(mangle (car name)) ,(cadr name)) ,@rest)
`(def-alien-variable ,(mangle name) ,@rest)))
(defmacro def-alien-routine-cpp (name &rest rest)
(if (consp name)
`(def-alien-routine (,(mangle (car name)) ,(cadr name)) ,@rest)
`(def-alien-routine ,(mangle name) ,@rest)))
>
>
>
> I am using c++ libraries via load-foreign and need a method of
> converting from demangled names to mangled names in order to use the
> alien interface. Any thing out there to do this?
>
> I was planning on just using a hash table created via code ripped from
> c++filt but do not wish to reinvent the wheel.
>
> Thank you,
> William