0

I've got a cpp file a.cpp and a shared object libA.so it's gonna use under the same folder, however, when I tried to use g++ to link them together, it declares that it cannot find the library (I checked with ldd afterwards).

This is the command I used g++ a.cpp -I . -L. -lA

Any idea how this might be solved?

Possible duplicates: building and linking a shared library

Emma He
  • 183
  • 2
  • 14
  • Do you mean you checked with `ldd` rather than `ld`? Anyway, you need to tell the run time linker how to find the library, it's not enough to tell `g++` how to find it. There are thousands of duplicate questions, search for `LD_LIBRARY_PATH`. – Jonathan Wakely Dec 26 '17 at 10:22
  • This is already mentioned in a comment on the question you linked from earlier: https://stackoverflow.com/questions/27208932/link-so-file-to-cpp-file-via-g-compiling#comment42899795_27208932 – Jonathan Wakely Dec 26 '17 at 10:28
  • 1
    Found the answer from this post http://gernotklingler.com/blog/creating-using-shared-libraries-different-compilers-different-operating-systems/ – Emma He Dec 27 '17 at 04:05

1 Answers1

-1

use g++ -o a a.cpp -I . -L. your-so-name.so

Jay Bhaskar
  • 157
  • 2
  • 11