Need help importing httplib

Pages: 12
Hi, so I want to #include "./httplib.h", but it always tells me that 'openssl/err.h': No such file or directory

I've tried adding the argument "/I C://Program Files (x86)//OpenSSL-Win32//include//openssl" to my compiler, but no luck.

What am I doing wrong?


I'm using: cl.exe as the compiler on Windows 10
Last edited on
How about:

/I "C:\\Program Files (x86)\\OpenSSL-Win32\\include"

Note that the quoted portion doesn't include the /I at the beginning.
And the slashes in the filename are backslashes.
Also, I think it should just go up to include (but maybe you do need the openssl part, too).
Last edited on
Same error :(
source file cannot be opened (error code "openssl/err.h") (dependency of "C:\Users\Downloads\helloworld\httplib.h").
Last edited on
I don't use Windows so I don't really know what I'm talking about here.
However, try:

/I "C:\Program Files\OpenSSL-Win64\"

If that doesn't work, try exactly:

/I "C:\Program Files (x86)\OpenSSL-Win32\include\"
Last edited on
No problem man! Any help is REALLY appreciated here, I've been trying to tackle on this for days on end now.

When I just import OpenSSL-Win64, I get this error:
'plus\projects\helloworld\requests_try.cpp': No such file or directory


When I include the include, I get the same old error.
Full command here:
cl.exe /std:c++17 /I "C:\Program Files\OpenSSL-Win64\" /permissive- /utf-8 /Zi /EHsc /nologo /Fe: "C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.exe" "C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp"

My tasks .json file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
	"version": "2.0.0",
	"tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe compilar archivo activo",
            "command": "cl.exe",
            "args": [
                "/std:c++17",
                "/I",
                "C:\\Program Files\\OpenSSL-Win64\\",
                "/permissive-",
                "/utf-8",
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compilador: cl.exe"
        }
    ]
}

Hello ErikDz,

When I have had this problem I use Windows "File Explorer" to find the file that I need. Then in the "Address Bar" when you click on in the "address Bar" it will change to the full path of where the file is located.

I just copy that and add the file name at the end.

Windows will use the back slash, which will need to be escaped if you use it. "C:\\Program Files (x86)\\OpenSSL-Win32\\include" as in dutch's example. Or you can use the forward slash. Either will work.

Once you get it working you may want to save the path somewhere for future use.

You said that you are using Windows 10, but neglected to mention what IDE you are using.

Andy
Hi Andy,
Apologies for not mentioning my IDE. It is VSCode.

The way you said of copying what appeared on the address bar was what I was doing all along.

When I have the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
	"version": "2.0.0",
	"tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe compilar archivo activo",
            "command": "cl.exe",
            "args": [
                "/std:c++17",
                "/I",
                "C:\\Program Files\\OpenSSL-Win64\\include",
                "/permissive-",
                "/utf-8",
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compilador: cl.exe"
        }
    ]
}


I get the same error as in the beggining.

ErikDz
Hello ErikDz,

Although I have VS Code on my computer I am not that familiar with it or even how it works.

What you referred to as a ".json" file looks very similar to a "make File". Neither of which I use often enough to fully understand it.

I do not know if it would help, but a ".json" file that works to compare to what you have posted and I might see something that is different.

Andy
It looks like a configuration file (not much like a makefile).
And I spot some lengua española in there!

So does C:\\Program Files\\OpenSSL-Win64\\include exist?
Does it have openssl/err.h in it?
How about C:\\Program Files (x86)\\OpenSSL-Win32\\include?
Hi dutch,

You're right, Im from Spain! :D

C:\\Program Files\\OpenSSL-Win64\\include
does exist indeed. I tried compiling with
C:\\Program Files (x86)\\OpenSSL-Win32\\include


and I got a different error (at least we're getting somewhere xD):
1
2
3
4
5
6
7
8
9
10
11
12
13
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(5): note: vea la declaraci�n de 'cli'
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(11): error C3927: "->": no se admite el tipo de valor devuelto final despu�s de un declarador que no es de funci�n
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(11): error C3613: falta el tipo de devoluci�n despu�s de '->' (se presupone 'int')
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(11): error C4430: falta el especificador de tipo; se presupone int. Nota: C++ no admite default-int
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(11): error C2371: 'res': nueva definici�n; tipos b�sicos distintos
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(10): note: vea la declaraci�n de 'res'
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(11): error C2146: error de sintaxis: falta ';' delante del identificador 'status'
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(12): error C3927: "->": no se admite el tipo de valor devuelto final despu�s de un declarador que no es de funci�n
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(12): error C3613: falta el tipo de devoluci�n despu�s de '->' (se presupone 'int')
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(12): error C4430: falta el especificador de tipo; se presupone int. Nota: C++ no admite default-int
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(12): error C2371: 'res': nueva definici�n; tipos b�sicos distintos
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(10): note: vea la declaraci�n de 'res'
C:\Users\erikd\Downloads\PityPiton\experimentos\C plus plus\projects\helloworld\requests_try.cpp(12): error C2146: error de sintaxis: falta ';' delante del identificador 'bod 
Hi Andy,

The
task.json
file works perfectly with any other program (which doesnt include httplib)

ErikDz
Those look like errors you should be able to fix.
If not, upload the file somewhere and I'll look at it.
Hi dutch,

What I'm using is a copy+paste of the example on the official github for httplib

1
2
3
4
5
6
7
8
9
10
11
12
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "./httplib.h"

// HTTP
httplib::Client cli("http://cpp-httplib-server.yhirose.repl.co");

// HTTPS
httplib::Client cli("https://cpp-httplib-server.yhirose.repl.co");

auto res = cli.Get("/hi");
res->status;
res->body;
You don't know c++, do you!
That's not a program.
There's no main.
cli is defined twice. You need to pick one or the other.
Simply mentioning res->status and res->body isn't going to do anything.

This should compile, although it's just the client so unless they keep a server for it running at the given address (which is possible) it won't do anything. You may need to add that initial define.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "./httplib.h"

int main() {
  httplib::Client cli("http://cpp-httplib-server.yhirose.repl.co");
  
  auto res = cli.Get("/hi");

  if (res) {
    std::cout << res->status << std::endl;
    std::cout << res->body << std::endl;
  }
}

Oh I can't believe that was it!
I started with C++ about a week ago. I come from 4yrs with python so all of this is pretty new to me.

Thank you very much dutch, definitely saved me from a massive headache!

:D
It just threw me another error:

Unable to open 'mutex.cpp': Unable to read file 'd:\agent\_work\57\s\src\vctools\crt\github\stl\src\mutex.cpp' (Error: Unable to resolve non-existing file 'd:\agent\_work\57\s\src\vctools\crt\github\stl\src\mutex.cpp').
I'm assuming that you don't have a drive D (or do you?), let alone a directory called \agent\_work\57\....

Do you know where that mutex.cpp file is on your disk? If so, you can maybe add something like this to your json file (changing \Your\Path\To\It\ with the proper location):

"sourceFileMap": {
   "d:\agent\_work\57\s\src\vctools\crt\github\stl\src": "C:\Your\Path\To\It\src"
}

I do have a D drive. But I'm unaware of where mutex.cpp is. Is it also a library like httplib?
Last edited on
That path, d:\agent..., is what was used to build the libraries originally on Microsoft's end.

Is this an error you can ignore, or does it actually prevent you from doing what you need to do?

Here is a StackOverflow post that also discusses this issue, although it doesn't have a lot of attention:
https://stackoverflow.com/questions/60472084/vscode-unable-to-open-file-unable-to-read-file-message-when-clicking-on-an
Last edited on
It stops me from compiling my program
Pages: 12