Forward Declarations Compilation Errors

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
Aphrodites
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Dec 27, 2018 7:34 am

Forward Declarations Compilation Errors

Post by Aphrodites »

I have been following the guide here: https://docs.wxwidgets.org/stable/overv ... world.html , and while compiling using cmake, there has been errors.

The guitestmain.cpp:

Code: Select all

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
	#include <wx/wx.h>
#endif

using namespace std;

class MyApp: public wxApp{

public:
	virtual bool OnInit();

};
The CMakeLists.txt:

Code: Select all

cmake_minimum_required (VERSION 2.6)
set (CMAKE_CXX_STANDARD 11)
project (guitest)
add_executable(guitest guitestmain.cpp)
The terminal result:

Code: Select all

jmbp:Desktop john$ cd guitest/
jmbp:guitest john$ mkdir build
jmbp:guitest john$ cd build
jmbp:build john$ cmake -G Ninja ..
-- The C compiler identification is AppleClang 10.0.0.10001044
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- 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: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/john/Desktop/guitest/build
jmbp:build john$ ninja
[1/2] Building CXX object CMakeFiles/guitest.dir/guitestmain.cpp.o
FAILED: CMakeFiles/guitest.dir/guitestmain.cpp.o 
/Library/Developer/CommandLineTools/usr/bin/c++    -std=gnu++11 -MD -MT CMakeFiles/guitest.dir/guitestmain.cpp.o -MF CMakeFiles/guitest.dir/guitestmain.cpp.o.d -o CMakeFiles/guitest.dir/guitestmain.cpp.o -c ../guitestmain.cpp
In file included from ../guitestmain.cpp:1:
In file included from /usr/local/include/wx/wxprec.h:12:
/usr/local/include/wx/defs.h:62:13: error: "No Target! You should use wx-config program for compilation flags!"
#           error "No Target! You should use wx-config program for compilation flags!"
            ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:24:
In file included from /usr/local/include/wx/event.h:22:
/usr/local/include/wx/cursor.h:108:26: error: calling 'GetBusyCursor' with incomplete return type 'const wxCursor'
            wxSetCursor( wxBusyCursor::GetBusyCursor() );
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/wx/utils.h:753:27: note: 'GetBusyCursor' declared here
    static const wxCursor GetBusyCursor();
                          ^
/usr/local/include/wx/gdicmn.h:32:28: note: forward declaration of 'wxCursor'
class WXDLLIMPEXP_FWD_CORE wxCursor;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:24:
/usr/local/include/wx/event.h:1880:14: error: field has incomplete type 'wxCursor'
    wxCursor m_cursor;
             ^
/usr/local/include/wx/gdicmn.h:32:28: note: forward declaration of 'wxCursor'
class WXDLLIMPEXP_FWD_CORE wxCursor;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:24:
/usr/local/include/wx/event.h:1863:11: error: no matching constructor for initialization of 'wxEvent'
        : wxEvent(event),
          ^       ~~~~~
/usr/local/include/wx/event.h:928:5: note: candidate constructor not viable: no known conversion from 'const wxSetCursorEvent' to 'int' for 1st argument
    wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL );
    ^
/usr/local/include/wx/event.h:1080:5: note: candidate constructor not viable: no known conversion from 'const wxSetCursorEvent' to 'const wxEvent' for 1st argument
    wxEvent(const wxEvent&);            // for implementing Clone()
    ^
/usr/local/include/wx/event.h:1876:56: error: cannot initialize return object of type 'wxEvent *' with an rvalue of type 'wxSetCursorEvent *'
    virtual wxEvent *Clone() const wxOVERRIDE { return new wxSetCursorEvent(*this); }
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:25:
/usr/local/include/wx/app.h:798:11: error: use of undeclared identifier 'wxApp'
        { wxApp::SetInitializerFunction(fn); }
          ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
In file included from /usr/local/include/wx/window.h:25:
/usr/local/include/wx/region.h:239:24: error: 'wxRegion' is an incomplete type
    return DoIntersect(wxRegion(rect));
                       ^
/usr/local/include/wx/gdicmn.h:37:28: note: forward declaration of 'wxRegion'
class WXDLLIMPEXP_FWD_CORE wxRegion;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
In file included from /usr/local/include/wx/window.h:25:
/usr/local/include/wx/region.h:244:23: error: 'wxRegion' is an incomplete type
    return DoSubtract(wxRegion(rect));
                      ^
/usr/local/include/wx/gdicmn.h:37:28: note: forward declaration of 'wxRegion'
class WXDLLIMPEXP_FWD_CORE wxRegion;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
In file included from /usr/local/include/wx/window.h:25:
/usr/local/include/wx/region.h:249:18: error: 'wxRegion' is an incomplete type
    return DoXor(wxRegion(rect));
                 ^
/usr/local/include/wx/gdicmn.h:37:28: note: forward declaration of 'wxRegion'
class WXDLLIMPEXP_FWD_CORE wxRegion;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:78:12: error: field has incomplete type 'wxFont'
    wxFont font;
           ^
/usr/local/include/wx/gdicmn.h:33:28: note: forward declaration of 'wxFont'
class WXDLLIMPEXP_FWD_CORE wxFont;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:81:14: error: field has incomplete type 'wxColour'
    wxColour colFg;
             ^
/usr/local/include/wx/gdicmn.h:31:28: note: forward declaration of 'wxColour'
class WXDLLIMPEXP_FWD_CORE wxColour;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:85:14: error: field has incomplete type 'wxColour'
    wxColour colBg;
             ^
/usr/local/include/wx/gdicmn.h:31:28: note: forward declaration of 'wxColour'
class WXDLLIMPEXP_FWD_CORE wxColour;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:1517:13: error: unknown type name 'WXWidget'
    virtual WXWidget GetHandle() const = 0;
            ^
/usr/local/include/wx/window.h:1519:34: error: unknown type name 'WXWidget'
    virtual void AssociateHandle(WXWidget WXUNUSED(handle)) { }
                                 ^
/usr/local/include/wx/window.h:1668:26: error: field has incomplete type 'wxCursor'
    wxCursor             m_cursor;
                         ^
/usr/local/include/wx/gdicmn.h:32:28: note: forward declaration of 'wxCursor'
class WXDLLIMPEXP_FWD_CORE wxCursor;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:1669:26: error: field has incomplete type 'wxFont'
    wxFont               m_font;                // see m_hasFont
                         ^
/usr/local/include/wx/gdicmn.h:33:28: note: forward declaration of 'wxFont'
class WXDLLIMPEXP_FWD_CORE wxFont;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:1670:26: error: field has incomplete type 'wxColour'
    wxColour             m_backgroundColour,    //     m_hasBgCol
                         ^
/usr/local/include/wx/gdicmn.h:31:28: note: forward declaration of 'wxColour'
class WXDLLIMPEXP_FWD_CORE wxColour;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:1671:26: error: field has incomplete type 'wxColour'
                         m_foregroundColour;    //     m_hasFgCol
                         ^
/usr/local/include/wx/gdicmn.h:31:28: note: forward declaration of 'wxColour'
class WXDLLIMPEXP_FWD_CORE wxColour;
                           ^
In file included from ../guitestmain.cpp:3:
In file included from /usr/local/include/wx/wx.h:38:
/usr/local/include/wx/window.h:1678:26: error: field has incomplete type 'wxRegion'
    wxRegion             m_updateRegion;
                         ^
/usr/local/include/wx/gdicmn.h:37:28: note: forward declaration of 'wxRegion'
class WXDLLIMPEXP_FWD_CORE wxRegion;
                           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.
How do I solve this problem?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Forward Declarations Compilation Errors

Post by PB »

I know very little about CMake but I am surprised it even finds wxWidgets. I thought you must tell CMake about it, with something like

Code: Select all

find_package(wxWidgets 3.1.0 COMPONENTS core base REQUIRED)
Assuming this is not you, here is a recent thread about CMake on OSX (which it seems you are using)
https://groups.google.com/forum/#!topic ... oPVS3i9n9o

wxWidgets officially supports CMake only since 3.1, here is official CMake guide for wxWidgets
https://docs.wxwidgets.org/trunk/overview_cmake.html
Aphrodites
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Dec 27, 2018 7:34 am

Re: Forward Declarations Compilation Errors

Post by Aphrodites »

I added the first piece of code in the third line of CMakeLists, but it returned this:

Code: Select all

CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_PREFIXES
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_SUFFIXES
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_PREFIXES
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_SUFFIXES
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES) (Required is at
  least version "3.1.0")
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindwxWidgets.cmake:963 (find_package_handle_standard_args)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/john/Desktop/guitest/build/CMakeFiles/CMakeOutput.log".
The second part I don't understand, and the third part seems to be a guide on compiling the library using Cmake, and not the app itself.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Forward Declarations Compilation Errors

Post by PB »

Aphrodites wrote:The second part I don't understand
I do not understand what exactly you did not understand? An OSX user there details a procedure how to use wxWidgets with CMake on OSX. I thought the information which is or perhaps will be there could be of help.
Aphrodites wrote:third part seems to be a guide on compiling the library using Cmake, and not the app itself.
Actually, it is both: At the end there is a chapter "Using CMake with your applications" which describes how to use CMake with your application using wxWidgets:
https://docs.wxwidgets.org/trunk/overvi ... cmake_apps


I assume you googled for the solution before you posted and advice such as listed e.g. here did not help...

BTW, when asking such questions, it is expected that information about the platform and OS version, wxWidgets version and configuration(s), as well as a compiler toolchain used are provided.
Aphrodites
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Dec 27, 2018 7:34 am

Re: Forward Declarations Compilation Errors

Post by Aphrodites »

The second part only mentions some things about building the app, and mostly about building wxWidgets itself with Cmake. His (2) error is the same with mine, but when I try to force wxWidgets_LIBRARIES in CMakeLists.txt on my downloaded directory's lib, my build directory's lib, my whole include directory, or my installed directory in my include, it gives me the same result. I followed the chapter at the end with no avail, still giving the same result.
Post Reply