Building Hiredis-2.8 in Visual Studio 2013
A checklist for the frustrated beginner Redis is a technology I'm only just beginning to use. If you don't know what it does, I question A) why you're reading this and by extension B) what you're doing with your life by even reading this blog. Seriously, get off the internet and go outside. If these questions have sent you spiralling into some sort of existential maelstrom, know that Redis provides an in-memory database which is very fast and very useful for inter-process communication. The possibilities are almost endless, and I am quite excited to start exploring them. Hiredis ( https://github.com/redis/hiredis ) is a reasonably stable C++ client written to access such a database. The developers have provided a Visual Studio solution which can be built with very little issue. However, as is the way with such things, linking it to another project can cause some headaches. I encountered several headaches when linking the project, but made a breakthrough right after being pleasantly distracted - so if all else fails, distract yourself for a while. It helps. I hope that going through the following checklist will alleviate this pain:
Firstly, coordinate your Platform Toolset. I am using v120_xp across all the projects, because it will run on our industrial hardware which runs XP. Make sure you change this for Win32_Interop, hiredis, and your project.
For your project, the hiredis project, and the Win32_Interop project, check that Properties->C/C++->Code Generation->Runtime Library is set to the same across all. I tested with /MTd and /MDd, both were fine as long as they matched between the calling project, the hiredis project, and the Win32_Interop project which hiredis uses for it's wrapped Winsock functions. This will resolve many linking errors that you might be seeing.
Ensure that hiredis is linked to Win32_Interop.lib - you can do this in Properties->Librarian->General->Additional Dependencies. Add the full path of your Win32_Interop.lib file. Mine was c:\dev\redis-2.8\msvs\Debug\Win32_Interop.lib, so be sure to link it properly otherwise you'll get a few linking errors from networking funtions such as socket, bind, fcntl, etc. I did not try linking with a pragma comment, so if you prefer the readability of this then try it out for yourself.
For your project, make sure you are using Multi-Byte Character Set - hiredis and Win32_Interop use these by default. If you're combining with MFC, you'll notice that MBCS was deprecated in VS2013. Check the link in the article here ( http://blogs.msdn.com/b/vcblog/archive/2013/07/08/mfc-support-for-mbcs-deprecated-in-visual-studio-2013.aspx ) which gives you a download for these.
In your project's Properties->C/C++->General->Additional Include Directories, add a path to the redis src directory amd the deps/hiredis directory. Mine were, respectively, c:\dev\redis-2.8\src and c:\dev\redis-2.8\deps\hiredis
In your main.cpp file, include "hiredis.h" before anything else. Windows has a funny habit of being quite fussy about the order of includes, so this is just something we all have to live with.
Link with hiredis.lib - you can do this as a #pragma comment(lib, "c:\your_redis_msvs_output_path\hiredis.lib") or in the linker, whichever you prefer.
This should solve the majority of confusing build errors. To properly test, run a default redis-server (the path to which may be something like c:\dev\redis-2.8\msvs\Debug\redis-server) and write a test program. This need not be anything more than creating a pointer to a redisContext and initialising it with the function redisConnect("127.0.0.1", 6379) and then pinging the server with redisReply *myRedisReply = (redisReply*)redisCommand(myRedisContext, "PING"); You can get the result of the ping (which should be "PONG") by looking in the str member of the redisReply object. That's it! If there are any other beginner errors that would be useful to list, contact me and I'll add them.
Edit: Some additional steps for building hiredis into a project:
You may need to add external files into the project from the src folder. Use extern "C" { ... } to wrap the #include-d redis headers, otherwise you'll get more unresolved external symbols. Then just add the existing files into your project. Make sure you #include files from the redis-2.8\deps\hiredis folder, and add files from the redis-2.8\src folder.
You also need to link against Win32_Interop.lib in your project, not just the hiredis one.












