open cv and c++ compile release without need library for run - c++

first i have simple code with c++ and opencv
its no matter what is the code
now in windows i used visual studio and i add the open cv library to visual stuio and compile it and its work but when i send it to another pc its need open cv library its hard to send all library so i find the program need some files like
opencv_highgui2410.dll
..... .dll
opencv_objdetect2410.dll
that's make my program run without the library
now i turned to ubuntu linux after i compile with codeblocks
this photo will show you how i linker the library
and
and i build the program and run it its work now when i sent the program to another pc its give an error some files not found like
error while loading shared libraries: libopencv_core.so.2.4
i copy this file libopencv_core.so.2.4 and add it beside the program still same error seems not like windows
any solution made me compile opencv program and run program without need full library just some of its file
or any idea to add files (libs) that's project needed to run beside program just like windows

I think this should help you.
But from the comments, i fear you have very little linux experience, I hope this will help, anyway:
https://s1meonov.wordpress.com/2010/12/27/opencv-static-linking-gnulinux-gcc/
(first, be sure to understand what shared and static libraries, how they work and how they impact on software licenses, and also be sure to understand how to install programs in linux. For installing have a look at this link: http://www.makeuseof.com/tag/beginners-guide-installing-software-ubuntu-apt/)

Related

Running c++ in Windows as .exe

I wrote a c++ program and converted it to a .exe file with the hopes to let it run on windows without needing to install a compiler. I ran well on my main computer (which has a compiler so it ran as expected) but did not run on another device. The error message shown was "libgcc_s_dw2-1.dll was not found"
How can I run a c++ program (or .exe file) from a flashdrive or other medium on any windows machine without extra installation.
C++ programs require additional c++ standard and runtime libraries to run. Most linker links to these libraries dynamically. That is some dll are required for running the program. You can run the program from a portable flash drive by copying those dll to the same folder as the application.
Alternatively, some linkers also have option to statically link, that is incorporate the code in dll ( kind of ) to your binary exe.
So you can either find out what all dll is required and copy them to your local folder ( maybe use something like dependancy walker or this newer one, i haven't actually used the newer alternative). Or use static linking like shown in this answer.

When u download additional libraries & add their features to ur c++ program, would u be able to run ur software on another PC (w/o the library)?

Quick question here, okay say that I have downloaded additional libraries and added them to my version of visual studios and have their #include and commands in my project source code.
If I was to take the .cpp file and bring it to my school computer which also has visual studios and doesn't have these additional libraries, it would have a bunch of missing errors and can't compile.
but..
What if I publish my project and I have it in a .exe file and I was to try and run it on another computer that doesn't have these libraries? Would the executable file run okay?
When you
#include <stuff>
stuff is used during compilation time. However, the libraries it may refer to (e.g. the include gives the definition of many functions from an external library), can be
static or
dynamic
static libraries are linked statically when the program is built, and are part of the executable. dynamic libraries like DLL are linked during the execution of the program .exe. Thus they (DLL) may not be present on another computer when you run the same exe on it.
It depends on the libraries you are using, but sometimes a package is available for download and installation on the other computer, so that they become available. Sometimes you have to copy a bunch of DLLs along with your exe to the other computer. For instance, some advice from Microsoft in this regard.

how to deploy netbeans Qt project to stand-alone executable

I'm working on a netbeans c++ Qt project in Ubuntu. I would like to deploy this program to a stand-alone executable that can be run from Windows machines.
I can't find anything online on how to do this. Is it possible?
You will have to compile the source on a Windows machine or set up a cross compiling toolchain.
I highly suggest the first option as the second isn't any fun.
Then you will either have to statically link the proper Qt dlls and compile them into the final executable or simply copy the required dlls into the path of the executable. What's the easiest way to figure out the required dlls? Try to run the program, it will fail and tell you which libraries you need to link to it. (Or run an ldd on ubuntu and keep track of the list)
(Note:I think statically linking the libraries may have licensing implications. It has been a while since I looked at the Qt licenses.)

compiling C++ console application in linux

I have generated a c++ shared library and integrated it with a C++ console application which is called from php. I was trying this on my windows os and it works perfect. Now I have to transfer it into a linux web server. I know I have to compile the c++ console application in linux again to run it and may be generate the c++ shared library also. I am new to the linux os, how can I compile the c++ console application in linux server assigning all the additional library,include files,header files generated from the c++ shared library like we do in Visual Studio? Any link regarding this will be highly appreciated. As the shared library is from matlab I should also assign the matlab include files and libraries ewhile compiling the c++ console application.
I think you will have to get a Linux port of your matlab made library, which might involve getting matlab installed and working on Linux (and a little testing & debugging).
When your lib is ready, port your console application also (debugging et. all), open a terminal then:-
gcc -Wall console_app.c /path/to/your/libFromMatlab.a -o console_app
If your console app's source spans multiple files, you may want to consider using an IDE like code::blocks or use a makefile to simplfy your work.
Add your "libFromMatlab.so" (notice the .so vs the .a above) location to the library path (or copy it to where the others reside), then make sure your console_app has executable flag set.
NB:Developing on any platform other than the target platform without cross-compiling is equivalent to playing Russian roulette...only less lethal.
-----EDIT------I also came across this article and thought section 4 may be of some value.

How to create a Standalone Executable program in C++?

I want to create a program that could work on any computer without the source code, How is that possible? and does it make any difference if I used OpenGL in the Program?
You cannot code a program in C++ that would work on any computer without giving your source code to be compiled.
For example, you could perhaps code in C++ a program, and compile it and build an executable which works on Windows x86-64, but that executable won't work on Linux (or MacOSX), and it won't work on ARM (e.g. Android phones) unless you consider using emulators
If you are developing your code with Visual C++ you may need to consider two options:
Make sure you link all libraries statically.
Install on the target computers along with your program Microsoft Visual C++ Redistributable Package corresponding to the Visual C++ version you use like the one at http://www.microsoft.com/download/en/details.aspx?id=5555. Some installer generating software will make it for you automatically.
Normally you would link your object file with some sort of a platform dependent loader. This loader loads your object and does all the stuff to start it from memory. Normally you can tell your compiler to link your object file and compile a blob. OpenGL is a powerful API and is usually distributed as a.dynamic linked library and is linked at runtime to your program. If I remember you just have to make sure the dll is where you want it and load the dll in your program from start.
Your C++ program is compiled and linked into an executable before it is run. You should be able to find that executable in a Debug or Release subfolder of the folder containing your project.
OpenGL, if you're not using GLUT or similar libraries, should just come with Windows and pose no additional problems. If you do use GLUT, it's enough to bundle the .dll file with your application.
In any case, the source code won't be necessary.
I want to create a program that could work on any computer without the source code, How is that possible? and does it make any difference if I used OpenGL in the Program?
By compiling and linking it into an executable. As long as you're not using some interpreted language (like Python, Ruby or such) you're presented with an executable inevitably. The biggest problem you may/will run into is dependencies on libraries. However those are linked into a binary as well. So what you're going to ship will be just a .exe; and some .dll maybe. Usually you'd wrap this in a installer package for deployment to the end user. Installers are created with something like the "NullSoft Installer System" (NSIS).
OpenGL itself is just a API, provided by a system library. So you don't ship OpenGL with your program, but expect the user to have it installed on the system (which will be the case if he installed the graphics drivers).