--- udunits2.h
+++ udunits2.h
@@ -11,6 +11,8 @@
 #include <stdarg.h>
 #include <stddef.h>
 
+#include "harp_udunits2_mangle.h"
+
 #ifdef _MSC_VER
 #include <stdlib.h>
 #include <stdio.h>
--- converter.h
+++ converter.h
@@ -14,6 +14,8 @@
 
 #include <stddef.h>
 
+#include "harp_udunits2_mangle.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
--- unitcore.c
+++ unitcore.c
@@ -252,7 +252,7 @@
 /*
  * Convert a Julian day number to a Gregorian/Julian date.
  */
-void
+static void
 julianDayToGregorianDate(julday, year, month, day)
     long	julday;		/* Julian day number to convert */
     int		*year;		/* Gregorian year (out) */
@@ -302,7 +302,7 @@
  *
  * The Gregorian calendar was adopted midday, October 15, 1582.
  */
-long
+static long
 gregorianDateToJulianDay(year, month, day)
     int		year;	/* Gregorian year */
     int		month;	/* Gregorian month (1-12) */
--- utparser.y
+++ utparser.y
@@ -16,6 +16,46 @@
 
 /*LINTLIBRARY*/
 
+#define yylex       harp_utlex
+#define yyerror     harp_uterror
+#define yymaxdepth	utmaxdepth
+#define yyparse     utparse
+#define yylval		utlval
+#define yychar		utchar
+#define yypact		utpact
+#define yyr1		utr1
+#define yyr2		utr2
+#define yydef		utdef
+#define yychk		utchk
+#define yypgo		utpgo
+#define yyact		utact
+#define yyexca		utexca
+#define yyerrflag	uterrflag
+#define yynerrs		utnerrs
+#define yyps		utps
+#define yypv		utpv
+#define yys		uts
+#define yy_yys		utyys
+#define yystate		utstate
+#define yytmp		uttmp
+#define yyv		utv
+#define yy_yyv		utyyv
+#define yyval		utval
+#define yylloc		utlloc
+#define yyreds		utreds
+#define yytoks		uttoks
+#define yylhs		utyylhs
+#define yylen		utyylen
+#define yydefred	utyydefred
+#define yydgoto		utyydgoto
+#define yysindex	utyysindex
+#define yyrindex	utyyrindex
+#define yygindex	utyygindex
+#define yytable		utyytable
+#define yycheck		utyycheck
+#define yyname		utyyname
+#define yyrule		utyyrule
+
 #include "config.h"
 
 #include "prefix.h"
@@ -32,15 +72,23 @@
 #include <strings.h>
 #endif
 
-extern int utlex (void);
-
 static ut_unit*		_finalUnit;	/* fully-parsed specification */
 static ut_system*	_unitSystem;	/* The unit-system to use */
 static char*		_errorMessage;	/* last error-message */
 static ut_encoding	_encoding;	/* encoding of string to be parsed */
-static int		_restartScanner;/* restart scanner? */
-static int		_isTime;        /* product_exp is time? */
+extern int		utrestartScanner;/* restart scanner? */
+extern int		utisTime;        /* product_exp is time? */
 
+/* external function declarations */
+#define YY_BUFFER_STATE void *
+YY_BUFFER_STATE ut_scan_string(const char *);
+void ut_delete_buffer(YY_BUFFER_STATE);
+int ut_get_bufferpos(YY_BUFFER_STATE);
+int yylex(void);
+ut_status utGetPrefixByName(ut_system* system, const char* string,
+                            double* value, size_t* len);
+ut_status utGetPrefixBySymbol(ut_system* system, const char* string,
+                              double* value, size_t* len);
 
 /*
  * Removes leading and trailing whitespace from a string.
@@ -279,11 +327,11 @@
 
 product_exp:	power_exp {
 		    $$ = $1;
-                    _isTime = isTime($$);
+                    utisTime = isTime($$);
 		} |
 		product_exp power_exp	{
 		    $$ = ut_multiply($1, $2);
-                    _isTime = isTime($$);
+                    utisTime = isTime($$);
 		    ut_free($1);
 		    ut_free($2);
 		    if ($$ == NULL)
@@ -297,7 +345,7 @@
 		} |
 		product_exp MULTIPLY power_exp	{
 		    $$ = ut_multiply($1, $3);
-                    _isTime = isTime($$);
+                    utisTime = isTime($$);
 		    ut_free($1);
 		    ut_free($3);
 		    if ($$ == NULL)
@@ -311,7 +359,7 @@
 		} |
 		product_exp DIVIDE power_exp	{
 		    $$ = ut_divide($1, $3);
-                    _isTime = isTime($$);
+                    utisTime = isTime($$);
 		    ut_free($1);
 		    ut_free($3);
 		    if ($$ == NULL)
@@ -493,45 +541,6 @@
 
 %%
 
-#define yymaxdepth	utmaxdepth
-#define yylval		utlval
-#define yychar		utchar
-#define yypact		utpact
-#define yyr1		utr1
-#define yyr2		utr2
-#define yydef		utdef
-#define yychk		utchk
-#define yypgo		utpgo
-#define yyact		utact
-#define yyexca		utexca
-#define yyerrflag	uterrflag
-#define yynerrs		utnerrs
-#define yyps		utps
-#define yypv		utpv
-#define yys		uts
-#define yy_yys		utyys
-#define yystate		utstate
-#define yytmp		uttmp
-#define yyv		utv
-#define yy_yyv		utyyv
-#define yyval		utval
-#define yylloc		utlloc
-#define yyreds		utreds
-#define yytoks		uttoks
-#define yylhs		utyylhs
-#define yydefred	utyydefred
-#define yydgoto		utyydgoto
-#define yysindex	utyysindex
-#define yyrindex	utyyrindex
-#define yygindex	utyygindex
-#define yytable		utyytable
-#define yycheck		utyycheck
-#define yyname		utyyname
-#define yyrule		utyyrule
-
-#include "scanner.c"
-
-
 /*
  * Converts a string in the Latin-1 character set (ISO 8859-1) to the UTF-8
  * character set.
@@ -645,7 +654,7 @@
 
             _unitSystem = (ut_system*)system;
             _encoding = encoding;
-            _restartScanner = 1;
+            utrestartScanner = 1;
 
 #if YYDEBUG
             utdebug = 0;
@@ -655,10 +664,10 @@
             _finalUnit = NULL;
 
             if (utparse() == 0) {
-                int       status;
-                ptrdiff_t n = yy_c_buf_p  - buf->yy_ch_buf;
+                int     status;
+                int    n = ut_get_bufferpos(buf);
 
-                if (n >= strlen(utf8String)) {
+                if (n >= (signed)strlen(utf8String)) {
                     unit = _finalUnit;	/* success */
                     status = UT_SUCCESS;
                 }
--- utscanner.l
+++ utscanner.l
@@ -9,13 +9,20 @@
  * lex(1) specification for tokens for the Unidata units package, UDUNITS2.
  */
 
+%option prefix="harp_ut"
 %option noyywrap
+%option noinput
+%option nounput
 
 %{
 
+/* This define is to allow more than one yacc file in the program */
+#define yylval utlval
+
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
+#define _USE_MATH_DEFINES
 #include <math.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -23,6 +30,17 @@
 #include <string.h>
 #include <time.h>
 
+#include "udunits2.h"
+#include "utparser.h"
+
+int utrestartScanner = 0;
+int utisTime = 0;
+
+int ut_get_bufferpos(YY_BUFFER_STATE buf)
+{
+    return yy_c_buf_p - buf->yy_ch_buf;
+}
+
 /**
  * Decodes a date.
  *
@@ -144,9 +162,9 @@
 %Start		ID_SEEN SHIFT_SEEN DATE_SEEN CLOCK_SEEN
 
 %%
-    if (_restartScanner) {
+    if (utrestartScanner) {
 	BEGIN INITIAL;
-	_restartScanner = 0;
+	utrestartScanner = 0;
     }
 
 <INITIAL,ID_SEEN>{space}*(@|{after}|{from}|{ref}|{since}){space}* {
@@ -247,7 +265,7 @@
 }
 
 <SHIFT_SEEN>{packed_date}(T|{space}*) {
-    if (_isTime) {
+    if (utisTime) {
         BEGIN DATE_SEEN;
         return decodeDate((char*)yytext, "%4d%2d%2d", &yylval.rval);
     }
--- xml.c
+++ xml.c
@@ -2137,7 +2137,7 @@ default_udunits2_xml_path()
     if (absXmlPathname[0] == 0) {
         const char* prefix = NULL; // Installation directory
 
-#       if defined(__APPLE__) || defined(__linux__)
+#       if 0
             Dl_info     info;
             const char  sep = '/'; // Pathname component separator
             char        buf[PATH_MAX];
