NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
On 15/04/14 02:55, Unidata UDUNITS Support wrote:
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.
My point is: The latest udunits doesn't build on ubuntu: $ rm -Rf build && mkdir build && cd build $ cmake .. $ make Scanning dependencies of target udunits2_doc [ 5%] Built target udunits2_doc Scanning dependencies of target libudunits2 [ 10%] Building C object lib/CMakeFiles/libudunits2.dir/converter.c.o [ 15%] Building C object lib/CMakeFiles/libudunits2.dir/error.c.o [ 21%] Building C object lib/CMakeFiles/libudunits2.dir/formatter.c.o [ 26%] Building C object lib/CMakeFiles/libudunits2.dir/idToUnitMap.c.o [ 31%] Building C object lib/CMakeFiles/libudunits2.dir/parser.c.o [ 36%] Building C object lib/CMakeFiles/libudunits2.dir/prefix.c.o [ 42%] Building C object lib/CMakeFiles/libudunits2.dir/status.c.o [ 47%] Building C object lib/CMakeFiles/libudunits2.dir/systemMap.c.o [ 52%] Building C object lib/CMakeFiles/libudunits2.dir/unitAndId.c.o [ 57%] Building C object lib/CMakeFiles/libudunits2.dir/unitcore.c.o [ 63%] Building C object lib/CMakeFiles/libudunits2.dir/unitToIdMap.c.o [ 68%] Building C object lib/CMakeFiles/libudunits2.dir/ut_free_system.c.o [ 73%] Building C object lib/CMakeFiles/libudunits2.dir/xml.c.o Linking C shared library libudunits2.so [ 84%] Built target libudunits2 Scanning dependencies of target udunits2lib_doc [ 89%] Built target udunits2lib_doc Scanning dependencies of target udunits2 [ 94%] Building C object prog/CMakeFiles/udunits2.dir/udunits2.c.o Linking C executable udunits2 ../lib/libudunits2.so: undefined reference to `fmod' ../lib/libudunits2.so: undefined reference to `exp' ../lib/libudunits2.so: undefined reference to `log' ../lib/libudunits2.so: undefined reference to `pow' ../lib/libudunits2.so: undefined reference to `log10' ../lib/libudunits2.so: undefined reference to `floor' collect2: error: ld returned 1 exit status make[2]: *** [prog/udunits2] Error 1 make[1]: *** [prog/CMakeFiles/udunits2.dir/all] Error 2 make: *** [all] Error 2The only way to fix it is to tell gcc that libudunits depends on libm while generating the .so:
Original command:/usr/bin/cc -fPIC -shared -Wl,-soname,libudunits2.so -o libudunits2.so [...] -lexpat
Fixed command:/usr/bin/cc -fPIC -shared -Wl,-soname,libudunits2.so -o libudunits2.so [...] -lexpat -lm
After the fix: $ make [ 5%] Built target udunits2_doc [ 84%] Built target libudunits2 [ 89%] Built target udunits2lib_doc Linking C executable udunits2 [ 94%] Built target udunits2 Scanning dependencies of target udunits2prog_doc [100%] Built target udunits2prog_doc
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.
My bad! Actually the documentation is clear enough on that point.
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.
My bad again, I think the documentation is clear enough.
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):
[...]
The above warnings are expected for the reasons given. You can disable them.
Good, I think i will eventually customise my unit definitions.
Regards, Steve Emmerson Ticket Details =================== Ticket ID: KIA-819973 Department: Support UDUNITS Priority: Normal Status: Closed
udunits
archives: