standalone independant executable using code::blocks with Windows8

asked 2014-08-08 03:48:48 -0500

lounice gravatar image

Hello,

I have developed a c++ console application project with code::blocks in windows using OpenCV 2.4.9. I have built OpenCV using CMAKE (with the BUILD_SHARED_LIBS flag OFF). Regarding Code::blocks, I have downloaded and installed the IDE alone and then I have installed the MingW/Msys compiler.

The application runs normally in Debug and in Release modes. However, when I run the released "exe" it generates an error saying that a DLL is missing. Based on this, I came to the conclusion that the compiler was performing dynamic linking. I have looked everywhere in the code::blocks' GUI to see if there was an option that enables static linking but I did not succeed. I have also looked for help online (googled it) for 2 days but the solutions I have found did not work.

Please, does anyone know how to generate a standalone independant executable (that will work in another PC. i.e: static linking) of a project that uses OpenCV in code::blocks ?

Thank you for your help !

L.

edit retag flag offensive close merge delete

Comments

1

rerunning cmake with BUILD_SHARED_LIBS=OFF will generate static libs.

but mind, that now you will have to care for all the dependancies yourself (dshow, windows libs, 3rd party, etc) and that gcc is very picky about the correct order of libs in the makefile/cmdline.

berak gravatar imageberak ( 2014-08-08 03:59:24 -0500 )edit

Like berak said, post the missing lib here, I have quite some experience in static linking in windows so might be able to give you the static lib you will need to add to your program. Static linking is a painful bitch to handle, but the result can be quite satisfactory.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-08 04:03:58 -0500 )edit

Thank you for your answers,

the missing dll is : libopencv_core249.dll. Regarding CMAKE, First time I have built OpenCV I did it with the default settings of CMAKE and for which the BUILD_SHARED_LIBS flag was ON then when the issue rised I have rebuilt it with the BUILD_SHARED_LIBS flag OFF. I have noticed that this did not change anything in the contents of the "lib" folder (which contains 87 ".dll.a" and ".a" files).

I insist on the fact that I want to generate an independant executable (I am learning how to generate a standalone application that can be used by a third party user who does not have any of OpenCV, code::blocks or other programing tools).

Thank you.

lounice gravatar imagelounice ( 2014-08-08 04:36:42 -0500 )edit

Hmmm are you sure you are configuring your codeblock project correctly? Those DLLs will not dissapear afaik, rather the internal built will be so that they can be copied as static lib.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-08 04:44:47 -0500 )edit

Did you add your libs to the linker options in your build settings?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-08 04:46:56 -0500 )edit

I remember that sometime ago I managed to generate an independant executable that uses OpenCV but it was with Visual C++. You are right when you ask the question on whether the codeblocks project is correctly configured or not. But as I said in my first post, I have looked into code::blocks's GUI for all possible configuration options and it seems that there is no further settings related to my issue (AFAIK, no option to select static or dynamic linking). It seems that it depends on the nature of the libs (dll's or static libs) added to the "link libraries" list of the "linker settings" in the project build options of code::blocks but I am not sure yet.

lounice gravatar imagelounice ( 2014-08-08 04:59:13 -0500 )edit

@steven: Yes I did add the libs to the linker options otherwise it would never compile. As I said, the project compiles just fine...

lounice gravatar imagelounice ( 2014-08-08 05:01:29 -0500 )edit

Yet the dll's are not found ... which is weird since it should compile statically. I know Visual Studio has a built option that has to be set from /md to /mt I think ... should look where that goes for codeblocks.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-08 05:40:29 -0500 )edit

@steven : I am working on it...

lounice gravatar imagelounice ( 2014-08-08 05:42:02 -0500 )edit

try adding -static and -staticgcc as options to the extra build options.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-08 05:48:12 -0500 )edit