Author Topic: Building a standalone exe  (Read 40414 times)

Offline robl

  • Single posting newcomer
  • *
  • Posts: 5
Building a standalone exe
« on: January 29, 2011, 01:02:54 pm »
Hi

I'm new to codeblocks, and trying to build a standalone .exe - It's a wxwidgets project.

I followed the instruction here (http://wiki.codeblocks.org/index.php?title=WxWindowsQuickRef) to set up the wxwidgets projects - (I used the wxPack installation option which includes the static libraries and made sure I left the "Use __WXDEBUG__ and Debug wxWidgets lib" UNchecked when creating the project)

It all builds fine in codeblocks - i.e. build + run works fine but the executable in the bin/release folder doesn't run - it come up with an error: "The program can't start because wxmsw28u_gcc.dll is missing from your computer"

1) why is it needing a dll? I thought I was building a "realease" not a "dll release" - i.e. all dll should be compiled into the exe.  I can't see any obvious options for making sure it's a full release.  Where abouts are they?  (in VC++ express it's under the compilation options and change it from "multithreaded dll" to "multithreaded" - I can't see the equivalent in codeblocks)

2) the file does actually exist here: "c:\wxWidgets2.8\lib\gcc_dll\wxmsw28u_gcc.dll", I've set up the global "$(#wx)" variable to point to "c:\wxWidgets2.8" and directories "c:\Program Files\CodeBlocks\MinGW\bin\" and "c:\wxWidgets2.8" are in my "path" environment variables

Can anyone help me out please - I'm guessing it's very obvious but it's defeating me at the moment!

Cheers

Rob

p.s. Have just added c:\wxWidgets2.8\lib\gcc_dll\ to the path env. variable so now runs on this pc but will not run on other pc's not containing these libraries - how can I link the referenced libraries into the executable? - i.e. a NON-dll release
« Last Edit: January 29, 2011, 02:11:41 pm by robl »

vectis99

  • Guest
Re: Building a standalone exe
« Reply #1 on: January 29, 2011, 02:26:31 pm »
I had this exact problem recently. I got around it by starting a second project with the same source files but untick the "Use wxWidgets dlls", use the monolithic library. If you look at the size of of your .exe it'll be tiny (55kb in my case), but the .exe with the monolithic library build will be much bigger (2.5mb ) and runs independantly of C::B.

Incidently, I found Dependancy Walker very useful in probing this bug/feature.

I hope you fiind this useful.

Mark Scott Cousins

Offline gd_on

  • Lives here!
  • ****
  • Posts: 797
Re: Building a standalone exe
« Reply #2 on: January 29, 2011, 02:27:42 pm »
Hi,
you have certainly built a wxwidget dll, so a dynamic library. If you link your project with this library, the linker resolves the links it needs with that library. So this library is also needed at run time.
If you want a completely independent executable, you need to link with a wxwidgets static library. You can generate one by using SHARED=0 on your make -f makefile.gcc ... line when you build wxwidgets. Your new static libraries will be in something like c:\wxWidgets2.8\lib\gcc_lib.

gd_on
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline robl

  • Single posting newcomer
  • *
  • Posts: 5
Re: Building a standalone exe
« Reply #3 on: January 29, 2011, 02:36:58 pm »
Cheers for that Mark, unfortunately I now get:

C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x562): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2016): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2162): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x29cf): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2a5f): undefined reference to `_Unwind_Resume'
 

and a lot more  of them! Any ideas? - Maybe I need to build wxwidgets manually rather than from wxPack?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7590
    • My Best Post
Re: Building a standalone exe
« Reply #4 on: January 29, 2011, 04:09:43 pm »
Cheers for that Mark, unfortunately I now get:

C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x562): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2016): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2162): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x29cf): undefined reference to `_Unwind_Resume'
C:\wxWidgets2.8\lib\gcc_lib/libwxmsw28u.a(monolib_string.o):string.cpp:(.text+0x2a5f): undefined reference to `_Unwind_Resume'
 

and a lot more  of them! Any ideas? - Maybe I need to build wxwidgets manually rather than from wxPack?


wxWidgets must be built and used with Compilers Compatible with each other!
IIRC, The above message means you are mixing SJLJ and DW2 versions of MinGW GCC compilers.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline robl

  • Single posting newcomer
  • *
  • Posts: 5
Re: Building a standalone exe
« Reply #5 on: January 29, 2011, 06:37:33 pm »
Thanks Tim, I didn't actually build wxWidgets myself - I used wxPack which comes with pre-compiled libraries.  I actually followed the advice that is on the CodeBlocks wiki - (link on my first post).  Do you think it's worth mentioning on the wiki that the version of the compiler that ships with Code::Blocks doesn't work with the libraries in wxPack? Or have I got the wrong end of the stick? I couldn't see an option to change the version in CodeBlocks - Have to admit this is all new to me i.e. I just thought the MinGW GCC compiler would work.  Every day is a school day!

Rob

oh...just had a touch of the RTFM's - bottom line of wiki FAQs =

"I get errors like "undefined reference to _Unwind_*"

wxWidgets was built with a different version of GCC than the one you're currently using. You need to rebuild wxWidgets with the same version of GCC that you use to compile your program.

I guess codeblocks is more up to date with its version of minGW GCC compiler than the one used to build in wxPack
« Last Edit: January 29, 2011, 06:56:08 pm by robl »

Offline robl

  • Single posting newcomer
  • *
  • Posts: 5
Re: Building a standalone exe
« Reply #6 on: January 29, 2011, 11:37:33 pm »
.....and so the pain continues...

All is good on my coding machine - I compiled wxWidgets with the static, monolithic options. And the executable runs on this machine.  However trying to run it on other pc's (i.e. with no code::blocks, gcc, wx etc) it bombs out with "application failed to start because mingwm10.dll doesn't exist - i.e. the mingw gcc dll has failed to be linked into the .exe.  It must be possible to produce an .exe for distribution???? But how? Sorry for my ignorance! and cheers for any help

Rob

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7590
    • My Best Post
Re: Building a standalone exe
« Reply #7 on: January 30, 2011, 01:58:21 am »
Learn how to use the newest TDM MinGW GCC; I believe there is a option to do a static link of the C Run-time.
Note, I am not sure of the above. Read it in a post on this site or maybe TDM site, cboard, or another site.
You really need to post questions about the compilers on a better site than this site; which is to support Code::Blocks not Compilers.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Building a standalone exe
« Reply #8 on: January 30, 2011, 03:47:15 am »
Also learn how to use google or any other search engine ----> http://lmgtfy.com/?q=static+link+mingwm10.dll  :P
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline robl

  • Single posting newcomer
  • *
  • Posts: 5
Re: Building a standalone exe
« Reply #9 on: January 30, 2011, 09:14:53 am »
Fair enough! 

Offline easyw

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Building a standalone exe
« Reply #10 on: July 15, 2011, 12:34:17 pm »
Hi there
I'm trying to compile a standalone exe ...
I've installed:
- CB 10.05 + Mingw
- wxPack_v2.8.9.02

and I tried to start a prj from template, using wxSmith, but the best I can obtain requires at least mingwm10.dll ...

could someone help me, may be sending a sample cb porject?

thanx :)

Offline easyw

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Building a standalone exe
« Reply #11 on: July 18, 2011, 03:32:59 pm »
I found a way for windows ... I post it here ...

1] download and install CB & MingW [codeblocks-10.05mingw-setup.exe]
    NB to easily compile WxWidgets I installed CB in "C:\CodeBlocks" instead of c:\Program Files
2] download and install wxMSW [wxMSW-2.8.12-Setup.exe] from http://www.wxwidgets.org/downloads/
    NB to easily compile WxWidgets I installed wxMSW in C:\wxWidgets-2.8.12
3] move to "C:\wxWidgets-2.8.12\build\msw" and create a batch file as following (monolithic lib no dll for release)
    path C:\CodeBlocks\MinGW\bin
    C:\CodeBlocks\MinGW\bin\mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 RUNTIME_LIBS=static SHARED=0
4] launch the batch file and wait until the libs are built [C:\wxWidgets-2.8.12\lib\gcc_lib]
    (if you need also debug build just rebuild with "BUILD=debug" option)
5] then launch CB and 'create a new project' wizard with wxWidgets
    - select wxWidgets 2.8.x
    - select title and dir for the project
    - select gui wxSmith and Frame based
    - select wxWidgets' location  "C:\wxWidgets-2.8.12"
    - select Release configuration (or Debug if you have built with Debug option)
    - select only "wxWidgets is built as monolithic library"
6] in Project
         Build option
            Compiler Settings
              Other Options
    delete "-mthreads" option
7] in Project
         Build option
            Linker Settings
              Other linker Options
    delete "-mthreads" option
    add "-static-libgcc" option

that's it!!! :)
Hoping this could help... :)
PS thanx to http://dev.arqendra.net/#cbnb where I got some good advice...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5914
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Building a standalone exe
« Reply #12 on: July 19, 2011, 03:58:20 am »
very nice tutorials. hope it can put in wiki. but I guess the wiki has already some similar materials. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Diazepam

  • Single posting newcomer
  • *
  • Posts: 6
Re: Building a standalone exe
« Reply #13 on: December 23, 2012, 01:11:09 pm »
I used
- C:\wxWidgets-2.9.4\build\msw
- echo %PATH% (to see if i still have C:\Program Files (x86)\CodeBlocks\MinGW\bin), and I do.
- mingw32-make.exe -f makefile.gcc clean
- mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 RUNTIME_LIBS=static SHARED=0

I opened Code::Blocks and I tryed to make a new project.
However, it didn't allow me to make a new project only with monolithic. It obligated me to use "Use WX dll" and "use unicode" too. This is my old build. I want to change it to what you instructed because I need a stand-alone exe, and the old build has SHARED=1 and doesn't have static runtime_libs.

What am I doing wrong?

Offline Diazepam

  • Single posting newcomer
  • *
  • Posts: 6
Re: Building a standalone exe
« Reply #14 on: December 26, 2012, 01:48:48 pm »
Should I just reinstall Windows ?