0

I wrote c++ code that in including some libraries that I included using -l option. The code is right on my machine but I want finally run this code on another machine named B. I built it on my machine using c++11 and GNU GCC Compiler and attempt to run it on machine B but it errors :

error while loading shared libraries: libcppkafka.so.0.1: cannot open shared object file: No such file or directory

How can I build c++ code with all dependencies to disappear this error?

note: libcppkafka.so.0.1 is in my machine in path /usr/local/lib

note: I use codeblock IDE, so I appreciate that if solution will be codeblock compatible

note: Both machines are ubuntu 16.04

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Soheil Pourbafrani
  • 3,249
  • 3
  • 32
  • 69

2 Answers2

1

In order to achieve your goal you have 2 options.

  1. You can copy your shared libraries(libcppkafka.so) with your executable and configure its location correctly.

  2. Or you can avoid shared libraries by statically linking them to your program. For this you'll need to have static version of those libraries (libcppkafka in your case)

miradham
  • 2,285
  • 16
  • 26
0

Since both machines are running the same distribution and version (Ubuntu 16.04), you could find out on the first machine the installed and useful packages, and install these on the second machine.

You'll need to copy the non-packaged things, e.g. in (some part of) /usr/local/lib

You could consider making a real .deb package for your thing (but that is more work).

Notice that an IDE is just an IDE and don't compile anything (an IDE is running external compiler commands; your compiler is GCC invoked as g++). You should perhaps compile on the command line (and you could even make that some shell script, to run on the other machine).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547