Reputation: 371
everybody, I am getting started develop a C++ project and in this project I must use some opensource project have several dll file. Then I have a question "How to build C++ project embed all dynamic link library in exe file?" Thank for help!
Note: Sorry, I forgot that I'm using visual studio compiler on x86
Upvotes: 1
Views: 2093
Reputation: 70204
There is no general answer to your question. It depends whether you need it to be cross platform or not.
However, since you're mentioning "visual studio compiler on x86", I bet you're targeting Windows. In such a case you have two options:
the official and recommended way: embed your dlls as resources in your executable; then when your program starts you extracts these dlls somewhere on the disk as temporary files (beware file permissions) then you use LoadLibrary
+ GetProcAddress
the hackish way: you write a PE executable loader in order to circumvent the fact that the Windows API only offers a way to LoadLibrary
from a file on disk. By writing your own PE loader you'll be able to load a dll directly from a memory stream. Then again, I'm just mentioning it for reference but it's by no means something one should do
Finally, you need to comply to the license chosen by those opensource projects you're using. My answers gives technical directions about how to achieve your goal; it doesn't mean the license of the project you're using allows you to do so.
Upvotes: 2