Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement to create a shared object library(.so) for qt project C++. I have to use this library in another project. Means the functions I have to call from another project.

Can you please help me to how to create a library. I am using Qt4.7 version in Linux environment.

What I have tried:

Example:
I have a project abc.pro
abc.cpp contains abc::display() function

Now I have another project xyz.pro
xyz.cpp contains xyz::show() function
So from show() function I have to call display function and I have to use abc project as abc.so as a library.
How to make it possible.
Posted
Updated 1-Apr-19 1:44am
Comments
11917640 Member 1-Apr-19 10:23am    
If you are using Qt Creator, it has "C++ Library" item in the File - New File or Project dialog.

1 solution

The same way you create any shared object library: linux create shared object - Google Search[^].
 
Share this answer
 
Comments
Member 13740197 1-Apr-19 9:04am    
Thanks for the reply.
The link which you have sent is giving an explanation about creating a library using .c files. But in my case, the whole qt project(which consists of default classes and functions because of this I could not convert into .cpp files) should convert into a library.
Richard MacCutchan 1-Apr-19 9:39am    
It does not matter what language the source code is in C or C++, the shared object library is created from the resulting objects. I would suggest you read the man pages for the ld(1): GNU linker - Linux man page[^].
Member 13740197 2-Apr-19 6:37am    
I have tried with object files like below
gcc -shared -o libc.so camcapture.o capture-win.o ctrl-tab.o designer.o general-tab.o glMsgDialog.o json.o main.o qrc_rsc.o qv4l2.o v4l2-api.o

But I am getting below error

/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: camcapture.o: Relocations in generic ELF (EM: 40)
camcapture.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status


What is this error and do I need to do anything to do with ld command and object files.
Richard MacCutchan 2-Apr-19 8:46am    
Like it says, the object file is in the wrong format.
Member 13740197 3-Apr-19 4:56am    
Actually the object files I have taken from qt project folder after building.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900