You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Tanner Swett <sw...@mail.gvsu.edu> on 2012/07/19 02:48:59 UTC

Undefined reference errors when attempting to link with Thrift

Hi,

I'm trying to write a C++ application that uses Thrift. When I attempt
to build it, however, I get a bunch of error messages saying that
certain references to Thrift-related things are undefined. Here is the
full output of my g++ command: http://pastie.org/4280898

The build command itself is: g++ -Wall -o parcv_server
-DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H -I/usr/local/include/thrift
-lopencv_core -lopencv_contrib -lthrift parcv_constants.cpp
parcv_server.cpp parcv_types.cpp ParCV.cpp

Here's my main() function: http://pastie.org/4280905

libthrift.so is in /usr/local/lib/libthrift.so, and it does not appear
to contain any symbol with "TNonblockingServer" in it.

I have Thrift 0.8.0, and I am trying to build this application on an
AWS instance running RHEL 6.3.

Thank you for your help,
Tanner Swett

Re: Undefined reference errors when attempting to link with Thrift

Posted by Rush Manbert <ru...@manbert.com>.
On Jul 18, 2012, at 5:48 PM, Tanner Swett wrote:

> Hi,
> 
> I'm trying to write a C++ application that uses Thrift. When I attempt
> to build it, however, I get a bunch of error messages saying that
> certain references to Thrift-related things are undefined. Here is the
> full output of my g++ command: http://pastie.org/4280898
> 
> The build command itself is: g++ -Wall -o parcv_server
> -DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H -I/usr/local/include/thrift
> -lopencv_core -lopencv_contrib -lthrift parcv_constants.cpp
> parcv_server.cpp parcv_types.cpp ParCV.cpp
> 
> Here's my main() function: http://pastie.org/4280905
> 
> libthrift.so is in /usr/local/lib/libthrift.so, and it does not appear
> to contain any symbol with "TNonblockingServer" in it.
> 
> I have Thrift 0.8.0, and I am trying to build this application on an
> AWS instance running RHEL 6.3.
> 
> Thank you for your help,
> Tanner Swett

Hi Tanner,

I believe the non blocking server is in libthriftnb (at least it used to be in earlier versions of Thrift), so you should add -lthriftnb to your build command. (You should also be sure it got built and installed.)

- Rush

Re: Undefined reference errors when attempting to link with Thrift

Posted by Tanner Swett <sw...@mail.gvsu.edu>.
Wait, hold up. Common sense suddenly prevailed. What
http://stackoverflow.com/questions/6900839/error-when-trying-to-compile-webdis
said is that the person who submitted the question put -levent in the
wrong place. I realized that I wasn't using -levent at all, so I added
that to ./build, and the dang thing finally built.

Trying to run the resulting executable gave me "./parcv_server: error
while loading shared libraries: libthrift-0.8.0.so: cannot open shared
object file: No such file or directory". So, I ran sudo ldconfig, and
it apparently worked.

So, what it looks like is:

* Using -lthriftnb is probably necessary to cause TNonblockingServer
to be found.
* Building and installing thrift-0.8.0/lib/c_glib and/or
thrift-0.8.0/lib/cpp may be necessary in order to cause libthriftnb.so
to exist.
* Using the flags Prasanna's pkg-config commands gave me may or may
not be necessary for some reason I don't know.
* Using -levent is probably necessary to avoid "undefined reference"
errors caused by libthriftnb.so.
* It's necessary to run ldconfig when appropriate.

And the build command that finally worked: g++ -Wall -o parcv_server
-DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H -I/usr/local/include/thrift
-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -L/usr/local/lib
-lopencv_core -lopencv_contrib -lthrift -lthriftnb -lthrift_c_glib
-lgobject-2.0 -lglib-2.0 -levent parcv_constants.cpp parcv_server.cpp
parcv_types.cpp ParCV.cpp

Thanks again for your help.

Should I edit the page http://wiki.apache.org/thrift/ThriftUsageC++,
section "Appendix: About TNonblockingServer", to say that you must
include the flag -lthriftnb when compiling?

Tanner

Re: Undefined reference errors when attempting to link with Thrift

Posted by Tanner Swett <sw...@mail.gvsu.edu>.
On Wed, Jul 18, 2012 at 9:24 PM, Prasanna Ponnada <po...@gmail.com> wrote:
> On a system with pkg-config, something like this for glib would do:
> root@htgt:~# pkg-config --cflags thrift_c_glib
> -I/usr/local/include/thrift -I/usr/include/glib-2.0
> -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
> root@htgt:~# pkg-config --libs thrift_c_glib
> -L/usr/local/lib -lthrift_c_glib -lgobject-2.0 -lglib-2.0

Thank you for your help so far, Prasanna. I still haven't been able to
get my application to build. Here are the details of what I've done so
far:

Running these commands, either as myself or as root, said, "No package
'thrift_c_glib' found". I found thrift_c_glib.pc, and ran the command
"export PKG_CONFIG_PATH='/home/tswett/thrift-0.8.0/lib/c_glib/'".
pkg-config complained that the package glib-2.0 was not found, so I
installed glib2-devel using YUM. After that, I was able to get the
flags I wanted:

[tswett@appa ~]$ pkg-config --cflags thrift_c_glib
-I/usr/local/include/thrift -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include
[tswett@appa ~]$ pkg-config --libs thrift_c_glib
-L/usr/local/lib -lthrift_c_glib -lgobject-2.0 -lglib-2.0

Running pkg-config using sudo gave me the error "No package
'thrift_c_glib' found" again; presumably, sudo doesn't preserve
environment variables.

Running ./build again with the new flags added gave me this error:

/usr/bin/ld: cannot find -lthrift_c_glib
collect2: ld returned 1 exit status

I looked at http://wiki.apache.org/thrift/ThriftInstallation again and
discovered that there's a directory called thrift-0.8.0/lib/c_glib. I
assumed at that point that I was supposed to build and install the
contents of this directory. Attempting to run make gave me these
errors: http://pastie.org/4284583 In short, thrift.h was attempting to
#include <glib.h>, but the full path to glib.h is
/usr/include/glib-2.0/glib.h. So, I ran "export
C_INCLUDE_PATH='/usr/include/glib-2.0'" and tried running make again.
This time, I got a whole mess of errors: http://pastie.org/4284602

Like before, I ran 'export
C_INCLUDE_PATH="$C_INCLUDE_PATH:/usr/lib64/glib-2.0/include"' and
tried running make again. This time, it successfully built the
contents of thrift-0.8.0/lib/c_glib, so I ran sudo make install.

Finally, I ran ./build again and got almost exactly the same error as
I did originally: http://pastie.org/4284628

On a hunch, I searched thrift-0.8.0 for files with TNonblockingServer
in the name, and found a file called
libthriftnb_la-TNonblockingServer.o in thrift-0.8.0/lib/cpp. I also
looked in /usr/local/lib, and saw that there was a file called
libthriftnb.so. I vaguely remembered being told that this file was
important, but I also specifically remembered this file not existing.
So, I added -lthriftnb to ./build and ran it again. I got a new set of
errors, and the old ones had gone, but I don't know whether or not
this meant the old ones were fixed: http://pastie.org/4284660

I ran make in thrift-0.8.0/lib/cpp, and it appeared to do nothing
before exiting ("entering directory", then "nothing to be done", then
"leaving directory"). I then ran sudo make install, which may have
done something. Running ./build again gave the same errors as last
time.

The new contents of ./build were, at that point: g++ -Wall -o
parcv_server -DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H
-I/usr/local/include/thrift -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include -L/usr/local/lib -lopencv_core
-lopencv_contrib -lthrift -lthrift_c_glib -lgobject-2.0 -lglib-2.0
-lthriftnb parcv_constants.cpp parcv_server.cpp parcv_types.cpp
ParCV.cpp

Reading http://stackoverflow.com/questions/6900839/error-when-trying-to-compile-webdis
made me suspect that I was putting the -l flags in the wrong order,
and I vaguely remembered something about -lthriftnb having to go in a
certain place. I tried moving it immediately before -lthrift, and
immediately after; all of these gave the same set of errors.

So, I'm currently stumped.

Tanner

Re: Undefined reference errors when attempting to link with Thrift

Posted by Prasanna Ponnada <po...@gmail.com>.
On Wed, Jul 18, 2012 at 5:48 PM, Tanner Swett <sw...@mail.gvsu.edu> wrote:
> Hi,
>
> I'm trying to write a C++ application that uses Thrift. When I attempt
> to build it, however, I get a bunch of error messages saying that
> certain references to Thrift-related things are undefined. Here is the
> full output of my g++ command: http://pastie.org/4280898
>
> The build command itself is: g++ -Wall -o parcv_server
> -DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H -I/usr/local/include/thrift
> -lopencv_core -lopencv_contrib -lthrift parcv_constants.cpp
> parcv_server.cpp parcv_types.cpp ParCV.cpp
>
> Here's my main() function: http://pastie.org/4280905
>
> libthrift.so is in /usr/local/lib/libthrift.so, and it does not appear
> to contain any symbol with "TNonblockingServer" in it.

On a system with pkg-config, something like this for glib would do:
root@htgt:~# pkg-config --cflags thrift_c_glib
-I/usr/local/include/thrift -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
root@htgt:~# pkg-config --libs thrift_c_glib
-L/usr/local/lib -lthrift_c_glib -lgobject-2.0 -lglib-2.0

thanks
Prasanna