Page 1 of 2

Where to put the -static switch?

Posted: Wed Mar 28, 2012 12:05 pm
by DarkBug
I don't know where to put the -static switch and how to insert the static libraries.

Used toolchain:
IDE: CodeLite 3.5.5377
Compiler: Unofficial TDM MinGW_v4.4.1
wxWidgets: wxPack v2.8.12.01

I create a new wxWidgets HelloWorld Projekt and compile it with -mwindows;$(shell wx-config --debug=no --libs --unicode=yes) and it works. After that i want that program to run on a non-developer machine, but i get the error message: wxmsw28u_gcc.dll not found. Then i compile the program with -mwindows;$(shell wx-config --debug=no --libs --unicode=yes --static) and only get:

Code: Select all

----------Build Started-------- 
C:\Windows\system32\cmd.exe /c ""mingw32-make.exe"  -j 4 -f "Test_wsp.mk"" 
----------Building project:[ Test - Release ]---------- 
mingw32-make.exe[1]: Entering directory `C:/Users/DarkBug/Desktop/Test' 
g++  -c  "C:/Users/DarkBug/Desktop/Test/main.cpp" -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:\wxWidgets2.8\lib\gcc_dll\mswu -IC:\wxWidgets2.8\include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0  -Wno-attributes   -o ./Release/main.o -I. 
g++ -o ./Release/Test @"C:\Users\DarkBug\Desktop\Test\Test.txt" -L.   -mwindows -s  -mthreads -LC:\wxWidgets2.8\lib\gcc_lib -lwxmsw28u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwxregexu -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 
./Release/main.o:main.cpp:(.text+0x4): undefined reference to `_imp___ZN12wxAppConsole14ms_appInstanceE' 
./Release/main.o:main.cpp:(.text+0x10): undefined reference to `_imp___ZN12wxAppConsole12ms_appInitFnE' 
./Release/main.o:main.cpp:(.text+0x3f): undefined reference to `_imp___Z7wxEntryP11HINSTANCE__S0_Pci' 
./Release/main.o:main.cpp:(.text+0x60): undefined reference to `_imp___ZN12wxAppConsole17CheckBuildOptionsEPKcS1_' 
./Release/main.o:main.cpp:(.text+0x77): undefined reference to `_imp___ZN5wxAppC2Ev' 
./Release/main.o:main.cpp:(.text+0xad): undefined reference to `_imp___ZN12wxStringBase4nposE' 
./Release/main.o:main.cpp:(.text+0xce): undefined reference to `_imp___ZN12wxStringBase8InitWithEPKwjj' 
./Release/main.o:main.cpp:(.text+0xf2): undefined reference to `_imp__wxFrameNameStr' 
./Release/main.o:main.cpp:(.text+0x112): undefined reference to `_imp__wxDefaultPosition' 
./Release/main.o:main.cpp:(.text+0x11e): undefined reference to `_imp___ZN11wxFrameBaseC2Ev' 
./Release/main.o:main.cpp:(.text+0x123): undefined reference to `_imp___ZTV7wxFrame' 
./Release/main.o:main.cpp:(.text+0x131): undefined reference to `_imp___ZN7wxFrame4InitEv' 
./Release/main.o:main.cpp:(.text+0x16e): undefined reference to `_imp___ZN7wxFrame6CreateEP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_' 
./Release/main.o:main.cpp:(.text+0x1e1): undefined reference to `_imp__wxButtonNameStr' 
./Release/main.o:main.cpp:(.text+0x205): undefined reference to `_imp___ZN12wxWindowBaseC2Ev' 
./Release/main.o:main.cpp:(.text+0x20a): undefined reference to `_imp___ZTV8wxWindow' 
./Release/main.o:main.cpp:(.text+0x240): undefined reference to `_imp___ZN8wxWindow4InitEv' 
./Release/main.o:main.cpp:(.text+0x245): undefined reference to `_imp___ZTV9wxControl' 
./Release/main.o:main.cpp:(.text+0x259): undefined reference to `_imp___ZN15wxBaseArrayLongC2Ev' 
./Release/main.o:main.cpp:(.text+0x25e): undefined reference to `_imp___ZTV12wxButtonBase' 
./Release/main.o:main.cpp:(.text+0x269): undefined reference to `_imp___ZTV8wxButton' 
./Release/main.o:main.cpp:(.text+0x277): undefined reference to `_imp__wxDefaultValidator' 
./Release/main.o:main.cpp:(.text+0x288): undefined reference to `_imp__wxDefaultSize' 
./Release/main.o:main.cpp:(.text+0x2b2): undefined reference to `_imp___ZN8wxButton6CreateEP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelRK11wxValidatorS4_' 
./Release/main.o:main.cpp:(.text+0x2ef): undefined reference to `_imp__wxEVT_COMMAND_BUTTON_CLICKED' 
./Release/main.o:main.cpp:(.text+0x32e): undefined reference to `_imp___ZN12wxEvtHandler7ConnectEiiiM8wxObjectFvR7wxEventEPS0_PS_' 
./Release/main.o:main.cpp:(.text+0x3b6): undefined reference to `_imp___ZN9wxControlD2Ev' 
./Release/main.o:main.cpp:(.text+0x3cb): undefined reference to `_imp___ZN13wxControlBaseD2Ev' 
./Release/main.o:main.cpp:(.text+0x3d8): undefined reference to `_imp___ZN12wxWindowBaseD2Ev' 
./Release/main.o:main.cpp:(.text+0x3e9): undefined reference to `_imp___ZN11wxFrameBaseD2Ev' 
./Release/main.o:main.cpp:(.text$_ZNK12wxWindowBase7GetNameEv[wxWindowBase::GetName() const]+0x2a): undefined reference to `_imp__wxEmptyString' 
./Release/main.o:main.cpp:(.text$_ZN9wxMiniAppD1Ev[wxMiniApp::~wxMiniApp()]+0x10): undefined reference to `_imp___ZN5wxAppD2Ev' 
./Release/main.o:main.cpp:(.text$_ZN9wxMiniAppD0Ev[wxMiniApp::~wxMiniApp()]+0x15): undefined reference to `_imp___ZN5wxAppD2Ev' 
./Release/main.o:main.cpp:(.text$_ZN9wxControl7CommandER14wxCommandEvent[wxControl::Command(wxCommandEvent&)]+0x7): undefined reference to `_imp___ZN9wxControl14ProcessCommandER14wxCommandEvent' 
./Release/main.o:main.cpp:(.text$_ZN12wxWindowBase18SetInitialBestSizeERK6wxSize[wxWindowBase::SetInitialBestSize(wxSize const&)]+0x7): undefined reference to `_imp___ZN12wxWindowBase14SetInitialSizeERK6wxSize' 
./Release/main.o:main.cpp:(.text$_ZNK9wxControl20GetDefaultAttributesEv[wxControl::GetDefaultAttributes() const]+0x1c): undefined reference to `_imp___ZN9wxControl25GetClassDefaultAttributesE15wxWindowVariant' 
./Release/main.o:main.cpp:(.text$_ZNK12wxWindowBase10HasCaptureEv[wxWindowBase::HasCapture() const]+0x8): undefined reference to `_imp___ZN12wxWindowBase10GetCaptureEv' 
./Release/main.o:main.cpp:(.text$_ZN12wxWindowBase19SetAcceleratorTableERK18wxAcceleratorTable[wxWindowBase::SetAcceleratorTable(wxAcceleratorTable const&)]+0x19): undefined reference to `_imp___ZN8wxObject3RefERKS_' 
./Release/main.o:main.cpp:(.text$_ZN12wxWindowBase7SetNameERK8wxString[wxWindowBase::SetName(wxString const&)]+0x12): undefined reference to `_imp___ZN12wxStringBaseaSERKS_' 
./Release/main.o:main.cpp:(.text$_ZN12wxButtonBaseD0Ev[wxButtonBase::~wxButtonBase()]+0xb): undefined reference to `_imp___ZTV12wxButtonBase' 
./Release/main.o:main.cpp:(.text$_ZN12wxButtonBaseD0Ev[wxButtonBase::~wxButtonBase()]+0x19): undefined reference to `_imp___ZN9wxControlD2Ev' 
./Release/main.o:main.cpp:(.text$_ZN12wxButtonBaseD1Ev[wxButtonBase::~wxButtonBase()]+0xb): undefined reference to `_imp___ZTV12wxButtonBase' 
./Release/main.o:main.cpp:(.text$_ZN12wxButtonBaseD1Ev[wxButtonBase::~wxButtonBase()]+0x15): undefined reference to `_imp___ZN9wxControlD2Ev' 
./Release/main.o:main.cpp:(.text$_ZN9wxMiniApp7OnClickER14wxCommandEvent[wxMiniApp::OnClick(wxCommandEvent&)]+0x1f): undefined reference to `_imp___ZN12wxWindowBase5CloseEb' 
collect2: ld returned 1 exit status 
mingw32-make.exe[1]: *** [Release/Test] Error 1 
mingw32-make.exe: *** [All] Error 2 
mingw32-make.exe[1]: Leaving directory `C:/Users/DarkBug/Desktop/Test' 
----------Build Ended---------- 
44 errors, 0 warnings
Even if i go to project options and insert "C:/wxWidgets2.8/lib/gcc_lib" into Linker->Library Paths as well as insert "libwxmsw28u.a;libwxbase28u.a" into Linker->Libraries it don't works.
In Code::Blocks i just have to insert the dependencies into Settings->Compiler and debugger...->Linker settings->Link libraries and add the -static switch to Other linker options. After that it will link every program statically.

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 12:59 pm
by eranif
DarkBug wrote:but i get the error message: wxmsw28u_gcc.dll not found.
Why not simply ship the DLL along with your software?
There are many advantages for using DLL over static library (reduced link time, smaller packages and others)

I never tried to use wx as static library, but in the link line I only see "-lwxmsw28u"
Is this sufficient? do you have any other static libraries that you need to link with? (like: wxbase), if you do you need to add them
DarkBug wrote:In Code::Blocks i just have to insert the dependencies into Settings->Compiler and debugger...->Linker settings->Link libraries and add the -static switch to Other linker options. After that it will link every program statically.
In my daily work we use the 'scrum' development methodology, as part of the process, we conduct a daily meeting where each developer on my team need to share with others the following
information: "what did you do yesterday?" "what I am going to do today?" and "who is blocking me?"

Any other information is replied with "And this information is relevant how?"

Eran

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 3:10 pm
by DarkBug
In this case i only want to compile your test app (Categorie: GUI, Template Type: Executable (wxWidgets enabled)) and link it statically to see how to configure CodeLite to link statically. I often use static link if i program little tools. For greater programs i ship the dll along with the software. Here is the Code of your test app:

Code: Select all

#include <wx/wx.h>

// application class
class wxMiniApp : public wxApp
{
public:
	// function called at the application initialization
	virtual bool OnInit();

	// event handler for button click
	void OnClick(wxCommandEvent& event) {
		GetTopWindow()->Close();
	}
};

IMPLEMENT_APP(wxMiniApp);

bool wxMiniApp::OnInit()
{
	// create a new frame and set it as the top most application window
	SetTopWindow( new wxFrame( NULL, -1, wxT(""), wxDefaultPosition, wxSize( 100, 50) ) );

	// create new button and assign it to the main frame
	new wxButton( GetTopWindow(), wxID_EXIT, wxT("Click!") );

	// connect button click event with event handler
	Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxMiniApp::OnClick) );

	// show main frame
	GetTopWindow()->Show();

	// enter the application's main loop
	return true;
}
Needs this test app more static libraries than libwxmsw28u.a and libwxbase28u.a?

Best regards,
DarkBug

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 3:29 pm
by eranif
DarkBug wrote:Needs this test app more static libraries than libwxmsw28u.a and libwxbase28u.a?
I am not sure since I never used the 'static' option of wxWidgets (I usually use monolithic / shared)
Maybe someone with more experience than me with wxWidgets as static library could answer this

Eran

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 4:00 pm
by DarkBug
Ok. Another question: Where does CodeLite search for static libraries if i don't insert a library path into Project Settings->Common Settings->Linker->Library Path, but insert libraries into Project Settings->Common Settings->Linker->Libraries?

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 7:48 pm
by NTUM
I noticed that your file is being compiled to use the wxWidgets dynamic library...

Code: Select all

g++  -c  "C:/Users/DarkBug/Desktop/Test/main.cpp" -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:\wxWidgets2.8\lib\gcc_dll\mswu -IC:\wxWidgets2.8\include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0  -Wno-attributes   -o ./Release/main.o -I. 
...while your linker is set to use the wxWidgets static library:

Code: Select all

g++ -o ./Release/Test @"C:\Users\DarkBug\Desktop\Test\Test.txt" -L.   -mwindows -s  -mthreads -LC:\wxWidgets2.8\lib\gcc_lib -lwxmsw28u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwxregexu -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 
Have you tried passing the --static option to the compiler too, so that way the "C++ Compiler Options" text box reads...

$(shell wx-config --cxxflags --unicode=yes --debug=no --static)

Re: Where to put the -static switch?

Posted: Wed Mar 28, 2012 10:08 pm
by DarkBug
I had to switch to another compiler. Now use the original MinGW from http://www.mingw.org. I added the --static switch to the compiler options too. In the end that was the last jigsaw, thank you NTUM. After i added the --static switch the program compiled. I tryed to open it from a non-developer machine and it says that libgcc_s_dw2-1.dll is missing. Then i added the -static switch before the -mwindows switch. Now it runs on non-developer machines.

Can somebody tell me the difference between the -static and the --static switch is? In the end i needed both of them.

Can i configure CodeLite to use this project settings for every project?

Re: Where to put the -static switch?

Posted: Thu Mar 29, 2012 12:23 pm
by Jarod42
--static in a flag for wx-config
-static is a flag for gcc

Re: Where to put the -static switch?

Posted: Thu Mar 29, 2012 3:49 pm
by DarkBug
I thought so, but why do i in Code::Blocks just have to add the -static switch to Settings->Compiler and debugger...->Linker settings->Other linker options and it works?

Re: Where to put the -static switch?

Posted: Thu Mar 29, 2012 7:45 pm
by eranif
DarkBug wrote:Another question: Where does CodeLite search for static libraries if i don't insert a library path into Project Settings->Common Settings->Linker->Library Path, but insert libraries into Project Settings->Common Settings->Linker->Libraries?
codelite is not a complier nor linker, it does not search for them, it simply activate the compiler to do this.
Even without knowing the configuration you can see in the build line where does ld is looking for the libraries (and from your link lines, I dont see any -static flag that is being passed to ld)
DarkBug wrote:but why do i in Code::Blocks just have to add the -static switch to Settings->Compiler and debugger...->Linker settings->Other linker options and it works?
Now that Jarod42 mentioned it, you need to add it to "project settings -> linker -> options"

so it will look something similar to:

Code: Select all

-s;$(shell wx-config --debug=no --unicode=yes --libs );-static
note that the -static is placed outside of the $(shell ..) expression

Eran