www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Adding libraries to an executable

reply "Anton Alexeev" <alexanto gmx.de> writes:
I've written a program which uses curl library. So on a PC 
without curl the program will not work until you install the 
library. Is there a way to put the curl library in the executable?
Sep 06 2013
next sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Friday, September 06, 2013 23:31:57 Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC
 without curl the program will not work until you install the
 library. Is there a way to put the curl library in the executable?
Statically link it. - Jonathan M Davis
Sep 06 2013
next sibling parent "Anton Alexeev" <alexanto gmx.de> writes:
On Friday, 6 September 2013 at 22:31:52 UTC, Jonathan M Davis 
wrote:
 On Friday, September 06, 2013 23:31:57 Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC
 without curl the program will not work until you install the
 library. Is there a way to put the curl library in the 
 executable?
Statically link it. - Jonathan M Davis
How can I do that? I have compiled my program with this command: "dmd -L-lphobos2 -L-lcurl test.d " Excuse me for that dumb question but I'm really new to compiled languages. I've written some code in Java but it's not the same.
Sep 07 2013
prev sibling parent "Anton Alexeev" <alexanto gmx.de> writes:
On Friday, 6 September 2013 at 22:31:52 UTC, Jonathan M Davis 
wrote:
 On Friday, September 06, 2013 23:31:57 Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC
 without curl the program will not work until you install the
 library. Is there a way to put the curl library in the 
 executable?
Statically link it. - Jonathan M Davis
Sorry for being noob but how I can do it?
Sep 09 2013
prev sibling next sibling parent reply "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Friday, 6 September 2013 at 21:31:59 UTC, Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC 
 without curl the program will not work until you install the 
 library. Is there a way to put the curl library in the 
 executable?
You just gave me an idea to compile in shared libraries and then to extract them on run. I'll let you know when I got some code. (Btw this is not a good idea but definitely will work for license reasons, although this could be a rather gray zone. Should be confirmed.).
Sep 07 2013
parent reply "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Saturday, 7 September 2013 at 09:05:39 UTC, Rikki Cattermole 
wrote:
 On Friday, 6 September 2013 at 21:31:59 UTC, Anton Alexeev 
 wrote:
 I've written a program which uses curl library. So on a PC 
 without curl the program will not work until you install the 
 library. Is there a way to put the curl library in the 
 executable?
You just gave me an idea to compile in shared libraries and then to extract them on run. I'll let you know when I got some code. (Btw this is not a good idea but definitely will work for license reasons, although this could be a rather gray zone. Should be confirmed.).
So I modified my Bin2D which allows compiling in resources[1]. Now it can produce an output file that when compiled in gives two new functions. These functions essentially extract the files for you. One of those is for temporary directory[2]. Little bit off topic but it can be utilised for packaging up shared libraries into your executable and then extracting on run. E.g. $ dub build $ cd bin $ ./Bin2D outputFile.d=outputModule lib1.so lib2.dll Just an example usage. Note not on dub repository. Just another option for ya. [1] https://github.com/rikkimax/Bin2D/blob/master/source/Bin2D.d [2] string[string] outputBin2D2FS()
Sep 07 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
On Saturday, 7 September 2013 at 10:13:39 UTC, Rikki Cattermole 
wrote:
 On Saturday, 7 September 2013 at 09:05:39 UTC, Rikki Cattermole 
 wrote:
 On Friday, 6 September 2013 at 21:31:59 UTC, Anton Alexeev 
 wrote:
 I've written a program which uses curl library. So on a PC 
 without curl the program will not work until you install the 
 library. Is there a way to put the curl library in the 
 executable?
You just gave me an idea to compile in shared libraries and then to extract them on run. I'll let you know when I got some code. (Btw this is not a good idea but definitely will work for license reasons, although this could be a rather gray zone. Should be confirmed.).
So I modified my Bin2D which allows compiling in resources[1]. Now it can produce an output file that when compiled in gives two new functions. These functions essentially extract the files for you. One of those is for temporary directory[2]. Little bit off topic but it can be utilised for packaging up shared libraries into your executable and then extracting on run. E.g. $ dub build $ cd bin $ ./Bin2D outputFile.d=outputModule lib1.so lib2.dll Just an example usage. Note not on dub repository. Just another option for ya. [1] https://github.com/rikkimax/Bin2D/blob/master/source/Bin2D.d [2] string[string] outputBin2D2FS()
Thank you for taking time and writing this tool but I don't really understand how to use it. Can you please explain it little bit more? So I have my main.d file with source code and I compile it with this command: "dmd -L-lphobos2 -L-lcurl main.d". How will I get all the libraries into one executable with Bin2D?
Sep 07 2013
parent "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Saturday, 7 September 2013 at 13:39:49 UTC, Anton Alexeev 
wrote:
 On Saturday, 7 September 2013 at 10:13:39 UTC, Rikki Cattermole 
 wrote:
 On Saturday, 7 September 2013 at 09:05:39 UTC, Rikki 
 Cattermole wrote:
 On Friday, 6 September 2013 at 21:31:59 UTC, Anton Alexeev 
 wrote:
 I've written a program which uses curl library. So on a PC 
 without curl the program will not work until you install the 
 library. Is there a way to put the curl library in the 
 executable?
You just gave me an idea to compile in shared libraries and then to extract them on run. I'll let you know when I got some code. (Btw this is not a good idea but definitely will work for license reasons, although this could be a rather gray zone. Should be confirmed.).
So I modified my Bin2D which allows compiling in resources[1]. Now it can produce an output file that when compiled in gives two new functions. These functions essentially extract the files for you. One of those is for temporary directory[2]. Little bit off topic but it can be utilised for packaging up shared libraries into your executable and then extracting on run. E.g. $ dub build $ cd bin $ ./Bin2D outputFile.d=outputModule lib1.so lib2.dll Just an example usage. Note not on dub repository. Just another option for ya. [1] https://github.com/rikkimax/Bin2D/blob/master/source/Bin2D.d [2] string[string] outputBin2D2FS()
Thank you for taking time and writing this tool but I don't really understand how to use it. Can you please explain it little bit more? So I have my main.d file with source code and I compile it with this command: "dmd -L-lphobos2 -L-lcurl main.d". How will I get all the libraries into one executable with Bin2D?
First I may have forgotten that phobos links with curl not loads at runtime. So if your wanting to use shared libraries like this over static still. You can basically compile normally. Then $ Bin2D output.d=output main curl.so Where main is the executable you built with dmd. You will need to add a main function to output.d e.g. import std.process; void main() { string[string] files = outputBin2D2FS(); execute(files["main"]); } Note that the usage of std.process is from memory. Although I would highly recommend using static instead if you can.
Sep 07 2013
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-06 23:31, Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC without curl
 the program will not work until you install the library. Is there a way
 to put the curl library in the executable?
On Linux, doesn't all distributions ship with libcurl by default? For Windows I found this: http://www.drdobbs.com/packing-dlls-in-your-exe/184416443 I have no idea if it works for D. -- /Jacob Carlborg
Sep 10 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
On Tuesday, 10 September 2013 at 07:02:17 UTC, Jacob Carlborg 
wrote:
 On 2013-09-06 23:31, Anton Alexeev wrote:
 I've written a program which uses curl library. So on a PC 
 without curl
 the program will not work until you install the library. Is 
 there a way
 to put the curl library in the executable?
On Linux, doesn't all distributions ship with libcurl by default? For Windows I found this:
Can be but not libphobos2
Sep 10 2013
parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-10 11:04, Anton Alexeev wrote:

 Can be but not libphobos2
Link statically with it, which is does by default. Just compile with: dmd -L-lcurl test.d -- /Jacob Carlborg
Sep 10 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
On Tuesday, 10 September 2013 at 11:06:04 UTC, Jacob Carlborg 
wrote:
 On 2013-09-10 11:04, Anton Alexeev wrote:

 Can be but not libphobos2
Link statically with it, which is does by default. Just compile with: dmd -L-lcurl test.d
The point is: http://pastebin.com/0VkYgFix
Sep 11 2013
parent reply Mike Parker <aldacron gmail.com> writes:
On 9/12/2013 6:20 AM, Anton Alexeev wrote:
 On Tuesday, 10 September 2013 at 11:06:04 UTC, Jacob Carlborg wrote:
 On 2013-09-10 11:04, Anton Alexeev wrote:

 Can be but not libphobos2
Link statically with it, which is does by default. Just compile with: dmd -L-lcurl test.d
The point is: http://pastebin.com/0VkYgFix
Apparently you need to install the libcurl dev package. The linker can't find libcurl.a.
Sep 11 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
On Thursday, 12 September 2013 at 01:16:28 UTC, Mike Parker wrote:
 On 9/12/2013 6:20 AM, Anton Alexeev wrote:
 On Tuesday, 10 September 2013 at 11:06:04 UTC, Jacob Carlborg 
 wrote:
 On 2013-09-10 11:04, Anton Alexeev wrote:

 Can be but not libphobos2
Link statically with it, which is does by default. Just compile with: dmd -L-lcurl test.d
The point is: http://pastebin.com/0VkYgFix
Apparently you need to install the libcurl dev package. The linker can't find libcurl.a.
I've installed libcurl4-openssl-dev 7.29.0-1ubuntu3.1 before I asked for help here. Else I can't even compile with that command: dmd -L-lphobos2 -L-lcurl test.d
Sep 12 2013
parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-12 12:14, Anton Alexeev wrote:

 I've installed libcurl4-openssl-dev 7.29.0-1ubuntu3.1 before I asked for
 help here. Else I can't even compile with that command: dmd -L-lphobos2
 -L-lcurl test.d
How does your dmd.conf file look like? -- /Jacob Carlborg
Sep 12 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
On Thursday, 12 September 2013 at 11:30:05 UTC, Jacob Carlborg 
wrote:
 On 2013-09-12 12:14, Anton Alexeev wrote:

 I've installed libcurl4-openssl-dev 7.29.0-1ubuntu3.1 before I 
 asked for
 help here. Else I can't even compile with that command: dmd 
 -L-lphobos2
 -L-lcurl test.d
How does your dmd.conf file look like?
; ; dmd.conf file for dmd ; ; dmd will look for dmd.conf in the following sequence of directories: ; - current working directory ; - directory specified by the HOME environment variable ; - directory dmd resides in ; - /etc directory ; ; Names enclosed by %% are searched for in the existing environment and inserted ; ; The special name % P% is replaced with the path to this file ; [Environment] DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib/i386-linux-gnu -L-L/usr/lib/x86_64-linux-gnu -L--no-warn-search-mismatch -L--export-dynamic
Sep 12 2013
parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-12 18:25, Anton Alexeev wrote:

 [Environment]

 DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import
 -L-L/usr/lib/i386-linux-gnu -L-L/usr/lib/x86_64-linux-gnu
 -L--no-warn-search-mismatch -L--export-dynamic
I don't see way explicitly linking with Phobos would make a difference, since the compiler will link with Phobos implicitly. That assumes you have libphobos2.a in /usr/lib/i386-linux-gnu or /usr/lib/x86_64-linux-gnu. -- /Jacob Carlborg
Sep 12 2013
parent reply "Anton Alexeev" <alexanto gmx.de> writes:
So, nobody can give an easy answer how to statically link the 
libraries with the executable and I have yo use Bin2D?
Sep 13 2013
next sibling parent "FreeSlave" <freeslave93 gmail.com> writes:
On Friday, 13 September 2013 at 19:54:41 UTC, Anton Alexeev wrote:
 So, nobody can give an easy answer how to statically link the 
 libraries with the executable and I have yo use Bin2D?
Did you try to use -static option of compiler? It forces to link application with static libraries instead of shared.
Sep 13 2013
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Friday, September 13, 2013 21:54:39 Anton Alexeev wrote:
 So, nobody can give an easy answer how to statically link the
 libraries with the executable and I have yo use Bin2D?
If you give the exact file name for the static library (e.g. /path/to/libcurl.a), then it should link against the static version of the library. Also, -L-static might help, as it tells the linker to only link static libraries. - Jonathan M Davis
Sep 13 2013