GCC Linker prefixes flatcc's flatcc_builder_init function with an underscore and does not link

183 views
Skip to first unread message

thomasa...@gmail.com

unread,
Oct 19, 2016, 10:08:13 AM10/19/16
to FlatBuffers
Hello everyone,

I'm making my way through the flatbuffers tutorial for C and I can't make it very far unfortunately. I've pasted the sample code into my project:

#include "flatbuffers/StarBuffer_builder.h"
#include "flatbuffers/flatcc_builder.h"
...
...
        flatcc_builder_t builder, *B;
        B = &builder;
        // Initialize the builder object.
        flatcc_builder_init(B);

zmq_cpub $./build.sh
Undefined symbols for architecture x86_64:
  "_flatcc_builder_init", referenced from:
      _main in publisher-d532f6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here's my build command: gcc publisher.c -o bin/zmq_pub -lczmq -lzmq

I'm on OSX. Here are my GCC details:

zmq_cpub $gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Any idea why GCC is adding the underscore?

thomasa...@gmail.com

unread,
Oct 19, 2016, 11:56:14 AM10/19/16
to FlatBuffers
Will update my own thread for posterity's sake. I had already used brew to install flatcc:

"brew install flatcc"

But I was not linking the library in like I was the ZMQ I had integrated earlier. Here's my updated build command:

gcc publisher.c -o bin/zmq_pub -lzmq -lflatcc

In my source I have the following imports:

#include "flatbuffers/StarBuffer_builder.h" // generated header file from my StarBuffer.fbs file
#include "flatbuffers/flatbuffers_common_builder.h"

Inside my flatbuffers folder I have:

 flatbuffers $ls
StarBuffer_builder.h StarBuffer_verifier.h flatbuffers_common_reader.h
StarBuffer_reader.h flatbuffers_common_builder.h

All good now!

mikkelfj

unread,
Oct 20, 2016, 3:25:33 AM10/20/16
to FlatBuffers


On Wednesday, October 19, 2016 at 5:56:14 PM UTC+2, thomasa...@gmail.com wrote:
Will update my own thread for posterity's sake. I had already used brew to install flatcc:

"brew install flatcc"

But I was not linking the library in like I was the ZMQ I had integrated earlier. Here's my updated build command:

gcc publisher.c -o bin/zmq_pub -lzmq -lflatcc

 
Good to hear that you solved it.

Most likely you want to link with -lflatccrt and not -lflatcc because the runtime library is much smaller. -lflatcc is used if you want to compile flatbuffer schema from within you application. But then again, the linker is probably smart enough to only take what it needs.

Reply all
Reply to author
Forward
0 new messages