4

Trying to build apr 1.7 on Windows with Visual Studio, tried 2017 and 2013.

When building the project (Debug|x86) or compiling e.g. dso.c if get the following error message:

1>dso.c
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing ')' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing '{' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ')'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2061: syntax error: identifier 'apr_winapi_pfn_if_indextoname'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ';'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2513: ' ': no variable declared before '='
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2065: 'apr_winapi_pfn_if_indextoname': undeclared identifier
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4047: '=': 'int' differs in levels of indirection from 'int *(__cdecl *)(NET_IFINDEX,PCHAR)'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2146: syntax error: missing ';' before identifier 'apr_load_dll_func'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2100: illegal indirection
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2064: term does not evaluate to a function taking 1207 arguments
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4033: 'apr_winapi_if_indextoname' must return a value

I have succesfully build version 1.65 (after apply the hint from http://letcoderock.blogspot.com/2017/09/build-log4cxx-trunk-on-windows-by.html or Apache Cross Compilation Error ./gen_test_char: cannot execute binary file)

Comparing apr_arch_misc.h of the two version, i have noticed DLL_IPHLPAPI was new to the enum apr_dlltoken_e and Intelisense was complaining about

APR_DECLARE_LATE_DLL_FUNC(DLL_IPHLPAPI, PCHAR, NETIOAPI_API_, if_indextoname, 0, (
    NET_IFINDEX InterfaceIndex,
    PCHAR       InterfaceName),
    (InterfaceIndex, InterfaceName));

with "expecting a ')'". If have changed NETIOAPI_API_ to WINAPI. Do not know if this is correct but the file could now be compiled (after running the above trick with gen_test_char.exe).

But after that I ran into the next Problem:

1>sockaddr.c
1>network_io\unix\sockaddr.c(144): error C2065: 'IF_NAMESIZE': undeclared identifier
1>network_io\unix\sockaddr.c(144): error C2057: expected constant expression
1>network_io\unix\sockaddr.c(144): error C2466: cannot allocate an array of constant size 0
1>network_io\unix\sockaddr.c(144): error C2133: 'scbuf': unknown size
1>network_io\unix\sockaddr.c(1274): error C2065: 'IF_NAMESIZE': undeclared identifier

I have succesfully build apr with gcc in linux/cygwin. I have looked into the the preprocessor substitutions for IF_NAMESIZE and here it is replaced by 44. But I can not find the definiton or where this is set.

Does anyone have an idea how to fix this? And is the above change to WINAPI correct?

Andre
  • 147
  • 11

3 Answers3

4

Just use cmake to build the Visual Studio Solution:

With

cmake -G "Visual Studio 15 2017" -A x64

the .sln ist properly set up and building the solution works with no errors. Even gen_test_char.exe is build.

Maybe the apr project should make the cmake building instructions a little bit more prominent on their site.

Andre
  • 147
  • 11
  • 2
    The amount of time that gets wasted because of this kind of stuff... I've been building APR with nmake for years and then suddenly, poof, nope can't do that no more. I mean, just remove the references to Makefile.win if it's no longer supported. – deltamind106 Jan 08 '20 at 17:02
  • 1
    Thank you. I spent hours on their useless outdated instructions before stumbling upon this. It seems the cmake route is the one they maintain, but it is mentioned essentially as an afterthought at the bottom of the page of instructions on how to do it the other ways (that don't work). I adapted the answer to VS 2019: cmake -G "Visual Studio 16 2019" -A x64 – Jimbo1987 Feb 02 '22 at 20:33
  • How does one modify this for VS2019 x85 architecture? cmake -G "Visual Studio 16 2019" -A x64 is working for 63-bit, but cmake -G "Visual Studio 16 2019" -A x86 errors out. – Sam Carleton Feb 13 '22 at 18:20
4

As written in README file:

Note you must manually modify the include\apr.hw file before you build to change default options

So i just removed line #define _WIN32_WINNT 0x0501 from apr-1.7.0\include\apr.hw and run nmake -f Makefile.win. Worked fine for me. VS2017 tools, Windows 10.

Quinto
  • 41
  • 2
3

In case someone else also runs into this problem: I was using cmake + nmake to build APR, but it still didn't work for me.

The reason was that I had old compilation flags to support Windows XP:

cmake -DMIN_WINDOWS_VER=0x0501 ...

Investigating Iphlpapi.h, it seems that netioapi.h and other networking headers used by the current version of APR are supported only starting from Vista onward:

#if (NTDDI_VERSION >= NTDDI_VISTA)

#include <netioapi.h>

#endif // (NTDDI_VERSION >= NTDDI_VISTA)

So in order for the compilation to work, just remove that cmake option or specify a value higher than 0x0600 (the equivalent for Vista).

Claudiu
  • 2,124
  • 4
  • 26
  • 36