0

I am a newbie to C++. I want to use, lacewing-project.org in my C++ project. I read the documentation on how to build it and successfully did it using both DLL - Release and Static Library - Release configurations.

Now I don't know how to use this in my project and how to setup and configure my project? I was following this tutorial, but was stuck in the middle because of missing options in the latest Visual Studio. I use Visual C++ Expression Ed., 2012 on Windows 8

I googled and did the following:

  • Added the lib file and the lacewing.h file in my project.
  • Under Visual C++ Project Properties, in the Linker folder -> Input I added the lib file as Additional Dependencies.

I placed the dll in Windows\System32 folder. Will I need to do anything with the dll other than placing it in win32 folder?

My code is from the hello world example given in the documentation.

When I try to compile I get:

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 ==========

Please help...

James M
  • 18,506
  • 3
  • 48
  • 56
  • Which lib file did you add as an additional dependency? – James M Apr 08 '13 at 09:15
  • >The lib that was generated when lacewing-project was compiled using "Static Library - Release". No other libs other than that – Jayarathina Madharasan Apr 08 '13 at 14:16
  • > And the dll was the one that was generated when compiled with DLL - Release – Jayarathina Madharasan Apr 08 '13 at 14:27
  • If you compile the library statically, you need to `#define lw_import` before including `lacewing.h` to strip the function prototypes of `__declspec(dllimport)`. You won't need a DLL if you link statically. – James M Apr 08 '13 at 14:46
  • @JamesMcLaughlin I am really sorry to disturb you, but I think I am doing something wrong.. :( Adding `#define lw_import` line before `#include "lacewing.h"` gives me 31 unresolved externals http://i.imgur.com/WCqTZc4.jpg – Jayarathina Madharasan Apr 08 '13 at 15:19
  • @JamesMcLaughlin And just for your reference, the project properties: http://i.imgur.com/bxCPjaD.jpg – Jayarathina Madharasan Apr 08 '13 at 15:25
  • That's the library dependencies. Because you're linking statically, you'll need to link them in yourself (as of 0.5.1, that's `ws2_32.lib mswsock.lib mpr.lib secur32.lib crypt32.lib`). – James M Apr 08 '13 at 15:52
  • wow... that worked. Just that you know, these lib files are present in `C:\Program Files\Windows Kits\8.0\Lib\win8\um\x86` for x86 Windows 8 machine... I request you to post your replies as answer below. Thanks a lot for your time. I really appreciate it. And thanks for your wonderful product. – Jayarathina Madharasan Apr 08 '13 at 16:45
  • Done. Glad you got it working! – James M Apr 08 '13 at 17:15

1 Answers1

1

To link statically with the library, one must define lw_import. If you don't do this, it will default to __declspec(dllimport):

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

which causes the linker to try and pull the functions in from a DLL (which is wrong when statically linking). To do this, you can either add lw_import= to your preprocessor definitions in the project properties, or #define it before including lacewing.h, as so:

#define lw_import
#include <lacewing.h>

As you're statically linking the library, you will also need to link any library dependencies into your own project. You can find the list in the project properties of liblacewing.vcproj itself, but as of 0.5.1 these are ws2_32.lib, mswsock.lib, mpr.lib, secur32.lib and crypt32.lib.

James M
  • 18,506
  • 3
  • 48
  • 56
  • For those who are wondering where to get the lib files on Windows 8, they are present in `C:\Program Files\Windows Kits\8.0\Lib\win8\um\x86` more info on this here: http://stackoverflow.com/a/14778492/960641 – Jayarathina Madharasan Apr 08 '13 at 18:01