Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to package C++ with dlls and libraries

Tags:

c++

release

I'm wondering how to "package" a C++ project for release. It uses various libraries, and I don't want a user to have to go through the same setup I did, with putting the right files in the right place and such. I had difficulty researching this, because I'm not sure the technical term for this issue. If I'm using command line compiling on Linux, is there an easy way to do this?

like image 293
Cannoliopsida Avatar asked Jun 08 '12 15:06

Cannoliopsida


People also ask

What is DLL in C language?

In Windows, a dynamic-link library (DLL) is a kind of executable file that acts as a shared library of functions and resources. Dynamic linking is an operating system capability. It enables an executable to call functions or use resources stored in a separate file.

Does C have DLL?

Yes, you can load a shared object (or dynamically linked library) using C code no matter what language was used to create it, as long as all run-time requirements are met. is DLL language dependent? Shared object itself is a binary in some format (i.e. on Linux it is ELF).


1 Answers

Your approach to this will differ on Windows and Linux because each OS handles this a different way. I'm more familiar with Linux so I'll restrict my answer to just the Linux side of things.

When you link your executable with a library using -l flag the linker defaults to looking in the normal system library directories so there are four approaches here.

  1. Require the user to properly install the libraries themselves. However, it sounds like you don't want to do that.

  2. Have the user add the library location to LD_LIBRARY_PATH variable.

  3. Your third option is force the linker to look in a certain path for the libraries using the -rpath flag. For example, to have the application look in its working directory for a shared library you can compile with: g++ -rpath ./ -l SomeLib -o MyApp myapp.cpp

  4. One other option is to static link your code with their library that way you only have to distribute one executable. If a static library exists you can use g++ -static -l SomeLib -o MyApp myapp.cpp to tell gcc to link statically.

like image 166
Eric Y Avatar answered Oct 07 '22 23:10

Eric Y