Hey everyone. I tried googling it, but with no luck. I have written this small program with C++, and I am trying to make it standalone.
I compile with
g++ -std=c++0x -lbcrypt -lboost_regex -o main main.o aes256.o `pkg-config --cflags --libs gtk+-2.0`
Bcrypt is a library I found on the internet.
But when I try to run the compiled program on another computer, it doesn't work, says libraries missing. So how can I make it standalone?
Well on linux you just download the repo it gets put in a single global folder which is bin (I think) and everything works.
If your project is to be distributed by source code, it would be easier to just tell people to download the dependencies, otherwise you still need to download the repo's of the libraries so that you can static compile them. I think the repo variant should be called "dev" sor something like that, and for all the missing libraries you can easily google what repo you need to download by looking up the command.
Also consider using the linux board next time you have problems related to an OS.
On dynamic linking the linker adds to the binary instructions that make the dynamic linker load the required shared objects (libraries, .so) when loading the program.
On static linking the linker copies object code from static libraries (.a) into the (monolithic) binary. Static library is essentially a collection concatenated object files.
-lnamespec--library=namespec
Add the archive or object file specified by namespec to the list of files to link. ... it will search the library path for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a.
-static
Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. You may use this option multiple times on the command line: it affects library searching for -l options which follow it.
Sounds like:
look for .so
IF found AND static not set
THEN use the .so
ELSE look for .a and use it, if found
Replacing libfoo.so with libfoo.a is not trivial, because the libfoo.so is likely to link/depend on other shared libraries, which also have to be replace with static versions, and those shared libraries might depend on ...
I solved my problem by reducing the number of libraries my code uses, keeping the libbcrypt.so in the same folder as the compiled application and using this command to compile: