0

I have the following situation. I've written a library (libA) with some helper classes and an application (app) which depends on this library. In one of the cpp files of the app I call a function from libA which has the following form:

int computeSomething(int param)
{

    int val;

    // Call to an internal libA function.
    val = computeInternal(param);

    return val;
}

During building of my app I get a linking error "undefined reference to computeInternal" which leads to a following error message "collect2: error: ld returned 1 exit status". Anyone has an idea why the linker requires a reference to an internal libA function?

What is more interesting my application was built successfully using Microsoft tools.

gchlebus
  • 41
  • 3
  • 1
    Did you link with your library? (i.e. gcc -Lyourlibpath -lyourlibname) – ikh Mar 24 '14 at 10:24
  • Could you please add the command you're using to build your application, plus the contents of your Makefile (if you're using make)? – Frank Schmitt Mar 24 '14 at 10:24
  • You need to include your linker command line and the resulting error messages. – Paul R Mar 24 '14 at 10:24
  • 1
    "Anyone has an idea why the linker requires a reference to an internal libA function?" - because how would it know what to link in otherwise? You have to link together **all** the object files. Also, this shows that you obviously don't know what compilation and linkage are for. Google "C++ compilation process". Plus, this has nothing to do with Microsoft tools. It's only that you didn't link all files together, whereas your Microsoft-specific IDE automatically did that. – user3447428 Mar 24 '14 at 10:26
  • In principle I build my application with following commands: g++ -c -IincludePathofLibA -o app.o app.cpp, and then g++ -o app app.o -LlibraryPath -llibName – gchlebus Mar 24 '14 at 10:59
  • If this is exact command you're using and `liblibname.so` contains `computeInterval` - there would be no error message. So one of this two things is not [entirely] true, or `computeInterval` have different declaration in library and in your app. – keltar Mar 24 '14 at 11:50
  • But I don't declare the computeInternal function anywhere in my app, because it is an internal function of libA. Is there a way to check whether the .so file contains a given function? – gchlebus Mar 24 '14 at 13:11
  • Bah... What do you mean 'not declared because it is internal' if you used this function in your app? Regardless, list of symbols could be dumped like explained in http://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file – keltar Mar 25 '14 at 03:06
  • I meant, that in my app there is no explicit call to the `computeInternal`. This function is invoked only by the libA itself. I'm confused, keltar could you elaborate? – gchlebus Mar 25 '14 at 13:18

0 Answers0