title: Link VowpalWabbit C library in an existing C project
body: <p>We have an existing C project in which we want to use vowpal wabbit. We are able to generate the executable binary of the project without vowpalWabbit and that run fine as well. But when we link vowpalWabbit with the existing project the generated binary is somehow corrupted. We are able to compile and run a standalone program by linking vowpal wabbit library.</p>
  
  <p>We are trying to link VowpalWabbit with the existing project's makefile in the following manner:</p>
  
  <pre><code>CFLAGS      = -g -Wall -O2 -std=gnu99 -Wno-unused-variable -Wno-sign-compare
  CXXFLAGS    = -g -Wall -O2 -std=gnu++11 -fno-strict-aliasing -Wno-unused-variable -Wno-sign-compare
  
  VW_LIBS = $(VW_HOME)/vowpal_wabbit/vowpalwabbit/libvw.la $(VW_HOME)/vowpal_wabbit/vowpalwabbit/liballreduce.la 
  
  SRC = $(BASE_DIR)/$(VW)/$(SRC_DIR)
  SRC_FILES =$(SRC)/vw_predict_test.cpp
  
  ALL_SRC_FILES =  $(SRC_DIR)/test_main.cpp \
              $(SRC_FILES) 
  
  
  bin_PROGRAMS = test 
  
  ##  binary
  test_SOURCES = $(ALL_SRC_FILES)
  test_LDADD = $(VW_LIBS) -lthriftnb -lthrift -levent -lpthread -lm -lssl -lstdc++  
  test_CXXFLAGS = $(INCLUDES) $(CXXFLAGS)
  test_CFLAGS = $(INCLUDES) $(CFLAGS)
  </code></pre>
  
  <p>this makefile generates corrupted executable. When we do ldd on that executable we get the following message :</p>
  
  <pre><code>$ ldd test
          not a dynamic executable
  </code></pre>
  
  <p>Please guide how can we link vowpalWabbit in our executable.</p>
  
  <p>EDIT : For a better understanding, pasting the snapshot of our MakeFile.</p>
  
  <pre><code>AUTOMAKE_OPTIONS = foreign
  ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
  
  CFLAGS      = -g -Wall -O2 -std=gnu99 -Wno-unused-variable -Wno-sign-compare
  CXXFLAGS    = -g -Wall -O2 -std=gnu++11 -fno-strict-aliasing -Wno-unused-variable -Wno-sign-compare
  
  BASE_DIR    = .
  # Dependencies defined here
  COMMON      = common
  COMMONS_REPO    = @COMMONS_REPO@
  ANALYTICS_REPO  = @ANALYTICS_REPO@
  
  CRYPT           = $(COMMONS_REPO)/crypt
  SSSTORE     = $(COMMONS_REPO)/datastore/lib/C
  PREDICT     = $(ANALYTICS_REPO)/predict
  SRC_DIR     = src
  LIB_DIR     = lib
  INCLUDE_DIR     = include 
  OBJDIR      = build
  SCRIPT_DIR      = scripts
  CONF_DIR    = conf
  VW      = $(ANALYTICS_REPO)/vw
  
  VW_LIBS = $(VW_HOME)/vowpal_wabbit/vowpalwabbit/libvw.la $(VW_HOME)/vowpal_wabbit/vowpalwabbit/liballreduce.la
  
  
  # install directories
  TARGET_DIR      = /mytest
  LOG_DIR         = /mytest/processor/logs
  TARGET_DATA_DIR     = /mytest/processor/data/processor/trafficking
  TARGET_CONF_DIR     = $(TARGET_DIR)/conf
  TARGET_LIB_DIR      = $(TARGET_DIR)/libs
  TARGET_BIN_DIR      = $(TARGET_DIR)/bin
  TARGET_SCRIPTS_DIR  = $(TARGET_DIR)/scripts
  TARGET_LOG_DIR      = $(LOG_DIR)/{cores,processor/{app,archive,concat_logs}}
  
  ##  Thrift autogeneration
  THRIFT_EXEC     =  /usr/local/bin/thrift
  
  CC= /usr/local/bin/qrintf gcc
  CXX= /usr/local/bin/qrintf g++
  
  PROTOCOL_DIR    =../resources/schema
  TEST_THRIFT =$(PROTOCOL_DIR)/test.thrift
  
  GENERATED_THRIFT=generated/thrift
  
  $(GENERATED_THRIFT)/gen-cpp/testservice.cpp: $(TEST_THRIFT)
      mkdir -p $(GENERATED_THRIFT)
      $(THRIFT_EXEC) -o $(GENERATED_THRIFT) --gen cpp $(TEST_THRIFT)
  
  CRYPT_SRC_FILES = $(CRYPT)/src/utils.cpp $(CRYPT)/src/keyPair.cpp $(CRYPT)/src/keystore.cpp
  
  DATASTORE_SRC = $(BASE_DIR)/$(SSSTORE)/$(SRC_DIR)
  
  ## Protobuf autogeneration
  PROTOBUF_INSTALL_DIR  =  /usr/local
  PROTOBUF_EXEC    =  $(PROTOBUF_INSTALL_DIR)/bin/protoc
  COMMON_PROTO    =  common.proto
  
  PROCESSOR_SCRIPT_FILES = $(SCRIPT_DIR)/test_logs.pl 
  
  PROCESSOR_CONF_FILES = $(CONF_DIR)/server.tmpl
  
  SCHEMA_FILES = $(SSSTORE)/src/avro.click.schema 
  
  CI_SCRIPTS_DIR = scripts/CI
  
  GENERATED_PROTOBUF=$(DATASTORE_SRC)/generated/proto
  GENERATED_PROCESSOR_LOG_PROTO=generated/proto
  
  $(GENERATED_PROTOBUF)/common.pb.cc: $(DATASTORE_SRC)/$(COMMON_PROTO)
          mkdir -p $(GENERATED_PROTOBUF)
          $(PROTOBUF_EXEC) --proto_path=$(DATASTORE_SRC) --cpp_out=$(GENERATED_PROTOBUF) $(DATASTORE_SRC)/$(COMMON_PROTO) 
  
  BUILT_SOURCES = $(GENERATED_THRIFT)/gen-cpp/testservice.cpp $(GENERATED_PROTOBUF)/common.pb.cc 
  
  
  EDGE_DEFAULT_INCLUDES = -I$(INCLUDE_DIR) -I$(BASE_DIR)/$(CRYPT)/$(INCLUDE_DIR) \
                          -I$(BASE_DIR)/$(SSSTORE)/$(INCLUDE_DIR) \
                          -I$(BASE_DIR)/$(PREDICT)/$(INCLUDE_DIR) \
                          -I$(BASE_DIR)/$(COMMON)/$(INCLUDE_DIR) \
                          -I/usr/local/include/thrift \
                          -I$(GENERATED_THRIFT)/gen-cpp -DOPTIMIZE_RESPONSE_FOR_SIZE=1 \
                          -I$(PROTOBUF_INSTALL_DIR)/include/ \
                          -I$(GENERATED_PROTOBUF) -g -I${GENERATED_PROCESSOR_LOG_PROTO} -g
  
  if CENTOS64
  INCLUDES = $(EDGE_DEFAULT_INCLUDES) -I /usr/lib64/glib-2.0/include
  endif
  
  if CENTOS
  INCLUDES = $(EDGE_DEFAULT_INCLUDES) -I /usr/lib/glib-2.0/include
  endif
  
  if DEBIAN64
  INCLUDES = $(EDGE_DEFAULT_INCLUDES) -I /usr/lib/x86_64-linux-gnu/glib-2.0/include 
  endif
  
  if DEBIAN
  INCLUDES = $(EDGE_DEFAULT_INCLUDES) -I/usr/lib/i386-linux-gnu/glib-2.0/include
  endif
  
  
  COMMON_SRC = $(BASE_DIR)/$(COMMON)/$(SRC_DIR)
  COMMON_SRC_FILES = $(COMMON_SRC)/mytest_config.c $(COMMON_SRC)/mytest_utils.c 
  
  DATASTORE_SRC_FILES = $(DATASTORE_SRC)/data_store.c
  
  SRC = $(BASE_DIR)/$(VW)/$(SRC_DIR)
  SRC_FILES = $(SRC)/predict_model.c $(SRC)/predict_variable_util.c  $(SRC)/vw_predict_test.cc
  
  ALL_SRC_FILES =  $(SRC_DIR)/test_main.cpp \
              $(COMMON_SRC_FILES) $(DATASTORE_SRC_FILES) $(SRC_FILES) $(CRYPT_SRC_FILES) 
  
  
  bin_PROGRAMS = test 
  
  bindir = build
  
  #all-local: $(bin_PROGRAMS)
  #   rm -rf *.o
  
  ##  binary
  test_SOURCES = $(ALL_SRC_FILES)
  test_LDADD = $(VW_LIBS) -lthriftnb -lthrift -levent -lpthread -lm -lssl -lglib-2.0 -lstdc++ -lz -luuid -lcrypto -lcitrusleaf -lavro -lrt -lprotobuf
  test_CXXFLAGS = $(INCLUDES) $(CXXFLAGS)
  test_CFLAGS = $(INCLUDES) $(CFLAGS)
  
  clean-local:
      -rm -rf $(GENERATED_THRIFT)
  
  install: test
      mkdir -p $(TARGET_BIN_DIR) $(TARGET_CONF_DIR) $(TARGET_SCRIPTS_DIR) $(TARGET_DATA_DIR) $(TARGET_LOG_DIR)
      install -t $(TARGET_BIN_DIR) test
      install -t $(TARGET_BIN_DIR) $(CI_SCRIPTS_DIR)/*
      install -t $(TARGET_CONF_DIR) $(PROCESSOR_CONF_FILES) $(SCHEMA_FILES)
      install -t $(TARGET_SCRIPTS_DIR) $(PROCESSOR_SCRIPT_FILES)
  </code></pre>
  
  <p>EDIT2: As suggested we are now using <code>vw_predict_test.cpp</code> and compiling using g++ . We have <code>liballreduce.a</code>, <code>libvw.a</code>, <code>libvw_c_wrapper.a</code> libraries we wanna link to our executable, so we did the following :</p>
  
  <pre><code>test_SOURCES = $(ALL_SRC_FILES)
  test_LDADD = -lthriftnb -lthrift -levent -lpthread -lm -lssl -lglib-2.0 -lstdc++ -lz -luuid -lcrypto -lcitrusleaf -lavro -lrt -lprotobuf -lboost_program_options $(VW_HOME)/vowpalwabbit/.libs/liballreduce.a  $(VW_HOME)/vowpalwabbit/.libs/libvw.a  $(VW_HOME)/vowpalwabbit/.libs/libvw_c_wrapper.a 
  test_CXXFLAGS = $(INCLUDES) $(CXXFLAGS) 
  test_CFLAGS = $(INCLUDES) $(CFLAGS)
  </code></pre>
  
  <p>now we are getting boost exceptions like :</p>
  
  <pre><code>/vowpalwabbit/.libs/libvw.a(search_sequencetask.o): In function `SequenceSpanTask::initialize(Search::search&amp;, unsigned long&amp;, boost::program_options::variables_map&amp;)':
  search_sequencetask.cc:(.text+0x13f6): undefined reference to `boost::program_options::options_description::m_default_line_length'
  search_sequencetask.cc:(.text+0x142e): undefined reference to `boost::program_options::options_description::options_description(std::string const&amp;, unsigned int, unsigned int)'
  </code></pre>
  
  <p>We added -lboost_program_options in LDADD as well which didn't work.</p>