How to compile gcc with shared library?

梦想的初衷 提交于 2019-12-11 11:13:47

问题


I create shared library libpl.so.

I use this command to create connections:

ln -s libpl.so.1.0.1 libpl.so.1
ln -s libpl.so.1.0.1 libpl.so

And now I try to compile my program using:

gcc main.c -o main -L. -libpl

but I have erros:

/usr/bin/ld: cannot find -libpl
collect2: error: ld returned 1 exit status

What should I do to fix it ? How compile it ?


回答1:


This line should help:

export LD_LIBRARY_PATH=/path/to/libpl.so:$LD_LIBRARY_PATH

You should follow this tutorial on shared libraries on linux

This tutorial may answer to all your questions.




回答2:


This line:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`pwd`"

working correctly.

Compiling with:

gcc main.c -o main -L. -lpl

Runing with:

./main


来源:https://stackoverflow.com/questions/36824381/how-to-compile-gcc-with-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!