Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating dynamically loaded Linux libraries using Eclipse

Tags:

c++

c

linux

eclipse

I am writing a program in C++ using Eclipse. I want to compile it as a library for Linux, somthing like a DLL in Windows. How I can do this? Do you know any tutorials on how libraries are created?

I just want to understand that is the analog of a DLL for Linux and how to create it. I will be thankful for a small example.

like image 858
user101375 Avatar asked Jun 10 '26 20:06

user101375


2 Answers

In Linux, DLL's equivalents are (kind of anyway) shared objects (.so).

You need to do something like this:

$ g++ -c -fPIC libfile1.cpp
$ g++ -c -fPIC libfile2.cpp
$ g++ -shared -o libyourlib.so libfile1.o libfile2.o

Take a look at some open source C++ library projects for more information. GTKMM is one of them.

Of course, instead of compiling everything manually it's highly recommended to use a make file or an IDE (such as Eclipse with CDT or KDevelop or {pick your favorite here}) that will create one for you behind the scenes.

like image 116
Pablo Santa Cruz Avatar answered Jun 13 '26 11:06

Pablo Santa Cruz


In UNIX/Linux world DLLs are called shared libraries and typically have .so or .o extension.

See Linux HOWTO on shared libs.

like image 36
qrdl Avatar answered Jun 13 '26 11:06

qrdl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!