1

I am trying to create a shared library in linux fro a program which uses opencv and tesseract with dynamic linking

I followed link My code is as follows

g++ -c Serial_Key.cpp -fPIC -o cdserial `pkg-config --cflags --libs opencv` -llept -ltesseract g++ -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 cdserial ln -sf libctest.so.1.0 libctest.so ln -sf libctest.so.1.0 libctest.so.1 g++ -c Test.cpp -fPIC -o cprog -lctest `pkg-config --cflags --libs opencv` -llept -ltesseract 

Here Test.cpp is a simple file as follows

#include <stdio.h> int Serial_key(); int main(){ int x=Serial_key(); printf("Success"); return 0;} 

somehow its giving error for ./cprog as ./cprog: cannot execute binary file: Exec format error

I feel that i am doing some fundamental mistake at 2nd line (g++ -shared) Please guide

1 Answer 1

1

After a little bit more head crunching, i found several silly mistakes in my above mentioned problem

Here is the corrected flow for others who may get stuck in similar problem

  1. First compile

    g++ -c Serial_Key.cpp -fPIC -o cdserial

  2. Create Shared library by mentioning libraries and their path with soname

    g++ -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 cdserial -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs -lopencv_videoio -llept -ltesseract -L/usr/local/lib

  3. Link soname with library

    ln -sf libctest.so.1.0 libctest.so ln -sf libctest.so.1.0 libctest.so.1

  4. Compile and create object for Test File

    g++ Test.cpp -fPIC -o cprog -lctest -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs -lopencv_videoio -llept -ltesseract -L/usr/local/lib

  5. Copy share library files to local lib

    cp libctest.so /usr/local/lib cp libctest.so.1 /usr/local/lib cp libctest.so.1.0 /usr/local/lib

  6. Ensure $LD_LIBRARY_PATH is pointing to shared library path

    export LD_LIBRARY_PATH=/usr/local/lib

  7. Run

    ./cprog

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.