Solved

Compiling websocketpp example in Windows

Posted on 2013-01-15
4
2,137 Views
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.
echo-server.cpp
WebSocketppCompileErrors.txt
0
Comment
Question by:anAppBuilder
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:ambience
Comment Utility
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
 

Author Comment

by:anAppBuilder
Comment Utility
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
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
Comment Utility
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
 

Author Comment

by:anAppBuilder
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now