1

I'm trying to compile a file with a shared library using the following command:

g++ -L. -lsubmit main.cpp

It outputs:

/tmp/ccRFpx1v.o: In function `main':
main.cpp:(.text+0x5): undefined reference to `Submit_test()'
collect2: error: ld returned 1 exit status

I have main.cpp and libsubmit.so in working directory. Here's my main.cpp

void Submit_test();
int main()
{
    Submit_test();
}

Here's nm -D --demangle libsubmit.so:

...
0000000000000e0e T Submit_test()
...

How should I compile that code?

A. K.
  • 311
  • 4
  • 16
  • Have you included the header file of the library? – izlin Dec 05 '16 at 16:18
  • Also have a look at this question: http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc – izlin Dec 05 '16 at 16:23

1 Answers1

3

This is probably a dup of how-to-know-if-one-shared-library-depends-on-another-shared-library-or-not

TLDR is that you should put linked libs after object/source files.

Community
  • 1
  • 1
yugr
  • 19,769
  • 3
  • 51
  • 96