Compiling websocketpp example in Windows

Posted on 2013-01-15
Medium Priority
Last Modified: 2013-01-17
I am experimenting with websockets and trying to compile the websocketpp echo server example in VisualStudio C++ 2010 Express.

I'm getting 49 unresolved externals, so I'm missing something, probably something obvious.  I'm relatively new to C++, but have a project coming up that will require a C++ websocket server.

I have attached the example source file (with my edits to add the boost libs) and a file showing my errors.
Question by:anAppBuilder
  • 2
  • 2
LVL 23

Expert Comment

ID: 38783371
I think what you are missing is building the lib from sources: https://github.com/zaphoyd/websocketpp/tree/master/src

and linking it to the example.

Author Comment

ID: 38785376
Thank you, ambience.  

I didn't think I would need to do that.  Per https://github.com/zaphoyd/websocketpp/wiki/Building-a-program-with-websocketpp:

"As WebSocket++ is a header only library all that is necessary to include it in your program is to include the WebSocket++ repository directory in your include path..."

But if I need to, could you please point me to something that will tell me how to do that?  I come from php and VBA land and am just learning this "compile and build it all yourself" world of C++.
LVL 23

Accepted Solution

ambience earned 2000 total points
ID: 38786959
Well, I dont understand why the documentation says so, clearly there are cpp files in the repository and take these errors for example

1>echo_server.obj : error LNK2019: unresolved external symbol "public: bool __thiscall websocketpp::SHA1::Result(unsigned int *)" (?Result@SHA1@websocketpp@@QAE_NPAI@Z) referenced in function

This method is defined in sha1.cpp file, so there are only two ways 1) include all the sources in your project (bad) 2) Make a lib and link to it.

This document http://msdn.microsoft.com/en-us/library/vstudio/ms235627%28v=vs.100%29.aspx details how to build static libs in general. But in your case, since the project does not provide any Visual Studio project files you may do it like

1) Create a static lib project in VS (empty).
1b) Try to have the project file named websocketpp and created at the root of the websocketpp folder. You can even close VS manually move it there and open from there. This step is only for convenience and convention.

2) In solution explorer, select websocketpp project and enable "Show All Files". Select all hpp, cpp files and folders and select Include in project.
2b) OR you can use Add Item (Existing) to achieve the same.

3) Build the project. It would produce websocketpp.lib

4) In your websocket server, goto Linker settings and add the werbsocketpp.lib to additional libraries. You may need to also add the path to lib in library in additional include folders.

The MSDN article would help you because it details these steps minutely.

Author Comment

ID: 38791346
Thank you again, ambien, both for a very helpful comment and the reference.  Clear and easy to follow.

Here are some notes for the next person:

1) When I first tried to build the library I got errors like this:
d:\users\MyComputer\documents\visual studio 2010\projects\libraries\websocketpp\websocketpp\websocketpp\shacmp.cpp(61): error C2065: 'SHA1' : undeclared identifier
To fix this, in each sha code file I had to add
     using websocketpp::SHA1;

2) Here are the linker settings needed in properties:
Linker>General>Additional Library Directories  full path to dir cointaining static library
Linker>Input>Additional Dependencies  full path to the library itself

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In a question here at Experts Exchange, a member was looking for "a little app that would allow sound to be turned OFF and ON by simply clicking on an icon in the system tray". This article shows how to achieve that, as well as providing the same OF…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question