Solved

Compiling websocketpp example in Windows

Posted on 2013-01-15
4
2,344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:ambience
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.
0
 

Author Comment

by:anAppBuilder
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++.
0
 
LVL 22

Accepted Solution

by:
ambience earned 500 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.
0
 

Author Comment

by:anAppBuilder
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

687 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