fatal error: Wt/WApplication.h: No such file or directory

983 Views Asked by At

I'm following along with this tutorial for Webtoolkit: https://www.webtoolkit.eu/wt/doc/tutorial/wt.html

I am running all this on a Rasbian/Debian on a Virtual Machine and I am using C++14

I decided to copy paste the hello.cpp code onto my Desktop and am compiling it like this on my terminal as I was facing linking errors and thus followed along with command line examples in the tutorial:

g++ -std=c++14 -o hello hello.cpp -I/usr/include -L/usr/lib

However I still get:

hello.cpp:1:29: fatal error: Wt/WApplication.h: No such file or directory
 #include <Wt/WApplication.h>

My Wt files are located in /usr/include and /usr/lib which is why I used them.

This stackoverflow did not solve my issue: How to Install Wt into a Custom Folder Without "fatal error: Wt/WApplication: No such file or directory"

EDIT: I was able to run the example files located in the Wt folders in /usr/lib/Wt/examples but can't run it on Desktop, I followed the command line examples on the tutorial for linking errors

EDIT 2: The cpp code if it helps, same as tutorial, just copy pasted:

#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>

class HelloApplication : public Wt::WApplication
{
public:
    HelloApplication(const Wt::WEnvironment& env);

private:
    Wt::WLineEdit *nameEdit_;
    Wt::WText *greeting_;
};

HelloApplication::HelloApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
    setTitle("Hello world");

    root()->addWidget(std::make_unique<Wt::WText>("Your name, please? "));
    nameEdit_ = root()->addWidget(std::make_unique<Wt::WLineEdit>());
    Wt::WPushButton *button = root()->addWidget(std::make_unique<Wt::WPushButton>("Greet me."));
    root()->addWidget(std::make_unique<Wt::WBreak>());
    greeting_ = root()->addWidget(std::make_unique<Wt::WText>());
    auto greet = [this]{
      greeting_->setText("Hello there, " + nameEdit_->text());
    };
    button->clicked().connect(greet);
}

int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
      return std::make_unique<HelloApplication>(env);
    });
}
3

There are 3 best solutions below

0
On

The Wt include files do not have the .h extension on some OSs. Try #include <Wt/WApplication>

root@08c7a05c8129:/usr/lib/Wt/examples/hello# ls /usr/include/Wt
Auth                       WBatchEditProxyModel       WDateValidator            WHTML5Audio          WLocalizedStrings         WPopupWidget           WSslInfo            WTimePicker
Chart                      WBoostAny                  WDefaultLayout            WHTML5Video          WLogger                   WProgressBar           WStackedWidget      WTimeValidator
Dbo                        WBootstrapTheme            WDefaultLoadingIndicator  WIOService           WMatrix4x4                WPushButton            WStandardItem       WTimer
Ext                        WBorder                    WDialog                   WIcon                WMeasurePaintDevice       WRadioButton           WStandardItemModel  WTimerWidget
Http                       WBorderLayout              WDllDefs.h                WIconPair            WMediaPlayer              WRandom                WStatelessSlot      WToolBar
Json                       WBoxLayout                 WDoubleSpinBox            WIdentityProxyModel  WMemoryResource           WRasterImage           WStreamResource     WTransform
Mail                       WBreak                     WDoubleValidator          WImage               WMenu                     WReadOnlyProxyModel    WString             WTree
Payment                    WBrush                     WEnvironment              WInPlaceEdit         WMenuItem                 WRectArea              WStringListModel    WTreeNode
Render                     WButtonGroup               WEvent                    WIntValidator        WMessageBox               WRectF                 WStringStream       WTreeTable
Utils                      WCalendar                  WException                WInteractWidget      WMessageResourceBundle    WRegExp                WStringUtil         WTreeTableNode
WAbstractArea              WCanvasPaintDevice         WFileResource             WItemDelegate        WMessageResources         WRegExpValidator       WSubMenuItem        WTreeView
WAbstractGLImplementation  WCheckBox                  WFileUpload               WItemSelectionModel  WModelIndex               WResource              WSuggestionPopup    WVBoxLayout
WAbstractItemDelegate      WCircleArea                WFitLayout                WJavaScript          WNavigationBar            WScrollArea            WSvgImage           WValidationStatus
WAbstractItemModel         WClientGLWidget            WFlags                    WJavaScriptPreamble  WObject                   WScrollBar             WTabWidget          WValidator
WAbstractItemView          WColor                     WFlashObject              WJavaScriptSlot      WOverlayLoadingIndicator  WSelectionBox          WTable              WVector3
WAbstractListModel         WCombinedLocalizedStrings  WFont                     WLabel               WPaintDevice              WServer                WTableCell          WVector4
WAbstractMedia             WComboBox                  WFontMetrics              WLayout              WPaintedWidget            WServerGLWidget        WTableColumn        WVectorImage
WAbstractProxyModel        WCompositeWidget           WFormModel                WLayoutItem          WPainter                  WShadow                WTableRow           WVideo
WAbstractSpinBox           WConfig.h                  WFormWidget               WLayoutItemImpl      WPainterPath              WSignal                WTableView          WViewWidget
WAbstractTableModel        WContainerWidget           WGLWidget                 WLength              WPanel                    WSignalMapper          WTemplate           WVirtualImage
WAbstractToggleButton      WCssDecorationStyle        WGenericMatrix            WLengthValidator     WPdfImage                 WSlider                WTemplateFormView   WVmlImage
WAccordionLayout           WCssStyleSheet             WGlobal                   WLineEdit            WPen                      WSocketNotifier        WText               WWebWidget
WAggregateProxyModel       WCssTheme                  WGoogleMap                WLineF               WPoint                    WSortFilterProxyModel  WTextArea           WWidget
WAnchor                    WDate                      WGradient                 WLink                WPointF                   WSound                 WTextEdit           WWidgetItem
WAnimation                 WDateEdit                  WGridLayout               WLoadingIndicator    WPolygonArea              WSpinBox               WTheme
WApplication               WDatePicker                WGroupBox                 WLocalDateTime       WPopupMenu                WSplitButton           WTime
WAudio                     WDateTime                  WHBoxLayout               WLocale              WPopupMenuItem            WSslCertificate        WTimeEdit
0
On

so use without extension:

#include <Wt/WApplication>
0
On

Try :

g++ -std=c++14 -o hello hello.cpp -I/usr/local/include/Wt -L/usr/local/lib64/

OR

g++ -std=c++14 -o hello hello.cpp -I/usr/local/include/Wt -L/usr/local/lib/