link error using wxwidgets in static for my own lib

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Laurent Berger
Earned some good credits
Earned some good credits
Posts: 138
Joined: Tue May 20, 2008 1:03 pm

link error using wxwidgets in static for my own lib

Post by Laurent Berger »

Hi,

I can compile link and run my project using my own lib using wxwidgets dll libs. Using static libs I have got 1 error and three warnings :

Code: Select all

2>main.obj : warning LNK4217: locally defined symbol ??0wxString@@QEAA@PEBD@Z (public: __cdecl wxString::wxString(char const *)) imported in function "unsigned char __cdecl wxNano::GetNumber<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$GetNumber@E@wxNano@@YAEV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
2>main.obj : warning LNK4217: locally defined symbol ??1wxString@@QEAA@XZ (public: __cdecl wxString::~wxString(void)) imported in function "unsigned char __cdecl wxNano::GetNumber<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$GetNumber@E@wxNano@@YAEV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
2>main.obj : warning LNK4049: locally defined symbol ?wxDefaultPosition@@3VwxPoint@@B (class wxPoint const wxDefaultPosition) imported
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) long __cdecl wxGetNumberFromUser(class wxString const &,class wxString const &,class wxString const &,long,long,long,class wxWindow *,class wxPoint const &)" (__imp_?wxGetNumberFromUser@@YAJAEBVwxString@@00JJJPEAVwxWindow@@AEBVwxPoint@@@Z) referenced in function "unsigned char __cdecl wxNano::GetNumber<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$GetNumber@E@wxNano@@YAEV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
2>G:\Lib\build\wxnanosamplelib\Debug\TDwx.exe : fatal error LNK1120: 1 unresolved externals
2>Done building project "TDwx.vcxproj" -- FAILED.
My project https://github.com/LaurentBerger/wxNano ... ter/sampleuse a lib https://github.com/LaurentBerger/wxNanowhich use wxwidgets. I use cmake to build wxnanolib and cmake to build wxnanosample . compile flags are in both configuration (dll or static) WXUSINGDLL;__WXMSW__ for exe and lib

What's wrong in my configuration ?

windows 10 VS 2017 wxwidgets github master
I use this flags
L.B.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Re: link error using wxwidgets in static for my own lib

Post by stahta01 »

You likely used the wrong defines and/or flags to build wxNano or wxNano is poorly written.

Edit: Using WXUSINGDLL means you are expected to link to the wxWidgets DLLs.

Edit3: I am trying to build the wxNano code using MSys2 GCC 8 to confirm the code is good using OpenCV 3.4.2 and wxWidgets 3.1.x
To confirm the CMake files are good is not sometime I can do.

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Re: link error using wxwidgets in static for my own lib

Post by stahta01 »

Only needed one code fix. main returns an int.

Edit: Downloading CMake for windows to see if it will create a good CB project to see if the cmake is close to correct.

Code: Select all

diff --git a/sample/main.cpp b/sample/main.cpp
index 6a2b8fb..ab5925c 100644
--- a/sample/main.cpp
+++ b/sample/main.cpp
@@ -10,7 +10,7 @@ class MyEventLoop : public wxEventLoopBase
 { 
 };
 
-void main(int argc,char**argv)
+int main(int argc,char**argv)
 {
     
     int l1 = wxNano::GetNumber<int>();
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Re: link error using wxwidgets in static for my own lib

Post by stahta01 »

I have not figured out how to build the sample code using an cmake created CB project.

Tim S.
Laurent Berger
Earned some good credits
Earned some good credits
Posts: 138
Joined: Tue May 20, 2008 1:03 pm

Re: link error using wxwidgets in static for my own lib

Post by Laurent Berger »

thanks for all test. What is your platform linux or windows ? (MSys2 GCC 8=windows ?)

There is a problem with flag WXUSINGDLL in wxNanoSample : it must be used only when static build is needed. I tried to insert in cmakelists.txt but it is not tested yet
L.B.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Re: link error using wxwidgets in static for my own lib

Post by stahta01 »

I tested on Windows 7 64 bit; MSys2 is a development environment that works a little like Unix/Linux.
Compiler was GCC (Rev1, Built by MSYS2 project) 8.2.0

WXUSINGDLL means you are using the wxWidgets DLLs.

Tim S.
Post Reply