如何使用草地项目

时间:2013-04-07 15:47:01

标签: c++ visual-c++ dll shared-libraries liblacewing

我是C ++的新手。我想在我的C ++项目中使用lacewing-project.org。我阅读了有关如何构建它的文档,并使用DLL - ReleaseStatic Library - Release配置成功完成了它。

现在我不知道如何在我的项目中使用它以及如何设置和配置我的项目?我正在关注this tutorial,但由于最新的Visual Studio中缺少选项而被卡在中间。我在Windows 8上使用Visual C ++ Expression Ed。,2012

我用Google搜索并执行了以下操作:

  • 在我的项目中添加了lib文件和lacewing.h文件。
  • 在Visual C ++项目属性下,在Linker文件夹中 - >输入我将lib文件添加为Additional Dependencies。

我将dll放在Windows \ System32文件夹中。除了将它放在win32文件夹中之外,我是否需要对dll做任何事情?

我的代码来自文档中提供的hello world example

当我尝试编译时,我得到:

1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>  Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol __imp__lw_version referenced in function "void __cdecl on_get(struct lacewing::_webserver *,struct lacewing::_webserver_request *)" (?on_get@@YAXPAU_webserver@lacewing@@PAU_webserver_request@2@@Z)
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl lacewing::pump_delete(struct lacewing::_pump *)" (__imp_?pump_delete@lacewing@@YAXPAU_pump@1@@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct lacewing::_error * __thiscall lacewing::_eventpump::start_eventloop(void)" (__imp_?start_eventloop@_eventpump@lacewing@@QAEPAU_error@2@XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct lacewing::_eventpump * __cdecl lacewing::eventpump_new(void)" (__imp_?eventpump_new@lacewing@@YAPAU_eventpump@1@XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl lacewing::_stream::writef(char const *,...)" (__imp_?writef@_stream@lacewing@@QAAXPBDZZ) referenced in function "void __cdecl on_get(struct lacewing::_webserver *,struct lacewing::_webserver_request *)" (?on_get@@YAXPAU_webserver@lacewing@@PAU_webserver_request@2@@Z)
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall lacewing::_webserver::host(long)" (__imp_?host@_webserver@lacewing@@QAEXJ@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall lacewing::_webserver::on_get(void (__cdecl*)(struct lacewing::_webserver *,struct lacewing::_webserver_request *))" (__imp_?on_get@_webserver@lacewing@@QAEXP6AXPAU12@PAU_webserver_request@2@@Z@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct lacewing::_webserver * __cdecl lacewing::webserver_new(struct lacewing::_pump *)" (__imp_?webserver_new@lacewing@@YAPAU_webserver@1@PAU_pump@1@@Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl lacewing::webserver_delete(struct lacewing::_webserver *)" (__imp_?webserver_delete@lacewing@@YAXPAU_webserver@1@@Z) referenced in function _main
1>C:\Users\Jayarathina\Desktop\New folder (3)\test\Debug\test.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

请帮忙......

1 个答案:

答案 0 :(得分:1)

要静态链接库,必须定义lw_import。如果您不这样做,它将默认为__declspec(dllimport)

#ifndef lw_import
   #define lw_import __declspec (dllimport)
#endif

导致链接器尝试从DLL中提取函数(静态链接时出错)。为此,您可以将lw_import=添加到项目属性中的预处理器定义,或#define之前添加lacewing.h,如下所示:

#define lw_import
#include <lacewing.h>

当您静态链接库时,您还需要将任何库依赖项链接到您自己的项目中。您可以在liblacewing.vcproj本身的项目属性中找到该列表,但从0.5.1开始,这些列表为ws2_32.libmswsock.libmpr.libsecur32.lib和{ {1}}。