0

This maybe really stupid, but I faced the following error, while trying to compile certain code modules, using cmake

    acg_localizer_active_search.cc:(.text+0x43c6): undefined reference to            
    `ANNkd_tree::ANNkd_tree(float**, int, int, int, ANNsplitRule)'
    acg_localizer_active_search.cc:(.text+0x4441): undefined reference to    
   `ANNkd_tree::ANNkd_tree(float**, int, int, int, ANNsplitRule)'
  1. Please help me to understand what this undefined reference error means.
  2. The error line mentioned as '.text+0x...', is not understandable. How can I locate the error.

I have been stuck for quite some time, solving error after error and have ended up here. Please help me. Thanks in advance

Sorry for not adding the code. it is around 2000 lines and am not sure where to locate this error. its part of a software package, called acg_localizer.

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92
  • 1. It's a linker error, the linker can't find the symbol. You need to place the library or object file containing it on the command line. – Daniel Fischer May 27 '13 at 11:04
  • did you define and link `ANNkd_tree::ANNkd_tree`? – billz May 27 '13 at 11:04
  • Undefined reference is a linker error. It's not a compile error. You did not define the thing in the error message, you forgot to link the file that defines it, you forgot to link to the library that defines it, or, if it's a static library, you have the wrong order on the linker command line. Check which one. (Note that some linkers call it an unresolved external) – PlasmaHH May 27 '13 at 11:05
  • Thank you for your patience. The problem is the code is not mine. It is part of a software package. @billz . Please tell me how can I search to find the place it has not been linked. an easy way or smthng? – Lakshmi Narayanan May 27 '13 at 11:08
  • @DanielFischer how do I place the object on the command line? – Lakshmi Narayanan May 27 '13 at 11:08
  • 1
    you are using Linux, I guess you are using g++ to compile your application. the command suppose to be: g++ something.cpp -lANNkd_tree if you have libANNkd_tree.so file or something similar. please show us how do you compile and link your code – billz May 27 '13 at 11:12
  • 1
    That would be something like `g++ source.cpp object_file.o` or `g++ source.cpp -lLibrary`. But if it's a software package you want to install, you're probably not writing the makefile yourself, so it's likely not that you just need to add an object file or library to a compilation command. – Daniel Fischer May 27 '13 at 11:13
  • True. @DanielFischer. am using cmake. the cmake generates the make file. How can I identify the compilation command? – Lakshmi Narayanan May 27 '13 at 11:25
  • Sorry, I don't know cmake at all, can't help you there. – Daniel Fischer May 27 '13 at 11:37
  • 1
    You need to make sure that you have a [TARGET_LINK_LIBRARIES](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:target_link_libraries) command in your CMakeLists.txt that points to the required library. – SethMMorton May 27 '13 at 16:40
  • @SethMMorton can v have a chat outside, if you dont mind? gmail, or gtalk? am stuck at this for 2 days. I checked the cmake files. I dunno wat am looking at or where I a missing it. – Lakshmi Narayanan May 27 '13 at 16:56
  • 1
    @LakshmiNarayanan You can contact me at the e-mail on my user page. Make sure you copy and paste the CMakeLists.txt in the e-mail. – SethMMorton May 29 '13 at 04:47

1 Answers1

1

That's a link time error. The method ANNkd_tree::ANNkd_tree(float**, int, int, int, ANNsplitRule) cannot be found in any libraries and object files specified in the link command, although it is referenced.

You have to find out where it is defined, and make sure the library it is defined in comes after the library that uses it on the linker command line.

You can use the nm tool to find out which symbols (= variables, methods) are defined or used by an object file or library. Do a man nm (or search on google) to find out more.

Axel
  • 13,939
  • 5
  • 50
  • 79