The real problem is that the graphviz/build/lib/common/CMakeFiles/common.dir/globals.c.o
built via cmake does not contain the global symbol definitions needed by graphviz. You can confirm, e.g. nm -Bo | grep Concentrate. It is a mystery why there this does not work. You can run make VERBOSE=1 and see it yourself. Maybe someone that has used cmake a lot can figure this out. Graphviz builds correctly with GNU autotools so I wonder if cmake is generating the wrong code. I don't have time to figure out how to fix cmake. Stephen North
Bit of background - I've used the same source bundle to successfully build Windows and Linux binaries through CMake - it's only Mac where it doesn't work.
I'm looking to integrate graphviz into our application as an embedded library (cgraph module), which is why CMake is preferred - it gives me control over rpath and/or framework creation on the Mac. I wouldn't know how to accomplish that using autotools. I can confirm that autotools does build correctly on the Mac, but only as a system-installed application. I cannot then turn it into a relocatable library without rewriting all the rpaths afterwards - a rather labour-intensive task...
I'm using the graphviz label stable_release_2.42.2 for my graphviz sources, CMake 3.14.2, MacOS 10.14.5 (Mojave), XCode command-line tools: Apple LLVM version 10.0.1 (clang-1001.0.46.4)
I'm afraid that after I got it working once, the project was put on hold and I have not investigated further. Even then, the builds were for a single platform and not targeted at further distribution. I don't really know anything about Macs to be able to give further insight into multi-platform binaries, or even MacOS frameworks.
In the automake builds, libcommon is only built as a "convenience" library of .o's (libcommon_C_la), and then later linked into libgvc which is the installable library. This allows for essentially independent Makefiles for lib/common and lib/gvc.
But if the scope of symbols in libcommon is being restricted prematurely then this wont work.
A possible workaround might be for cmake to not compile anything in lib/common, but instead compile lib/common/.c and lib/gvc/.c directly into libgvc
I've had the advantage of just trying a brand new / clean install MacOS, and yes I can confirm it needs/uses libtool:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.Please set them or make sure they are set and tested correctly in the CMake files:LTDL_INCLUDE_DIR (ADVANCED)CMake Error: The following variables are used in this project, but they are set to NOTFOUND.Please set them or make sure they are set and tested correctly in the CMake files:LTDL_INCLUDE_DIR (ADVANCED)used by target "gvc"
And yes, I'm getting the exact same linker error, this is with CMake 3.15.4 and AppleClang 11.0.0
The globals.c.o built by cmake does not export global symbols in the way
that the automake based compile does. One can determine this just by:
$ cd ~/src/graphviz
$ nm lib/common/.libs/globals.o | grep N_width
0000000000002c88 S _N_width
$ nm build/lib/common/CMakeFiles/common.dir/globals.c.o | grep N_width
0000000000000008 C _N_width
$
I don’t think libtool is involved because the compile doesn’t generate a
It appears that the automake generated Makefile has -fno-common and adding this to
build/lib/common/CMakefiles/common.dir/flags.make allows the build to progress further, but then
the compilation of the pango plugin dies:
[ 84%] Building C object plugin/pango/CMakeFiles/gvplugin_pango.dir/gvgetfontlist_pango.c.o
In file included from /Users/north/src/graphviz/plugin/pango/gvgetfontlist_pango.c:55:
In file included from /usr/local/include/pango-1.0/pango/pangocairo.h:25:
In file included from /usr/local/include/pango-1.0/pango/pango.h:25:
In file included from /usr/local/include/pango-1.0/pango/pango-attributes.h:25:
In file included from /usr/local/include/pango-1.0/pango/pango-font.h:25:
/usr/local/include/pango-1.0/pango/pango-coverage.h:28:10: fatal error: 'hb.h' file not found
#include <hb.h>
^~~~~~
1 error generated.
which means that the dependency between pango and harfbuzz is not being handled properly in CMake.
Someone with a bigger stake in the CMake build should take a turn at working on this now. Also color_lib
needs to be installed (populated into the build tree) in build/lib/common which I assume is just an oversight
in some config file somewhere.
Great spot on -fno-common, looking at the clang docs this makes complete sense:
-fcommon, -fno-common¶
This flag specifies that variables without initializers get common linkage. It can be disabled with -fno-common.
With this flag added, the cgraph library builds and should hopefully be usable by my application. I shall test that further tomorrow. (I don't build or use the UI components of graphviz)
Also color_lib needs to be installed (populated into the build tree) in build/lib/common which I assume is just an oversight in some config file somewhere.
OK, I also can get the full CMake graphviz build to run, if I
manually copy lib/common/color_lib to build/lib/common/color_lib (why doesn't graphviz/cmake/generate_color_lib.cmake.in do this, or is this not being invoked?)
manually add -fno-common to C_FLAGS in build/lib/common/CMakeFiles/common.dir/flags.make
wherever that really comes from.
manually add -I/usr/local/Cellar/harfbuzz/2.6.2/include/harfbuzz to C_INCLUDES in
build/plugin/pango/CMakeFiles/gvplugin_pango.dir/flags.make
wherever that really comes from
(the value should of course come from running pkg-config --cflags harfbuzz).
Please can someone create patches for the CMake configuration to do the above?
I tested the CMake change above, and can confirm that I can now build cgraph library and the layout plugins that my application requires. Thank you @truenorth and @ellson for your help.
Please can an expert comment on how to incorporate the proposed patch to lib/common/CMakeLists.txt, which unfortunately "does not work" in the sense that it makes CMake complain,
CMake Error at lib/common/CMakeLists.txt:39 (target_compile_options): Cannot specify compile options for target "common" which is not built by this project.
I have experienced a similar undefined symbol issue on an older OSX machine (late-2009 Mac Mini, 10.11.6 El Capitan with Xcode 8.2.1/clang 800.0.42.1, CMake 3.17.3). The attached logs are based on the current graphviz source and dependencies supplied by Fink, though I've seen similar behavior with dependencies provided by brew (FWIW, brew doesn't support a platform this old and couldn't successfully build pangocairo but CMake found the minimal graphviz dependencies regardless).
I'm putting together a small MR for changes I made to get CMake to find pangocairo under Fink (glibconfig.h actually) but the only change made for the build using brew dependencies was the addition of set(CMAKE_MACOSX_RPATH TRUE) to the root CMakeLists.txt and even that should have only affected the installation paths, not compilation.
It's old and small and slow but I finally have an OSX machine for testing CMake builds. I've made separate progress building installers and I'd like to take a stab at getting CMake completely working on OSX. Guidance on where to look to sort out this library/symbol issue would be appreciated -- thanks!