
2013/10/21 Laurent Zubiaur <den.ranx@...400...>:
Hi,
I managed to build lib2geom on OS X. Since it was not an easy task I thought it might be useful to share the information with the community.
I planned to write a small tutorial and make it available soon. But first I'd like to request some advice regarding the following issues I faced during the build.
- Avoid glib dependency
I wanted to link lib2geom against my application without having to link against glib too so I replaced the following line in src/2geom/svg-path-parser.cpp: _push(g_ascii_strtod(buf.c_str(), NULL)); with _push(strtod(buf.c_str(), NULL));
and removed the glib.h include.
We cannot incorporate this change, because it introduces a bug. What strtod() does depends on the current locale - for instance it will treat the comma as a decimal separator in many locales. SVG path strings always use numbers with dots as decimal separators, so the path parser would fail in many locales (e.g. the French and Polish ones). We must use a locale-independent conversion function such as g_ascii_strtod.
- Removing librt
Since librt does not exist in OS X (and is not required too) I removed the following line in src/2geom/toys/CMakeLists.txt TARGET_LINK_LIBRARIES(lpetoy "-lrt") TARGET_LINK_LIBRARIES(toy-2 "-lrt")
- Call to pow is ambiguous
Call to the pow function is ambiguous so I forced the call with casting by replacing pow( ..., ... ) with pow( (double) ..., (double) …)
in the following files: boolops-topo.cpp intersect-data.cpp levelsets-test.cpp pencil-2.cpp pencil.cpp sb-to-bez.cpp sketch-fitter.cpp sweeper-toy.cpp
If the ambiguity comes from the pow() function in transforms.h, then it can be removed, because it's not used anywhere and not very useful.
- clock_gettime does not exist on OS X
In src/2geom/toys/toy-framework-2.h I replaced the following code snippet:
#ifdef WIN32 clock_gettime(clock, &ts); ns = ts.tv_sec * NS_PER_SECOND + ts.tv_nsec / NS_PER_NS; #else ns = 0; #endif
with
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); ts.tv_sec = mts.tv_sec; ts.tv_nsec = mts.tv_nsec; ns = ts.tv_sec * NS_PER_SECOND + ts.tv_nsec / NS_PER_NS; #elif WIN32 clock_gettime(clock, &ts); ns = ts.tv_sec * NS_PER_SECOND + ts.tv_nsec / NS_PER_NS; #else ns = 0; #endif
and add the required includes at the beginning of the file. #ifdef __MACH__ # include <mach/clock.h> # include <mach/mach.h> #endif
See http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-...
I think it would be preferable to use portable Glib time functions. We need Glib for g_ascii_strtod anyway.
- Cannot compile pw-toy.cpp
I was not able to compile src/2geom/toys/pw-toy.cpp so I simply disable it in src/2geom/toys/CmakeLists.txt.
src/2geom/toys/pw-toy.cpp:48:30: error: variable length array of non-POD element type 'PiecewiseGeom::SBasis' Piecewise<SBasis> pws[curves];
Probably this should be changed to std::vector.
- Missing return value
Added “return 0;” at the end of the function “cmpy” in uncross.cpp.
src/2geom/toys/uncross.cpp:175:5: error: control may reach end of non-void function [-Werror,-Wreturn-type]
That's obviously a bug.
Regards, Krzysztof