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)'
Please help me to understand what this undefined reference error means.
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.
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.
Related
Here's my issue:
In my project, I have a class called Match. Now, I would like to use somebody else's code to compare their results. They, unfortunately, also have a class called Match.
OK, so I thought I'd do:
namespace MonteCarlo {
#include "monte-carlo/match.hpp"
}
I appreciate that this is not best practice, but I really just want to test the output for now rather than rewrite everything in new namespaces.
Then, I made a shared library out of his code, and linked it:
LIBPATHS = -L mysql_connector/lib/ -Lmonte-carlo/lib
LIBS = -l mysqlcppconn -l boost_date_time -l boost_iostream boost_system -l boost_filesystem -l MonteCarloTennis
But when I build, I get:
evaluator.cc:139: undefined reference to `MonteCarlo::Match::Match(double, double, double, double, bool, bool)'
evaluator.cc:140: undefined reference to `MonteCarlo::Match::play_match()'
But in the library, using nm, I see:
0000000000001286 T Match::Match(double, double, double, double, bool, bool)
0000000000001286 T Match::Match(double, double, double, double, bool, bool)
I am really new to libraries, so I could really use your advice. Am I getting this linker error because my library is not linking correctly, or because I wrapped the Match class in the namespace and thus the two functions in the library are not found?
Thank you to Joachim Pileborg for providing the answer!
Wrapping the #include in a namespace meant the linker couldn't find the corresponding function in the library. I have now fixed the issue by putting my colleague's code into namespaces.
So a very simple error, but there was so much that could have gone wrong (my first time building a library!) that it was really helpful to get Joachim's advice. Thanks again!
Recently I found an example of how to use the expect library in C++. I tried to compile it, but the compiler (g++) said, that tcl8.5/expect.h doesn't exists. So I tried to include tcl8.6/expect.h - still the same error. I checked the /usr/include/ directory and I wasn't surprised when I've noticed, that there is no tcl8.x directory.
I've searched for files with "expect" in their name. Here's what I found:
/usr/include/expect_tcl.h
/usr/include/expect_comm.h
/usr/include/expect.h
Unfortunately when I tried to include any of these I got the following list of errors during compilation:
> g++ test.cpp -Wall -std=c++0x -ltcl8.6 -lglog -o test
/tmp/cce8k1BA.o: In function `task(std::string const&, std::string const&, std::string const&)':
test.cpp:(.text+0x16): undefined reference to `exp_is_debugging'
test.cpp:(.text+0x20): undefined reference to `exp_timeout'
test.cpp:(.text+0x38): undefined reference to `exp_popen'
etc...
How can I solve this problem?
[EDIT]
When I tried to link it with the expect lib (-lexpect) I got the following error:
/usr/bin/ld: cannot find -lexpect
collect2: error: ld returned 1 exit status
I'm sure that both - tcl8.6 and expect 5.45-4 are installed.
The usual way of distributing Expect these days puts the shared library in a non-standard location and loads it dynamically by full pathname. This works well and is minimal fuss for most people, but does make it rather hard to use Expect's C interface in your own code.
The easiest way is going to be to build your own copy from source, especially as that will give you control over how exactly it was built. This can particularly include keeping the majority of symbols in the library instead of stripping them on install, which will help a lot with debugging. You probably ought to use the current supported version. (Yes, it's a release from several years ago. It doesn't need a lot of support effort most of the time.)
You haven't linked to the expect library during your build. Add -lexpect to your g++ command.
I've been having some difficulty compiling a piece of C++ code for the physics engine Bullet Physics, and was hoping to get some advice.
This is my first time using gcc as a compiler, and including directories for compiling in general, so I'm going to give my whole process of problem-solving because I'm not sure where I went wrong or what the pertinent information is.
When I first tried to compile the code I got a fatal error about "No such error or directory", so I decided to add the directory with the -I option (1). It fixed the first error, but another popped up. Again, I was able to make the error go away with a -I option to the directory needed(2).
Then I got a whole long list of errors like the following:
main.cpp:(.text+0x33): undefined reference to 'RagdollDemo::initPhysics()'
main.cpp:(.text+0x84): undefined reference to 'glutmain(int, char**, int, int, char const*, DemoApplication*)'
/tmp/cc4MqhHm.o: In function '__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0xe7): undefined reference to `std::ios_base::Init::Init()'
I tried a few different things, but the solution ended up using my home bullet folder (or usr/local/include/bullet/) with the --sysroot option (3).
This created a lot of errors for the C++ header files, and then I linked to a few more directories with -I (4-5), but at after one of the added directories the same set of errors that I thought I solved with the --sysroot addition popped up again (6).
I can't tell what to do now. I would guess that declaring the bullet folder as my root makes it impossible for the compiler to find the required C++ files in my actual root directories, but I don't what to do about that... and when I tried including the C++ files I needed, the compiler seemingly forgot I told it to use bullet as my root.
Final compilation I tried before I gave up and realized asking for help might be better than spending 3 hours looking at documentation without any idea of what the exact problem is. Numbers correspond to the steps above.
gcc
(3)--sysroot=/home/josh/bullet-2.82-r2704/
(1)-isystem/home/josh/bullet-2.82-r2704/Demos/OpenGL/
(2)-isystem/home/josh/bullet-2.82-r2704/src/
(4)-I/usr/include/
(5)-I/usr/include/c++/4.8
(6)-I/usr/include/x86_64-linux-gnu/c++/4.8/
./main.cpp
I'm using Ubuntu 14.04 LTS and my OS and emacs 24.3.1 as my IDE.
Any help would be greatly appreciated.
Best,
Josh
What you are seeing is not include issue. Linker is failing to link with symbols. You need to link with proper library, for example lglut
I'm using Code Blocks IDE and I want to install Tiled Map Editor for SFML. So, I downloaded the source and imported it to my project. Unfortunately, the build finished with an error due to missing zlib library. I downloaded it and built again. This time I received an error that reads:
undefined reference to `inflateInit2_'|
undefined reference to `inflateEnd'|
undefined reference to `inflateEnd'|
On the Internet I found the advice to join the linker command -lz, but the compiler refuses throwing the error: cannot find -lz. Does anyone know how to fix it?
Use the option -L<path> to tell the linker where to find libz.so.x.y.z.
For your reference: http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
you can see where your zlib is installed like this :
/sbin/ldconfig -p| grep libz.so
it should find one or more entries if installed, otherwise it will return blank line
I am trying to compile a giant software package, and this is the last hurdle I can't seem to figure out.
I'm getting errors like:
RNDiracDeterminantBase.cpp:(.text+0x22bf): undefined reference to `dgetrf_'
RNDiracDeterminantBase.cpp:(.text+0x2524): undefined reference to `dgetri_'
RNDiracDeterminantBase.cpp:(.text+0x3005): undefined reference to `dgetri_'
../../lib/libqmcwfs.a(RNDiracDeterminantBase.cpp.o): In function `qmcplusplus::RNDiracDeterminantBase::ratio(qmcplusplus::ParticleSet&, int, qmcplusplus::ParticleAttrib<qmcplusplus::TinyVector<double, 3u> >&, qmcplusplus::ParticleAttrib<double>&)':
RNDiracDeterminantBase.cpp:(.text+0x4156): undefined reference to `dgemv_'
RNDiracDeterminantBase.cpp:(.text+0x420f): undefined reference to `dger_'
Google reveals that these references are to Intel's MKL library. However, I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in:
/mkl/lib/intel64/
Can post more information if requested.
I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in: /mkl/lib/intel64/
The fact that there are tons of files doesn't mean you have to try each library in turn.
To find out which library defines the symbols you want, run this command:
cd /mkl/lib/intel64
nm -A *.a | egrep '[TWBD] (dger_|dgemv_|dgetrf_|dgetri_)$'
Also be sure to put libraries at the end of your link line, as the order of archive libraries on command line matters.
Based on the incomplete information you provided, it's likely that you need libmkl_intel_lp64.a, libmkl_gnu_thread.a, and libmkl_core.a.
Intel MKL has a built-in tool to help you figure out linking: /mkl/tools/mkl_link_tool. This tool is also available on the web: http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor. Use this tool to get the exact link line for your situation.
You should have asked your question on the official MKL forum (http://software.intel.com/en-us/forums/intel-math-kernel-library). You'd get the answer for this type of questions within hours instead of days.
I had a similar problem when setting up mingw on windows.
The following library linking order worked for me with gcc:
mkl_intel_thread
mkl_rt
mkl_core
mkl_intel_lp64
Hope this helps anyone stuck with this problem.