User forums > Using Code::Blocks

Missing DLLs when running a program

(1/1)

Léa Massiot:
Hello,

Thank you for reading my post.
My problem is about missing DLLs when running a program generated using "Code::Blocks".

I have created a new "Console application" project with "Code::Blocks":
--- Code: ---"File" -> "New" -> "Project..."
"Console application"
"C++"
"Project title: foo"
"Compiler: GNU GCC Compiler"
--- End code ---

I opened "main.cpp" and edited the following code:
--- Code: ---#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  cout << "Entering the program." << endl;

  ofstream myfile;
  myfile.open("C:\somewhere\in\the\filesystem\foo.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();

  cout << "File opened, written and closed." << endl;
  return 0;
}
--- End code ---

1) If I build the program: it builds properly.

2) If I go to "C:\where\codeblocks\projects\reside\foo\bin\Debug\" and double click the program "foo.exe": it executes properly.

3) Now if I:
- copy "foo.exe" somewhere else in the filesystem (in "C:\somewhere\in\the\filesystem_2\"),
- go to this directory,
- and run the program,
I get the following message:

--- Code: ---The application has failed to start because libgcc_s_dw2-1.dll wasn't found. Re-installing the application may fix the problem.
--- End code ---

4) If I add the path "C:\MinGW\bin\" - where "libgcc_s_dw2-1.dll" (and also "libstdc++-6.dll") can be found - to the "Path" environment variable and run the program again: it works properly.

So, my question is the following: is it possible to create a "Code::Blocks" project / configure a "Code::Blocks" project / build a "Code::Project" so that wherever we put the program "foo.exe" in the filesystem (including on another computer), it executes properly with no missing DLLs messages?

Thank you for helping and best regards,
--
Léa

--- Code: ---=====================================================================
OS                      = WinXP
Code::Blocks version    = svn build rev 7550 - SDK version = 1.11.16
C++ compiler            = mingw32-g++.exe
Linker for dynamic libs = mingw32-g++.exe
Linker for static libs  = ar.exe
=====================================================================
--- End code ---

MortenMacFly:

--- Quote from: Léa Massiot on February 22, 2012, 11:36:01 am ---So, my question is the following: is it possible to create a "Code::Blocks" project / configure a "Code::Blocks" project / build a "Code::Project" so that wherever we put the program "foo.exe" in the filesystem (including on another computer), it executes properly with no missing DLLs messages?

--- End quote ---
That is not a Code::Blocks, but a platform issue. Several solution candidate exist:
- put that DLL into a system folder
- add the path to the DLL to you system PATH
- link statically to embed what's needed.

Léa Massiot:
Thank you for your answer.

--- Quote from: MortenMacFly ---link statically to embed what's needed
--- End quote ---
Can you tell me how to do this?
Thank you.

MortenMacFly:

--- Quote from: Léa Massiot on February 22, 2012, 12:49:33 pm ---
--- Quote from: MortenMacFly ---link statically to embed what's needed
--- End quote ---
Can you tell me how to do this?
Thank you.

--- End quote ---
It depends on your compiler, the compiler version and the libs you are using. Inspect the compiler manual and refer to the documentation of the SDK/libs you are using. I cannot help much.

Léa Massiot:
Ok. Thank you.

I managed to make it work thanks to your help and this document:
http://softwaresalariman.blogspot.com/2011/03/configure-netbeans-to-statically-link.html

In "Code::Blocks", I went to:
--- Code: ---"Settings" -> "Compiler and debugger..."
"Global compiler settings"
"Linker settings"
--- End code ---

I added the following options to "Other linker options":
--- Code: ----static-libgcc -static-libstdc++
--- End code ---

After doing this, I was able to build and execute the program properly without having to copy the DLLs to be in the same directory as the executable.

Thanks and best regards.

Navigation

[0] Message Index

Go to full version