在 Wt 上编译 hello world 时出现问题

发布于 2024-11-18 05:10:03 字数 6238 浏览 1 评论 0原文

我尝试使用 Wt 编译一个类似 hello world 的应用程序,但链接时遇到问题 我使用 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);
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽月 2024-11-25 05:10:03

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

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.

女中豪杰 2024-11-25 05:10:03

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

据我所知,你正在取消 qmake 然后 make 。
如果这样做,请检查项目配置文件,并与 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(拥有二进制女巫是一个独立的网络服务器)库。
还要确保您可以通过 INCLUDE 环境变量访问 Wt 头文件,并且可以通过 PATH 环境变量访问 Wt 库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文