Posting my work for posterity. Realized after finishing my last example in C++ that I actually needed to do it in C all along (awesome, right?). Both iterations took me considerable effort as a Java programmer and I think a lot of the sample code out there leaves far too many holes - especially when it comes to building which is considerably more difficult from the command line for someone who is used to using, say Eclipse, to build a project and handle dependencies.
How to install dependencies for OSX with brew:
brew install flatcc
brew install zeromq
You'll need all the standard builder binaries installed as well. I used gcc to compile with:
gcc publisher.c -o bin/zmq_pub -lzmq -lflatcc
gcc subscriber.c -o bin/zmq_sub -lzmq
This assumes you've installed the zmq and flatcc libraries which should get symlinked to your /usr/local/include after brew finishes installing them. Like this:
zmq_cpub $ls -la /usr/local/include
lrwxr-xr-x 1 user group 37 Oct 18 18:43 flatcc -> ../Cellar/flatcc/0.3.4/include/flatcc
You'll get compilation errors such as:
Undefined symbols for architecture x86_64:
if you don't have the libraries correctly installed / linked. The compiler / linker will rename functions and prefix them with _ and potentially confuse the hell out of you. Like Undefined symbols for architecture x86_64 _flatcc_builder_init
even though there never is supposed to be an _flatcc_builder_init
.
That's because linking libraries in C / C++ is fundamentally different than in Java. Instead of a specific project build path that you add JARs too there are known locations where external C / C++ libraries can install to. /usr/local/include
, /usr/local/lib
, /usr/lib
, and /usr/include
.
And don't forget to generate the header files to use in your local project after installing the flatcc binary to your path:
flatcc -a Car.fbs
That should be pretty much every obstacle I faced on my trip down C lane. Hope it helps someone out there.