pkulchenko / wxlua

wxlua: Lua bindings for wxWidgets cross-platform GUI toolkit; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and wxWidgets 3.x
306 stars 59 forks source link

CMake fails when building for wx3.1.4 #67

Closed LesNewell-SheetCam closed 4 years ago

LesNewell-SheetCam commented 4 years ago

Win10 wxWidgets 3.1.4 Git master CMake 3.17.2 wxLua Git master

wxWidgets built multilib shared using VS2019. Samples compile and run.

Run CMake on wxLua and I get this error: ` WARNING: Unable to find requested wxWidgets component : scintilla

I now get: `CMake Warning at build/CMakewxAppLib.cmake:325 (message):

It is obviously finding wx because the version numbers show correctly and the wxWidgets paths are correct. This looks like the custom FindwxWidgets.cmake is unhappy so I removed it, allowing CMake to fall back to it's own FindwxWidgets.cmake.

Now after this hackery CMake is happy, generating a VS solution. The files compile but won't link. I get loads of unresolved externals: 4>luamodule.obj : error LNK2001: unresolved external symbol "protected: static struct wxEventTable const wxApp::sm_eventTable" (?sm_eventTable@wxApp@@1UwxEventTable@@B) 4>wxllua.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlobject.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlstate.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlua_bind.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlstack.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlbind.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlcallb.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlconsole.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxldserv.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxldtarg.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxlsock.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxldebug.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxbase_bind.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxbase_data.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA) 4>wxbase_datetime.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)" (?wxTheAssertHandler@@3P6AXABVwxString@@H000@ZA)

I checked and the linker has the paths to the correct wxWidgets libraries.

pkulchenko commented 4 years ago

WARNING: Unable to find requested wxWidgets component : scintilla * wxWidgets requested but not found.

What happens if you ignore this warning? Can you include full cmake command and its output?

I just rebuilt using the latest wxlua master and wxwidgets 3.1.4 on Windows and don't see this warning, but I'm using mingw/msys.

LesNewell-SheetCam commented 4 years ago

If I ignore the warning it will generate solution files but they are missing links to the wx headers and libraries. If I manually add them to the projects I still end up with the same link errors. I'm using cmake-gui. I'll post the output tomorrow.

pkulchenko commented 4 years ago

Also, can you try building from the command line instead of cmake-gui?

LesNewell-SheetCam commented 4 years ago

Here's the result of running cmake on the command line. Sorry about the formatting. I don't know why that is happening.

C:\wx-3.0\wxlua\build>"C:\Program Files\CMake\bin\cmake" -DwxWidgets_ROOT_DIR=/wx-3.0/wxWidgets -DwxWidgets_LIB_DIR=/wx-3.0/wxWidgets/lib/vc_dll -DBUILD_SHARED_LIBS=true -A Win32 ../wxlua -- Building for: Visual Studio 16 2019 -- The C compiler identification is MSVC 19.24.28316.0 -- The CXX compiler identification is MSVC 19.24.28316.0 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x86/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x86/cl.exe - works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x86/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x86/cl.exe - works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- --------------------------------------------------------------------------- -- CMake command line options and tips specific to this project -- -- In the CMake GUI you can set values and press configure a few times -- and until there are no more red items, then press generate. -- -- Usage: cmake -D[OPTION_NAME]=[OPTION_VALUE] /path/to/CMakeLists.txt/ -- --------------------------------------------------------------------------- -- -DHELP=TRUE -- Show this help message and exit, no files will be generated. -- -DCMAKE_BUILD_TYPE=[Debug, Release, RelWithDebInfo, MinSizeRel] : (Default Debug) -- Makefiles : You must set the build type to Debug, Release... -- MSVC GUI : No need to set this since you can choose it in the GUI. -- -DBUILD_SHARED_LIBS=[TRUE, FALSE] : (Default static in MSW, shared in Linux) -- Build shared (.DLL or .so) or static (.lib or .a) libraries. -- ---------------------------------------------------------------------------

-- * No build type was specified, using default 'Debug'

-- -- BUILD TYPE: Debug -- BUILD_SHARED_LIBS: true -- -- * System is 32-bit TRUE, is 64-bit FALSE -- -- CMAKE_SOURCE_DIR = C:/wx-3.0/wxlua/wxLua -- CMAKE_BINARY_DIR = C:/wx-3.0/wxlua/build --

-- --------------------------------------------------------------------------- -- wxWidgets library settings : -- -- Note that ONLY an all shared (DLL) or all static build is supported. -- I.E. If you choose shared you must link to shared wxWidgets libs. -- Set -DBUILD_SHARED_LIBS=[TRUE, FALSE] to control shared/static lib. -- -- Finding wxWidgets for MSW and MSVC -- -DwxWidgets_ROOT_DIR=[path] : (e.g. /path/to/wxWidgets/) -- Path to the root of the wxWidgets build, must at least set this. -- -DwxWidgets_LIB_DIR=[path] : (e.g. /path/to/wxWidgets/lib/vc_lib/) -- Path to the wxWidgets lib dir also set this if libs can't be found. -- -DwxWidgets_CONFIGURATION=[configuration] : -- Set wxWidgets configuration; e.g. msw, mswu, mswunivu... -- Where 'u' = unicode and 'd' = debug. -- MSVC GUI : You need only choose msw, mswu, mswuniv, mswunivu since -- release or debug mode is chosen in the GUI. -- -DwxWidgets_COMPONENTS=[...stc;html;adv;core;base or mono] : -- For non-monolithic builds choose the wxWidgets libs to link to. -- xrc;xml;gl;net;media;propgrid;richtext;aui;stc;html;adv;core;base -- For monolithic builds choose mono and the contribs libs. -- stc;mono -- The extra decorations, e.g. wxmsw28ud_adv.lib, will be searched for. -- Libs that cannot be found will be printed below, please fix/remove -- them to be able to build this project. -- You will get compilation/linker errors if wxWidgets is not found. -- -- Finding wxWidgets for GCC and Unix type systems -- -DwxWidgets_CONFIG_EXECUTABLE=[path/to/wx-config] : -- Specify path to wx-config script for GCC and Unix type builds -- * ---------------------------------------------------------------------------

-- Using these wxWidgets components: stc;scintilla;webview;gl;xrc;xml;net;media;propgrid;richtext;aui;html;adv;core;base -- Could NOT find wxWidgets (missing: wxWidgets_FOUND) -- CMake Warning at build/CMakewxAppLib.cmake:325 (message):

-- - wxWidgets_VERSION = 3.1.4 = 3.1.4 -- - wxWidgets_COMPONENTS = stc;scintilla;webview;gl;xrc;xml;net;media;propgrid;richtext;aui;html;adv;core;base -- - wxWidgets_INCLUDE_DIRS = /wx-3.0/wxWidgets/lib/vc_dll/mswu;/wx-3.0/wxWidgets/include -- - wxWidgets_LIBRARY_DIRS = /wx-3.0/wxWidgets/lib/vc_dll -- - wxWidgets_LIBRARIES = debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_stc.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_stc.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_webview.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_webview.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_gl.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_gl.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_xrc.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_xrc.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31ud_xml.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31u_xml.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31ud_net.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31u_net.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_media.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_media.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_propgrid.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_propgrid.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_richtext.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_richtext.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_aui.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_aui.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_html.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_html.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_adv.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_adv.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31ud_core.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxmsw31u_core.lib;debug;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31ud.lib;optimized;/wx-3.0/wxWidgets/lib/vc_dll/wxbase31u.lib;opengl32;glu32;winmm;comctl32;rpcrt4;wsock32 -- - wxWidgets_CXX_FLAGS = -- - wxWidgets_DEFINITIONS = WXUSINGDLL;UNICODE;_UNICODE -- - wxWidgets_DEFINITIONS_DEBUG = _DEBUG;WXDEBUG -- - wxWidgets_PORTNAME = -- - wxWidgets_UNIVNAME = -- - wxWidgets_UNICODEFLAG = -- - wxWidgets_DEBUGFLAG = WARNING: Unable to find requested wxWidgets component : scintilla -- wxWidgets requested but not found. -- wxLua using built-in Lua 5.1 library -- WARNING: cppcheck NOT found, NOT generating ADD_CPPCHECK_TEST() tests -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- WARNING: Doxygen NOT found, wxLua_doxygen target will not be generated. -- Configuring done -- Generating done -- Build files have been written to: C:/wx-3.0/wxlua/build

LesNewell-SheetCam commented 4 years ago

OK, most of the link errors seem to be specific to my slightly odd configuration which is needed to maintain XP compatibility. If I do the CMake hackery I get something that mostly builds.

I did find a problem in wxlstack.h: WX_DECLARE_HASH_MAP_WITH_DECL( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual, wxUIntPtrToUIntPtrHashMap, class WXDLLIMPEXP_BASE );

I'm using shared wxWidgets and shared wxLua so WXDLLIMPEXP_BASE resolves to __declspec(dllimport). This results in a number of unresolved external symbols.

Just for testing I changed it to: WX_DECLARE_HASH_MAP_WITH_DECL( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual, wxUIntPtrToUIntPtrHashMap, class);

I'll see if that causes problems when I get to reading the Lua stack.

pkulchenko commented 4 years ago

-DwxWidgets_ROOT_DIR=/wx-3.0/wxWidgets

-- Could NOT find wxWidgets (missing: wxWidgets_FOUND) -- * CMake Warning at build/CMakewxAppLib.cmake:325 (message): WARNING: Could not find wxWidgets! Please see help above.

I'm not sure why the script would report that wxWidgets is not found; maybe try changing the ROOT reference to c:/wx-3.0/wxWidgets or c:\wx-3.0\wxWidgets.

I'll see if that causes problems when I get to reading the Lua stack.

I'm not sure what else to suggest, so if you get this resolved, please update the ticket with details. Thanks!

LesNewell-SheetCam commented 4 years ago

I tried changing to c:\wx-3.0\wxWidgets and it made no difference. It must be finding wxWidgets because you get this: -- * - wxWidgets_VERSION = 3.1.4 = 3.1.4 Additionally if I remove the FindwxWidgets.cmake supplied with wxLua and use the one supplied with cMake it finds wxWidgets as it should.

pkulchenko commented 4 years ago

Additionally if I remove the FindwxWidgets.cmake supplied with wxLua and use the one supplied with cMake it finds wxWidgets as it should.

I think this is correct. It probably comes down to the missing versions in the script. I updated the script, so expect it to work.

LesNewell-SheetCam commented 4 years ago

Thanks. I just tested it and it CMake now completes. Did you have any thoughts on the problem in wxlstack.h? I also found another anomaly. In wxWebview_bind.h, line 14: #if not defined(wxUSE_WEBVIEW) This generates a compiler warning. Should that not be: #if !defined(wxUSE_WEBVIEW)

pkulchenko commented 4 years ago

Did you have any thoughts on the problem in wxlstack.h? I'm using shared wxWidgets and shared wxLua so WXDLLIMPEXP_BASE resolves to __declspec(dllimport). This results in a number of unresolved external symbols.

I'm not sure why this is an issue, as I also use a shared wxWidgets build on Windows and have never had a problem (although I'm not using VS).

I'll see if that causes problems when I get to reading the Lua stack.

I read this as being related to the wxlstack.h issue and that you were going to see if this is a real issue or not.

I also found another anomaly. In wxWebview_bind.h, line 14:

if not defined(wxUSE_WEBVIEW)

This generates a compiler warning. Should that not be:

if !defined(wxUSE_WEBVIEW)

I think you are right, but I'll double check.

pkulchenko commented 4 years ago

@sheetcam, fixed the check; thanks! Let me know if you figure out the wxlstack.h issue.

LesNewell-SheetCam commented 4 years ago

Well, WXDLLIMPEXP_BASE resolves to __declspec(dllimport). As wxUIntPtrToUIntPtrHashMap is not defined in any other libraries, there is an unresolved external.

I think this comes down to how the two compilers handle linking.

VC expects to be able to resolve all externals when you create a libary.

In my experience GCC does not worry too much about unresolved externals when creating libraries. It only fully checks when you link your final executable. If the executable does not use those externals you won't get any errors. I've been bitten by this before. My libraries appeared to build fine but I had problems linking the executable due to unresolved externals.

pkulchenko commented 4 years ago

@sheetcam, I think this definition shouldn't have _WITH_DECL suffix. Can you try this patch:

diff --git a/wxLua/modules/wxlua/debug/wxlstack.h b/wxLua/modules/wxlua/debug/wxlstack.h
index 13109c1..862a605 100644
--- a/wxLua/modules/wxlua/debug/wxlstack.h
+++ b/wxLua/modules/wxlua/debug/wxlstack.h
@@ -24,8 +24,8 @@ class WXDLLIMPEXP_FWD_CORE wxProgressDialog;

 class WXDLLIMPEXP_FWD_WXLUADEBUG wxLuaDebugData;

-WX_DECLARE_HASH_MAP_WITH_DECL( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual,
-                               wxUIntPtrToUIntPtrHashMap, class WXDLLIMPEXP_BASE );
+WX_DECLARE_HASH_MAP( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual,
+                     wxUIntPtrToUIntPtrHashMap, class WXDLLIMPEXP_BASE );

 // ----------------------------------------------------------------------------
 // wxWindowIds for the wxLuaStackDialog
pkulchenko commented 4 years ago

Actually, this is a better diff:

diff --git a/wxLua/modules/wxlua/debug/wxlstack.h b/wxLua/modules/wxlua/debug/wxlstack.h
index 13109c1..51a6f18 100644
--- a/wxLua/modules/wxlua/debug/wxlstack.h
+++ b/wxLua/modules/wxlua/debug/wxlstack.h
@@ -24,8 +24,8 @@ class WXDLLIMPEXP_FWD_CORE wxProgressDialog;

 class WXDLLIMPEXP_FWD_WXLUADEBUG wxLuaDebugData;

-WX_DECLARE_HASH_MAP_WITH_DECL( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual,
-                               wxUIntPtrToUIntPtrHashMap, class WXDLLIMPEXP_BASE );
+WX_DECLARE_HASH_MAP( wxUIntPtr, wxUIntPtr, wxIntegerHash, wxIntegerEqual,
+                     wxUIntPtrToUIntPtrHashMap );

 // ----------------------------------------------------------------------------
 // wxWindowIds for the wxLuaStackDialog
LesNewell-SheetCam commented 4 years ago

Yup, that second diff works for me. Thank you.

pkulchenko commented 4 years ago

Ok; pushed.