title: gcc undefined reference error on Ubuntu
body: <p>I have a strange problem and i have gone through all similar questions but can't find an answer. </p>
  
  <p>I am trying to compile some code which keeps throwing up undefined reference error even though the library is specified using -l and is in the LD_LIBRARY_PATH too. I can't figure out the reason. Here is an example </p>
  
  <blockquote>
    <p>gcc -L/home/sam/gmdb/lib -L/home/sam/db/add-ons/lib
    -L/home/sam/convert/lib -L/home/sam/rtana/lib -L/home/sam/rtana/add-ons/lib   -o /home/sam/gmdb/bin/server /home/sam/db/obj/tools/server/server.o
    /home/sam/db/obj/tools/common/tool_data_parse.o
    /home/sam/db/obj/tools/common/tool_param.o
    /home/sam/gmdb/obj/tools/common/tool_public.o -lgmcommon
    -L/home/sam/db/add-ons/vpp/lib/suse -lipsi_crypto -lipsi_osal -lipsi_pse -lipsi_ssl -lgmmd5 -lgmkernel -lgmpl -lgmrep -lgmsqlserver -lgmsqlclient -lconvert -lrtana -lglog -lgflags -lprotobuf -lre2 -lboost_timer -lnuma -lpthread -lm -lrt</p>
  </blockquote>
  
  <p>The list of undefined errors is long but the first one is</p>
  
  <blockquote>
    <p>/home/usama/convert/lib/libconvert.so: undefined reference to
    `numa_num_configured_cpus'</p>
  </blockquote>
  
  <p>So as you can see it's complaining about a method in libnuma. libnuma is provided a -lnuma as you can see, and is present in /usr/lib </p>
  
  <p>The error mentions libconvert which is just a shared library that has a call to numa_num_configured_cpus but is not linked with libnuma, and it shouldn't matter since libconvert is just an so file. I am providing the -lnuma while generating the executable as you can see above. Here is the nm out on libconvert</p>
  
  <pre><code>nm -C -u convert/lib/libconvert.so | grep numa*
                   U google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)
                   U numa_num_configured_cpus
                   U numa_num_configured_nodes
  </code></pre>
  
  <p>I did try to compile with --unresolved-symbols, which results in successful compilation but the binary doesn't run again complaining about undefined symbols. </p>
  
  <p>My GCC version is </p>
  
  <pre><code>gcc --version
  gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
  Copyright (C) 2012 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>And Ubuntu is 64 bit Ubuntu 12.10</p>
  
  <p>Does anyone have a clue if i am hitting a bug or what is going on?</p>