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

[UDUNITS #KIA-819973]: Build and run problem on ubuntu 13.10 32bits



Chris,

[I've driven your inquiry into our support-email system so that others can 
benefit.]

> Hi there,
> 
> Using master or d98f047 (v2.2.3), I ran into build problems. For some
> reason libudunits2.so isn't build with -lm, causing the build of the
> udunits2 bin to fail.

I belive the "-lm" option should be used when you build an application and not 
when the UDUNITS sharable library is built.

> My quick workaround was to rebuild the lib "manually" by appending "-lm" to
> the original CC command.

You've likely just added the math library to the UDUNITS library. You can check 
for this via the nm(1) utility.

> Now i'm running into some basic usage problems, first the command line
> test, which works:
> $ echo $LC_NAME
> en_NZ.UTF-8
> $ udunits2
> You have: 1e3 V.A
> You want: W
> 1000 V.A = 1000 W
> 
> Now my quick test:
> $ cat test.c
> #include <stdio.h>
> #include <udunits2.h>
> 
> int main(int argc, char *argv[])
> {
> ut_system *sys = ut_read_xml(NULL);
> if (!sys) { printf("Sys error\n"); return 1; }
> 
> ut_unit *from = ut_parse(sys, "V.A", UT_UTF8);
> if (!from) { printf("From error\n"); return 1; }
> 
> ut_unit *to = ut_parse(sys, "W", UT_UTF8);
> if (!to) { printf("To error\n"); return 1; }
> 
> int res = ut_are_convertible(from, to);
> if (res == 0) {
> cv_converter* conv = ut_get_converter(from, to);
> if (!conv) { printf("Conv error\n"); return 1; }
> printf("%g\n", cv_convert_double(conv, 1e3));
> }
> else {
> printf("%d %d %d\n", UT_SUCCESS, UT_NOT_SAME_SYSTEM, UT_BAD_ARG);
> printf("%d %p %p\n", res, from, to);
> }

The sense of the "res == 0" test in the above is inverted: the function returns 
false (i.e., 0) if and only if numeric values are not convertible between the 
two units.

> 
> free(from);
> free(to);
> free(sys);

You should use ut_free(ut_unit*) and ut_free_system(ut_unit_system*) in the 
above instead of free(). The documentation needs to be improved in the area. 
I'll get on that.

> 
> return 0;
> }
> $ gcc -Wall test.c -o test -ludunits2 && ./test
> 0 5 1
> 1 0x9743b00 0x9748908
> 
> Which means that from and to are non null, but can_convert tells me that
> one of the two is null (1=UT_BAD_ARG)
> 
> Am I doing something wrong? This is what the udunits2 command line tool is
> doing basically
> 
> BTW, I have some warning messages as well (both with udunits2 -r and my
> test prog):
> Definition of "kt" in "/usr/local/share/udunits/udunits2-common.xml", line
> 90, overrides prefixed-unit "1000000 kilogram"
> Definition of "microns" in "/usr/local/share/udunits/udunits2-common.xml",
> line 336, overrides prefixed-unit "1e-15 second"
> Definition of "ft" in "/usr/local/share/udunits/udunits2-common.xml", line
> 433, overrides prefixed-unit "1e-12 kilogram"
> Definition of "yd" in "/usr/local/share/udunits/udunits2-common.xml", line
> 441, overrides prefixed-unit "8.64e-20 second"
> Definition of "pt" in "/usr/local/share/udunits/udunits2-common.xml", line
> 655, overrides prefixed-unit "1e-09 kilogram"
> Definition of "at" in "/usr/local/share/udunits/udunits2-common.xml", line
> 1052, overrides prefixed-unit "1e-15 kilogram"
> Definition of "ph" in "/usr/local/share/udunits/udunits2-common.xml", line
> 1571, overrides prefixed-unit "3.6e-09 second"
> Definition of "nt" in "/usr/local/share/udunits/udunits2-common.xml", line
> 1578, overrides prefixed-unit "1e-06 kilogram"

The above warnings are expected for the reasons given. You can disable them.

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: KIA-819973
Department: Support UDUNITS
Priority: Normal
Status: Closed