tags:

views:

657

answers:

3

Hello,

I'm normally a Java developer, but I'm writing a C++ library right now they will use LibCurl. And I'm very un-aware in the C++ world!

What I'm writing is infact a library for use by other developers (its a client code used to access our API).

Will end users be required to have libcurl installed, or can the developers somehow include this in the EXE or package it somehow?

Actually the same goes, I might use QT in the library, will they be required to have this installed? I'm guessing the way it works is that developers of course will need it, but once its compiled to binary its not required? Unlike java where you need the Jar files all along...

Cheers for any help, Alan

+1  A: 

Many libraries can be used either statically or dynamically linked. Curl is one of them (see e.g. this message, and I would say it's reasonable to do so. QT is rather huge, so you should dynamically link it if at all possible. However, even it can be statically linked.

The essential difference between static and dynamic linking is that static linking includes the library in the application's object code, while with dynamic linking the application accesses the library on-demand from the system it's installed on.

Matthew Flaschen
+1  A: 

If you link libcurl statically then the end-user does not require libcurl, as it will be linked into to the executable directly at compile time.

If you link libcurl dynamically, then the end-user does require libcurl to be installed on their system and available as a shared object library.

However, you're in a different spot. You're writing a library for use by other developers. Thus, your end-user is in fact not really an end-user. In such scenarios it is "better" to provide to link dynamically against libcurl.

If you linked statically then your library would encapsulate in its code a copy of the libcurl library. Now imagine a developer using your library is also using 10 other libraries, all statically linked against libcurl. That developer is basically going to be including 10 copies of libcurl in his/her end product. This is not very efficient and hence dynamic linking against dependencies is preferred when developing a library.

However...

If a developer is using 10 different libraries which require libcurl but some of those libraries require a specific older/newer version than others then static linking will be useful.

Hope that helps...

However if you dynamically link you have to make sure your code works with different versions of libCurl. Otherwise the user has a problem if another lib needs a specific version
Martin Beckett
A: 

I wrote a closed-source application in C++ that linked to libcurl in its earlier versions.

This turned out to be a mistake because every Linux version has a different libcurl. It was much less cross-version compatible than glibc and libstdc++. I did not want to ship the libcurl library with the application.

I had simple needs. So I rewrote the application to call out to curl using system() instead. This worked on every version of Linux.

Zan Lynx