On 6/16/2012 4:00 PM, Nathan Ridge wrote:
> ----------------------------------------
>> Date: Sat, 16 Jun 2012 09:31:57 -0400
>> From:
dama...@gmail.com
>> To:
wx-u...@googlegroups.com
>> Subject: Re: Building a static library that depends on wxWidgets
>>
>> On 6/16/2012 5:03 AM, Llu�s Batlle i Rossell wrote:
>>> On Fri, Jun 15, 2012 at 11:09:47PM -0400, damateem wrote:
>>>> I've built a static library that utilizes wxWidgets. It built
>>>> without errors, but I'm having linking issues when I link the
>>>> library into my application. When the application links, the linker
>>>> reports that there are multiple definitions of wxWidgets classes and
>>>> functions.
>>>>
>>>> What might I be doing wrong? Is there documentation somewhere that
>>>> will step me through this process?
>>> I don't think there is any difference whether it is wxWidgets, or any other
>>> library, in this your linking process.
>>>
>>> The linker will tell you where are the multiple definitions.
>> True, but how do I prevent the multiple definitions? Since my library
>> uses wxWidgets, MinGW is including it in my library.
>>
>> It seems that I need a way to tell MinGW to exclude wxWidgets from my
>> library.
>>
>> How do I do that?
> MinGW should not include wxWidgets in your library unless you tell it to.
>
> What commands do you use to build your library?
Just to prove I could get this to work at the simplest level, I created
two very small example projects. One a static library that utilizes
wxWidgets and another, a wxWidgets application that utilizes the library.
The library contains only one function,
void Dummy( wxString &Param )
{
Param =_T("Dummy string");
}
which it called from a button click handler in the application.
void test_appFrame::OnbtnTestClick(wxCommandEvent& event)
{
wxString s;
Dummy( s );
wxMessageBox( s );
}
The library builds fine.
mingw32-g++.exe -Wall -g
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\contrib\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib\mswud
-c C:\user_data\david\code\test_lib\test_lib.cpp -o obj\Debug\test_lib.o
ar.exe -r -s libtest_lib.a obj\Debug\test_lib.o
ar.exe: creating libtest_lib.a
However, the application does not.
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__
-DwxUSE_UNICODE -Wno-attributes -Winvalid-pch -include wx_pch.h
-DWX_PRECOMP -Wall -g -D__WXDEBUG__
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\contrib\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib\mswud
-c C:\user_data\david\code\test_lib\wx_pch.h -o
wx_pch.h.gch\Debug_wx_pch_h_gch
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__
-DwxUSE_UNICODE -Wno-attributes -Winvalid-pch -include wx_pch.h
-DWX_PRECOMP -Wall -g -D__WXDEBUG__
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\contrib\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib\mswud
-c C:\user_data\david\code\test_lib\test_appMain.cpp -o
obj\Debug\test_appMain.o
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__
-DwxUSE_UNICODE -Wno-attributes -Winvalid-pch -include wx_pch.h
-DWX_PRECOMP -Wall -g -D__WXDEBUG__
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\contrib\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib\mswud
-c C:\user_data\david\code\test_lib\test_appApp.cpp -o
obj\Debug\test_appApp.o
windres.exe -i C:\USER_D~1\david\code\test_lib\resource.rc -J rc -o
obj\Debug\resource.res -O coff
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\include
-IC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib\mswud
mingw32-g++.exe
-LC:\user_data\david\dajac\source_pool\wxWidgets-2.8.11\lib\gcc_lib -L.
-o bin\Debug\test_app.exe obj\Debug\test_appApp.o
obj\Debug\test_appMain.o obj\Debug\resource.res -mthreads -ltest_lib
-lwxmsw28ud -lwxpngd -lwxjpegd -lwxtiffd -lwxzlibd -lkernel32 -luser32
-lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32
-luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
./libtest_lib.a(test_lib.o):C:/user_data/david/dajac/source_pool/wxWidgets-2.8.11/include/wx/string.h:965:
undefined reference to `wxStringBase::operator=(char const*)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 7 seconds)
1 errors, 0 warnings
I've tried moving "-ltest_lib" after "-lwxmsw28ud", but I get the same
error.
wxmsw28ud is being linked into the application, so why the undefined
reference error?
Thanks,
David