How to compile curlpp with Windows?

Here's what I have done:
I have successfully compiled curl with MinGW from MSYS after a whole day messing stuff up.
Downloaded curlpp from https://github.com/jpbarrette/curlpp and extracted it.
Opened MSYS shell, cd to the folder, typed ./autogen.sh, ran without any error, then ./configure.
It stopped at "checking for boostlib >= 1.33.1... configure: error: We could not detect the boost libraries (version 1.33 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. ..."
So I spent another day trying to install boost. It was a hassle, but I am quite sure I got it installed properly. Here's what I did:
Downloaded boost from http://www.boost.org/
Followed http://www.boost.org/doc/libs/1_61_0/more/getting_started/windows.html (I do not have Visual Studio so I used gcc instead)
I haven't tested it yet but I'm pretty sure it's installed properly. So I run ./configure again. But it still shows the same error.
You'll probably have more luck with CMake and MinGW without using MSYS. Here's what worked on my Windows 10 64bit system using the default Windows command prompt:
0. install nuwen MinGW since it includes boost already: https://nuwen.net/mingw.html
1. add C:/MinGW/bin to your system PATH (or always use the console launchers)
2. install CMake: https://cmake.org/download/
3. download and extract the curl source zip: https://curl.haxx.se/download.html
4. build curl with cmake:
cd curl-7.50.1
mkdir build && cd build
cmake -G "MinGW Makefiles" .. -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
cmake --build . --target install
5. download and extract curlpp source code: https://github.com/jpbarrette/curlpp
6. Open curlpp's CMakeLists.txt and scroll to line 115 - add a # to the start of the lines for examples 13 and 14 - they have unconditional calls to *nix-only functions and the developer didn't even bother to make sure they worked on Windows.
7. build curlpp with cmake, pointing it at the curl installation:
cd curlpp-master
mkdir build && cd build
cmake -G "MinGW Makefiles" .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_CXX_FLAGS=-DBUILDING_CURLPP" -DCURL_INCLUDE_DIR=../../curl-7.50.1/install/include -DCURL_LIBRARY=../../curl-7.50.1/install/lib/libcurl_imp.lib
cmake --build .
Unfortunately I'm not sure how you're supposed to install curlpp because it doesn't have an install step for CMake. I also had to add that -DBUILDING_CURLPP hack because apparently the author forgot to add that to their CMake script, not to mention having to comment out examples 13 and 14. The project looks to be in shambles to me - it still uses auto_ptr and the "rewritten CMakeLists.txt" is pretty strange as far as CMakeLists.txt files go, not to mention the old unused subdirectory CMakeLists.txt are still there.

Either way, following the steps above got everything to build for me. Note that you may have to grab curl-7.50.1/install/bin/libcurl.dll and put it in the same directory as the example executables in order to run them. Alternatively you could install curl directly into your MinGW folder, e.g. -DCMAKE_INSTALL_PREFIX=C:/MinGW/

As for actually using curlpp, I have no idea. All I know is how to build it ;p
Last edited on
It seems I haven't had luck with boost yet. Followed your instruction without any problems, then at the very last instruction "cmake --build .", I get an error building example 18:
fatal error: boost/bind.hpp: No such file or directory
#include <boost/bind.hpp>
                                    ^
compilation terminated.


Edit: I'm sorry. I didn't read the nuwen MinGW install instruction thoroughly and I opened a normal command prompt instead of the one with the distro.
It compiles successfully now. I will test it.
Thanks a lot.
By thanks I mean I would never be able to compile it without some help from the Internet. I'm new to Windows programming and it's a shame that curlpp is not documented enough.
As a side question how do you figured out the steps above?
Last edited on
FallingStar wrote:
As a side question how do you figured out the steps above?
After spending many weeks trying to compile other people's code, I've learned where to look. I also use CMake with my own projects. Most projects that have a CMakeLists.txt will build fine, in my experience. Some, like this one, just need a little help.

For curl, I tried building without -DBUILD_TESTING=OFF and it encountered an error about a subdirectory not having a CMakeLists.txt file, so I opened the main CMakeLists.txt and looked for all the add_subdirectory commands, found the one that was causing the issue, and noticed that it was conditional on BUILD_TESTING, so I just turned it off :p

For curlpp, I had a lot of trouble - it uses CMake's built in FindCURL module which hasn't been updated in years unlike other find modules, so you have to pass both the include directory AND the path to the lib. I just looked at the source code in CMake's GitHub repository to find out the names of the variables I needed to set, but the naming convention is present in most find modules so I could have guessed.

That got it to configure, now I needed to build it - whenever it got to a linking step, it kept complaining about curlpp's own symbols being unresolved. Scrolling back up the build log I notice a lot of warnings about dllimport attributes, and I know what the issue is - typically libraries use a define to control whether the code is being exported to the DLL or imported from it so the same headers can be used for both compilation and user projects. I looked through the source code and found this:
https://github.com/jpbarrette/curlpp/blob/4632e2d58aa37d435dba071692668db146501bce/include/curlpp/internal/buildconfig.h#L31-L51
So I knew to fix it I had to set BUILDING_CURLPP during compilation. Fun fact, all the other project files (e.g. visual studio) do seem to properly set this flag, so they only forgot in the CMake scripts.

After that it mostly worked and then those two examples I told you to comment out failed to build, so I just hand-edited the CMakeLists.txt in that case to not build them - they're just examples and you can read their source and fix the portability issues yourself I assume. Generally though I try to avoid editing files by hand at all costs - in this case it was necessary.

Welcome to Windows programming, where developers often only test their code on *nix and say that it should work 'in theory' on Windows. Sometimes you have to apply elbow grease ;)
Last edited on
That seems like a lot of experience. Guess I have to spend time then.
I'm trying to compile example00. When I run the compiled example00.exe, they indeed run (after copying the dll into the folder), but when I try to compile myself, I get a bunch of
undefined reference to '_imp__ZN6curlpp7CleanupC1Ev'
undefined reference to '_imp__ZN6curlpp4EasyC1Ev'

and so on.
I use Codeblocks IDE.
When I first compile curl example by myself, I also get the same errors. But when I add libcurl.dll.a to the project's linker settings, it is fixed. This time I tried to add curlpp-master/build/libcurlpp.dll.a to the project's linker settings, but the problems persists.

Edit: I just try to compile curl-only example and the same problem pop up. It seems that there is no libcurl.dll.a when I compile with your instructions. Adding libcurl_imp.lib does not fix the problem.
Last edited on
libcurl_imp.lib is just a renamed libcurl.dll.a, not sure why they chose to do it that way.

Be aware that linking order matters - you need both of libcurl_imp.a and libcurlpp.dll.a but if one order results in linker errors then try swapping them around.

EDIT: You may not need curl since curlpp is built as shared, actually. Not sure why you're getting those errors though.
Last edited on
Okay so I'm trying to compile curl example. I got it to work in the command line with this command (CMess is the name of my project)
gcc main.c -L..\..\CMess\curl-7.50.1\build\lib -I..\..\CMess\curl-7.50.1\install\include -lcurl

But still not in the IDE.
I wonder why I don't need to link to any specific file when I compile in the command prompt and it still works? And what does -lcurl do and how do I recreate such behaviour in the IDE?
Last edited on
FallingStar wrote:
I wonder why I don't need to link to any specific file when I compile in the command prompt and it still works? And what does -lcurl do and how do I recreate such behaviour in the IDE?
-lcurl is the specific file you are linking.
-L..\..\CMess\curl-7.50.1\build\lib
tells GCC where to look for libraries and -lcurl tells GCC to link a library named curl. It looks for a file named libcurl.a - in an IDE generally you'd just need to give it the full path to the file.

I'm not fully sure why -lcurl worked for you and not -lcurl_imp - did you rename the library file or something? I'm also not sure why you didn't need -lcurlpp
Last edited on
As I said before I'm testing curl, not curlpp.
It seems that my IDE can not properly link the .lib file. I tried to add -lcurl to linker options and it said:
libcurl.dll: file not recognized: File format not recognized

So I thought that it is linking to the wrong file: the .dll one instead of the .lib. So I did some searching and add -static. It now says cannot find -lcurl.
I also found this:
mingw32-gcc.exe -Wall -O2 -I..\..\CMess\curl-7.50.1\include -c main.c -o obj\Release\main.o
mingw32-g++.exe -L..\..\CMess\curl-7.50.1\build\lib -o bin\Release\curltest2.exe obj\Release\main.o  -lcurl -s 

It's using g++ instead of gcc. Is that a problem? I don't get why it tries to use g++.

Edit: Okay I just figure out mine looks like this: http://i.stack.imgur.com/PPGUM.jpg
Edit2: I don't think that's the problem because libcurlpp.dll.a links just fine. The problem must be linking libcurl_imp.lib. Renaming it doesn't work.
Last edited on
You have to use the same compiler to compile curl as you do with your own code. So, since you compiled curl with nuwen MinGW, you have to also compile your own project with nuwen MinGW and/or tell your IDE how to use nuwen MinGW.

If you don't want to use nuwen MinGW, my instructions should also work with other compilers on your system as long as you tell CMake how to use them, e.g.
-DCMAKE_C_COMPILER=mingw32-gcc.exe -DCMAKE_CXX_COMPILER=mingw32-g++.exe
Wow that works like a charm! I added nuwen MinGW as a compiler to my IDE and it works now. I also get why it works in a normal command prompt: because I have C:\MinGW\bin in my PATH so calling gcc/g++ from the command line would call gcc/g++ from nuwen.
If I come up with a question later (which will happen because I'm learning) I will ask it on the forum.
I've figured out and learnt so many things throughout this!
Thank you for all your assistance.
closed account (48bpfSEw)
clang seems to support the last release of C++.

Therefor I am trying to get the compiler run on my windows system.
I found recently this site which explains accurately the steps for installation on windows or an unix system:

http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt3/

Topic archived. No new replies allowed.