How to statically link "protoc" on linux?

5,616 views
Skip to first unread message

Jacky

unread,
Jun 30, 2010, 9:13:23 AM6/30/10
to Protocol Buffers
Hi All,

I'm a newbie here, please forgive me if the question looks silly. :)

I've tried "./configure && make && make install" to install protocol
buffer 2.3.0 on my Ubuntu 10.4 machine, and it works fine.

On the other hand, I'm thinking about whether it's possible to build
an "independent" executable file / directory which I can copy to other
machine and run directly.

I've tried "./configure --enable-static" but it seems doesn't work.

Any suggestions are highly appreciated.

Thanks,
Jacky

Josh Hartman

unread,
Jun 30, 2010, 12:43:02 PM6/30/10
to Protocol Buffers
./configure --disable-shared worked for me on OSX. Please let me know how it goes!

Josh


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Jacky

unread,
Jul 9, 2010, 7:31:18 AM7/9/10
to Protocol Buffers
Many thanks! sorry for the late reply - I've just went back. :)

I tried this:

jacky@alpha:~/workspace/protobuf-2.3.0/src$ ldd protoc
linux-vdso.so.1 => (0x00007fff427ba000)
libz.so.1 => /lib/libz.so.1 (0x00007fe2e1485000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fe2e1171000)
libm.so.6 => /lib/libm.so.6 (0x00007fe2e0eed000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fe2e0cd6000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fe2e0ab9000)
libc.so.6 => /lib/libc.so.6 (0x00007fe2e0736000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe2e16b9000)

It seems like the binary file still depends on some gcc-related shared
objects.

Thanks!
- Jacky

On Jul 1, 12:43 am, Josh Hartman <atomicfo...@gmail.com> wrote:
> ./configure --disable-shared worked for me on OSX. Please let me know how it
> goes!
>
> Josh
>
> On Wed, Jun 30, 2010 at 6:13 AM, Jacky <jacky.chao.w...@gmail.com> wrote:
> > Hi All,
>
> > I'm a newbie here, please forgive me if the question looks silly. :)
>
> > I've tried "./configure && make && make install" to install protocol
> > buffer 2.3.0 on my Ubuntu 10.4 machine, and it works fine.
>
> > On the other hand, I'm thinking about whether it's possible to build
> > an "independent" executable file / directory which I can copy to other
> > machine and run directly.
>
> > I've tried "./configure --enable-static" but it seems doesn't work.
>
> > Any suggestions are highly appreciated.
>
> > Thanks,
> > Jacky
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Protocol Buffers" group.
> > To post to this group, send email to prot...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > protobuf+u...@googlegroups.com<protobuf%2Bunsu...@googlegroups.com>
> > .

Oliver Jowett

unread,
Jul 9, 2010, 9:08:12 AM7/9/10
to Jacky, Protocol Buffers
Jacky wrote:
> Many thanks! sorry for the late reply - I've just went back. :)
>
> I tried this:
>
> jacky@alpha:~/workspace/protobuf-2.3.0/src$ ldd protoc
> linux-vdso.so.1 => (0x00007fff427ba000)
> libz.so.1 => /lib/libz.so.1 (0x00007fe2e1485000)
> libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fe2e1171000)
> libm.so.6 => /lib/libm.so.6 (0x00007fe2e0eed000)
> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fe2e0cd6000)
> libpthread.so.0 => /lib/libpthread.so.0 (0x00007fe2e0ab9000)
> libc.so.6 => /lib/libc.so.6 (0x00007fe2e0736000)
> /lib64/ld-linux-x86-64.so.2 (0x00007fe2e16b9000)
>
> It seems like the binary file still depends on some gcc-related shared
> objects.

I actually spent a while today dealing with the same issue, and
eventually admitted defeat and gave up on trying to convince libtool and
friends to behave.

Instead I did this:

./configure --disable-shared
make
rm src/protoc && make # this is just to make the link command obvious

Then rerun the final invocation of g++ that libtool runs to link protoc,
adding "-static" to it.

(Yes, I know, static binaries are evil, but so is libstdc++ version skew)

-O

Kenton Varda

unread,
Jul 9, 2010, 3:11:24 PM7/9/10
to Oliver Jowett, Jacky, Protocol Buffers
LDFLAGS=-static isn't good enough?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.

Oliver Jowett

unread,
Jul 10, 2010, 8:42:31 AM7/10/10
to Kenton Varda, Jacky, Protocol Buffers
Kenton Varda wrote:
> LDFLAGS=-static isn't good enough?

Nope, something along the way eats it.

-O

Chao Wang

unread,
Jul 10, 2010, 12:16:36 PM7/10/10
to Kenton Varda, Oliver Jowett, Protocol Buffers
Will it solve the libz.so.1 linking problem?

Thanks,
Jacky

Deepak Bala

unread,
Nov 20, 2011, 11:27:02 PM11/20/11
to Chao Wang, prot...@googlegroups.com
I understand this thread is really old, but I thought updating the
group with a solution might help those that stumble across this in the
future.

I had some success removing dynamic dependencies on protoc and making
the binary static using Ermine. Please refer to this wiki -
http://www.coderanch.com/how-to/java/ProtocIndependentBinary

Thanks
- Deepak

On Jul 10 2010, 9:16 pm, Chao Wang <jacky.chao.w...@gmail.com> wrote:
> Will it solve the libz.so.1 linking problem?
>
> Thanks,
> Jacky
>
>
>
>
>
>
>
> On Sat, Jul 10, 2010 at 3:11 AM, Kenton Varda <ken...@google.com> wrote:
> > LDFLAGS=-static isn't good enough?
>

> >> protobuf+u...@googlegroups.com<protobuf%2Bunsu...@googlegroups.com>

Alan Duan

unread,
Mar 3, 2014, 9:00:24 AM3/3/14
to prot...@googlegroups.com
This is one way to build the protobuf compiler (protoc) statically.
tar xfz protobuf-x.x.x.tar.gz
cd protobuf-x.x.x
./configure
make
cd srv
sed -i 's/^AM_LDFLAGS\(.*\)$/AM_LDFLAGS\1 -all-static/' Makefile
make

./protoc --version
file protoc
ldd protoc

cody....@gmail.com

unread,
Sep 2, 2016, 3:07:15 PM9/2/16
to Protocol Buffers
It works for me. I use protobuf 2.5.0.

在 2010年7月1日星期四 UTC+8上午12:43:02,Joshua Hartman写道:
Reply all
Reply to author
Forward
0 new messages