• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2569
  • Last Modified:

Compiling websocketpp example in Windows

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.
echo-server.cpp
WebSocketppCompileErrors.txt
0
anAppBuilder
Asked:
anAppBuilder
  • 2
  • 2
1 Solution
 
ambienceCommented:
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.
0
 
anAppBuilderAuthor Commented:
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++.
0
 
ambienceCommented:
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.
0
 
anAppBuilderAuthor Commented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now