Author Topic: Missing DLLs when running a program  (Read 35920 times)

Offline Léa Massiot

  • Multiple posting newcomer
  • *
  • Posts: 39
Missing DLLs when running a program
« on: February 22, 2012, 11:36:01 am »
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"

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;
}

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.

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
=====================================================================

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Missing DLLs when running a program
« Reply #1 on: February 22, 2012, 12:04:23 pm »
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?
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Léa Massiot

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Missing DLLs when running a program
« Reply #2 on: February 22, 2012, 12:49:33 pm »
Thank you for your answer.
Quote from: MortenMacFly
link statically to embed what's needed
Can you tell me how to do this?
Thank you.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Missing DLLs when running a program
« Reply #3 on: February 22, 2012, 01:59:29 pm »
Quote from: MortenMacFly
link statically to embed what's needed
Can you tell me how to do this?
Thank you.
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Léa Massiot

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Missing DLLs when running a program
« Reply #4 on: February 22, 2012, 03:33:44 pm »
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"

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

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.