October 26, 2024
Chicago 12, Melborne City, USA
C#

gcc undefined reference error on Ubuntu


I have a strange problem and i have gone through all similar questions but can’t find an answer.

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

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

The list of undefined errors is long but the first one is

/home/usama/convert/lib/libconvert.so: undefined reference to
`numa_num_configured_cpus’

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

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

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

I did try to compile with –unresolved-symbols, which results in successful compilation but the binary doesn’t run again complaining about undefined symbols.

My GCC version is

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.

And Ubuntu is 64 bit Ubuntu 12.10

Does anyone have a clue if i am hitting a bug or what is going on?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video