Issue compiling hello world on Wt
I try to compile a hello world like application using Wt but have problems to link
I use Qt creator and mingw32
as compiler
what am I doing wrong ? Any help will be appreciated
The process "C:/MinGW32/bin/mingw32-make.exe" exited normally.
Configuration unchanged, skipping qmake step.
Starting: "C:/MinGW32/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Wt/HelloWt-build-desktop'
C:/MinGW32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Wt/HelloWt-build-desktop'
g++ -c -DNDEBUG -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -D__MINGW32__ -D_WIN32 -DQT_DLL -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I'../../Qt/2010.05/qt/include/QtCore' -I'../../Qt/2010.05/qt/include/QtNetwork' -I'../../Qt/2010.05/qt/include' -I'../../Wt2/Include' -I'../../boost/include/boost-1_45' -I'../../Qt/2010.05/qt/include/ActiveQt' -I'debug' -I'../../WtTest/HelloWt' -I'.' -I'../../Qt/2010.05/qt/mkspecs/win32-g++' -o debug/main.o ../../WtTest/HelloWt/main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug/HelloWt.exe debug/main.o -L'c:/Qt/2010.05/qt/lib' C:\Wt2\lib\libwt.a C:\Wt2\lib\libwthttp.a C:\QtSDK\mingw\lib\libws2_32.a C:\QtSDK\mingw\lib\libwsock32.a C:\boost\lib\libboost_thread-mgw45-mt-d-1_45.a C:\boost\lib\libboost_regex-mgw45-mt-d-1_45.a C:\boost\lib\libboost_date_time-mgw45-mt-d-1_45.a C:\boost\lib\libboost_signals-mgw45-mt-d-1_45.a C:\boost\lib\libboost_system-mgw45-mt-d-1_45.a C:\boost\lib\libboost_program_options-mgw45-mt-d-1_45.a C:\boost\lib\libboost_filesystem-mgw45-mt-d-1_45.a -lQtNetworkd4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Wt/HelloWt-build-desktop'
mingw32-make: Leaving directory `C:/Wt/HelloWt-build-desktop'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `WServer':
C:/wt-3.1.9/src/http/WServer.C:142: undefined reference to `Wt::WAbstractServer::instance_'
C:/wt-3.1.9/src/http/WServer.C:140: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~WServer':
C:/wt-3.1.9/src/http/WServer.C:145: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~WServer':
C:/wt-3.1.9/src/http/WServer.C:145: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(HTTPStream.obj): In function `HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.C:17: undefined reference to `Wt::WebStream::WebStream(bool)'
C:\Wt2\lib\libwthttp.a(HTTPStream.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug/HelloWt.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/MinGW32/bin/mingw32-make.exe" exited with code %2.
Error while building project 开发者_JS百科HelloWt (target: Desktop)
When executing build step 'Make'
Here is the source
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <boost/version.hpp>
using namespace Wt;
/*
* A simple hello world application class which demonstrates how to react
* to events, read input, and give feed-back.
*/
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);
private:
WLineEdit *nameEdit_;
WText *greeting_;
void greet();
};
/*
* The env argument contains information about the new session, and
* the initial request. It must be passed to the WApplication
* constructor so it is typically also an argument for your custom
* application constructor.
*/
HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
setTitle("Hello world"); // application title
root()->addWidget(new WText("Your name, please ? ")); // show some text
nameEdit_ = new WLineEdit(root()); // allow text input
nameEdit_->setFocus(); // give focus
WPushButton *b = new WPushButton("Greet me.", root()); // create a button
b->setMargin(5, Left); // add 5 pixels margin
root()->addWidget(new WBreak()); // insert a line break
greeting_ = new WText(root()); // empty text
/*
* Connect signals with slots
*
* - simple Wt-way
*/
b->clicked().connect(this, &HelloApplication::greet);
/*
* - using an arbitrary function object (binding values with boost::bind())
*/
nameEdit_->enterPressed().connect
(boost::bind(&HelloApplication::greet, this));
}
void HelloApplication::greet()
{
/*
* Update the text, using text input into the nameEdit_ field.
*/
greeting_->setText("Hello there, " + nameEdit_->text());
}
WApplication *createApplication(const WEnvironment& env)
{
/*
* You could read information from the environment to decide whether
* the user has permission to start a new application
*/
return new HelloApplication(env);
}
int main(int argc, char **argv)
{
/*
* Your main method may set up some shared resources, but should then
* start the server application (FastCGI or httpd) that starts listening
* for requests, and handles all of the application life cycles.
*
* The last argument to WRun specifies the function that will instantiate
* new application objects. That function is executed when a new user surfs
* to the Wt application, and after the library has negotiated browser
* support. The function should return a newly instantiated application
* object.
*/
return WRun(argc, argv, &createApplication);
}
You may need to reverse the order of libwt.a and libwthttp.a on your command line. The order of arguments sometimes matters to the GNU linker.
You are trying to link you application with QtCore, QtNetwork and ActiveQt libraries, and not with Wt libraries.
As far as I can see you are unsing qmake and then make. If you do, check you project configuration file, and compare with Hello World example of Wt used with qmake:
QT -= core
QT -= gui
TARGET = CppHelloWtQtCreatorUbuntu
LIBS += -L/usr/lib -lwt -lwthttp
QMAKE_CXXFLAGS += -DNDEBUG
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
wittyapplication.cpp
HEADERS += \
wittyapplication.h
As you can see here, all linking with Qt libraries are removed and added wt and wthttp (to have binary witch is a standalone webserver) libs. Also make shure you have Wt header files accesible via INCLUDE enviroment variable and Wt libraries are acessibe via PATH enviroment variable.
精彩评论