Search code examples
cwindowslibevent

cannot build libevent on windows


So I have been trying to build libevent on Windows. However, it keeps giving me the following output when I run nmake MakeFile.nmake...

        cl /IWIN32-Code /IWIN32-Code/nmake /Iinclude /Icompat /DHAVE_CONFIG_H /I.  
/Ox /W3 /wd4996 /nologo /c event.c buffer.c bufferevent.c bufferevent_sock.c bufferevent_pair.c 
listener.c evmap.c log.c evutil.c strlcpy.c signal.c bufferevent_filter.c evthread.c bufferevent_ratelim.c 
evutil_rand.c evutil_time.c win32select.c evthread_win32.c buffer_iocp.c event_iocp.c bufferevent_async.c 
event.c
event.c(31): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
buffer.c
buffer.c(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
bufferevent.c
bufferevent.c(31): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
bufferevent_sock.c
bufferevent_sock.c(32): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
bufferevent_pair.c
bufferevent_pair.c(29): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
listener.c
listener.c(30): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
evmap.c
evmap.c(30): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
log.c
log.c(44): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
evutil.c
evutil.c(31): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
strlcpy.c
strlcpy.c(37): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
signal.c
signal.c(34): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
bufferevent_filter.c
bufferevent_filter.c(31): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
evthread.c
evthread.c(34): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory
bufferevent_ratelim.c
bufferevent_ratelim.c(30): fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
evutil_rand.c
evutil_rand.c(38): fatal error C1083: Cannot open include file: 'limits.h': No such file or directory
evutil_time.c
evutil_time.c(31): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
win32select.c
win32select.c(33): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
evthread_win32.c
evthread_win32.c(34): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
buffer_iocp.c
include\event2/buffer.h(82): fatal error C1083: Cannot open include file: 'stdarg.h': No such file or directory
event_iocp.c
event_iocp.c(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
Generating Code...
Compiling...
bufferevent_async.c
bufferevent_async.c(36): fatal error C1083: Cannot open include file: 'errno.h': No such file or directory
Generating Code...
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0
\VC\bin\cl.EXE"' : return code '0x2'
Stop.

It seems as if it cannot find certain files. So I found the directory where winsock2.h and other files were located and added a environment variable to those files but I still get the same error. I also noticed that I could not actually find sys/types.h and limits.h on my system. I would really appreciate if someone could help figure out what is causing this issue. thanks.

Update: So I have determined where all of the files needed on my system are and I have tried adding an environment variable to the appropriate directories, however, they still cannot be found when I run nmake.


Solution

  • The libevent README.md file does not suggest using nmake. It points you to using CMake and the existing Makefile.nmake has a big comment at the top suggesting it might not work. So install cmake (you can use Chocolatey 'choco install cmake') then run the commands as documented.

    mkdir build
    cmake -DEVENT__DISABLE_OPENSSL=ON ..
    cmake --build .
    

    This worked for me using Visual Studio 2017 with the git checkout of branch release-2.1.8-stable. I added the disable-openssl option as it failed without this and I didn't want to spend time installing that separately.