thrift cpp sample code compile error
The -lthrift option should be at the end of the command line, after the cpp files.
I've compiled successfully the sample on Ubuntu 11.10/gcc 4.6.1/boost 1.49 with the following makefile:
THRIFT_VER =thrift-0.8.0
USR_DIR =${HOME}/usr
THRIFT_DIR =${USR_DIR}/${THRIFT_VER}
INCS_DIRS =-I${USR_DIR}/include -I${THRIFT_DIR}/include/thrift
LIBS_DIRS =-L${USR_DIR}/lib -L${USR_DIR}/${THRIFT_VER}/lib
CPP_DEFS =-D=HAVE_CONFIG_H
CPP_OPTS =-Wall -O2
LIBS =-lthrift
GEN_SRC = ../gen-cpp/SharedService.cpp \
../gen-cpp/shared_types.cpp \
../gen-cpp/tutorial_types.cpp \
../gen-cpp/Calculator.cpp
GEN_INC = -I../gen-cpp
default: server client
server: CppServer.cpp
g++ ${CPP_OPTS} ${CPP_DEFS} -o CppServer ${GEN_INC} ${INCS_DIRS} CppServer.cpp ${GEN_SRC} ${LIBS_DIRS} ${LIBS}
client: CppClient.cpp
g++ ${CPP_OPTS} ${CPP_DEFS} -o CppClient ${GEN_INC} ${INCS_DIRS} CppClient.cpp ${GEN_SRC} ${LIBS_DIRS} ${LIBS}
clean:
$(RM) -r CppClient CppServer
Take care to put tabs at the beginning of the make commands.
My layout is:
boost 1.49 installed in ${HOME}/usr
boost headers in ${HOME}/usr/include
boost libs in ${HOME}/usr/libthrift 0.8.0 installed in ${HOME}/usr/thrift-0.8.0
thrift headers in ${HOME}/usr/thrift-0.8.0/include
thrift libs in ${HOME}/usr/thrift-0.8.0/lib
To run the samples:
#!/bin/bash
THRIFT_VER=thrift-0.8.0
USR_DIR=${HOME}/usr
THRIFT_DIR=${USR_DIR}/${THRIFT_VER}
export LD_LIBRARY_PATH=${THRIFT_DIR}/lib:${LD_LIBRARY_PATH}
exec $1