问题在Wt编译你好世界

时间:2011-07-02 15:37:26

标签: wt

我尝试使用Wt编译一个像应用程序一样的hello世界,但是链接有问题 我使用Qt creator和mingw32作为编译器

我做错了什么?任何帮助将不胜感激

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 HelloWt (target: Desktop)
When executing build step 'Make'

这是来源

#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);
}

2 个答案:

答案 0 :(得分:1)

您可能需要在命令行上颠倒libwt.a和libwthttp.a的顺序。参数的顺序有时对GNU链接器很重要。

答案 1 :(得分:0)

您正在尝试将应用程序与QtCore,QtNetwork和ActiveQt库链接,而不是与Wt库链接。

据我所知,你正在取消qmake然后制作。 如果这样做,请检查项目配置文件,并与用于qmake的Wt的Hello World示例进行比较:

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

正如您在此处所看到的,所有与Qt库的链接都被删除并添加了wt和wthttp(以使二进制女巫是一个独立的Web服务器)库。 另外,你可以通过INCLUDE环境变量访问Wt头文件,并通过PATH环境变量获取Wt库。