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.
1. 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.
2. 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")
3. 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
4. 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-...
5. 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];
6. 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 all! :)
Thanks in advance Regards.
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
Hi Krzysztof,
Thanks for your answer.
If anyone's interested I wrote a small how-to build on OS X here http://www.pix2d.com/2013/10/build-lib2geom-on-os-x/.
Regarding the dependencies, it would be nice to be able to build lib2geom dependencies-free as possible.
I guess glib is required (even though it seems to be used only for g_ascii_strtod for the moment). But I think the other (gtk,cairo, pango...) are only needed by libtoy. Is this correct?
$ otool -L lib2geom.3.0.dylib
lib2geom.3.0.dylib: lib2geom.3.0.dylib (compatibility version 3.0.0, current version 0.0.0) /Users/lzubiaur/gtk/inst/lib/libgsl.0.dylib (compatibility version 18.0.0, current version 18.0.0) /Users/lzubiaur/gtk/inst/lib/libgslcblas.0.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) /Users/lzubiaur/gtk/inst/lib/libgtk-quartz-2.0.0.dylib (compatibility version 2401.0.0, current version 2401.21.0) /Users/lzubiaur/gtk/inst/lib/libgdk-quartz-2.0.0.dylib (compatibility version 2401.0.0, current version 2401.21.0) /Users/lzubiaur/gtk/inst/lib/libatk-1.0.0.dylib (compatibility version 21010.0.0, current version 21010.1.0) /Users/lzubiaur/gtk/inst/lib/libgio-2.0.0.dylib (compatibility version 3801.0.0, current version 3801.0.0) /Users/lzubiaur/gtk/inst/lib/libpangocairo-1.0.0.dylib (compatibility version 3601.0.0, current version 3601.0.0) /Users/lzubiaur/gtk/inst/lib/libgdk_pixbuf-2.0.0.dylib (compatibility version 3001.0.0, current version 3001.0.0) /Users/lzubiaur/gtk/inst/lib/libpango-1.0.0.dylib (compatibility version 3601.0.0, current version 3601.0.0) /Users/lzubiaur/gtk/inst/lib/libcairo.2.dylib (compatibility version 11203.0.0, current version 11203.16.0) /Users/lzubiaur/gtk/inst/lib/libgobject-2.0.0.dylib (compatibility version 3801.0.0, current version 3801.0.0) /Users/lzubiaur/gtk/inst/lib/libglib-2.0.0.dylib (compatibility version 3801.0.0, current version 3801.0.0) /Users/lzubiaur/gtk/inst/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.1.0) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
Regards
On Thu, Oct 24, 2013 at 3:06 PM, Krzysztof Kosiński <tweenk.pl@...400...>wrote:
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
participants (3)
-
Den Ranx
-
Krzysztof Kosiński
-
Laurent Zubiaur