Re: Building on win32

Daniel Sahlberg <[email protected]>
Newsgroups gmane.comp.apache.apr.devel
Message-ID <CAMHy98Ow90FO0d4FCsCOgRhy04LQPkJA08AFxm4r6ysUbHWL9g@mail.gmail.com>
Den mån 10 juni 2024 kl 21:56 skrev Timofey Zhakov <[email protected]>:

> On Sun, Jun 9, 2024 at 10:32 PM Daniel Sahlberg
> <[email protected]> wrote:
> >
> > Hi,
> >
> > I'm trying to wrap my head around building APR on Windows.
> >
> > The website [1] contains instructions on running for running msdev on
> aprutil.dsw or to open aprutil.dsw in Visual Studio. However I don't have
> msdev on my installation (Visual Studio Community 2022) and the support for
> .dsw files was deprecated in Visual Studio 2022.
> >
> > The README file suggests to run nmake but that failed out of the box
> with an error in apr_arch_misc.h:
> >
> > [[[
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2143: syntax error: missing ')' before '*'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2143: syntax error: missing '{' before '*'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2059: syntax error: ')'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(510): error
> C2061: syntax error: identifier 'apr_winapi_pfn_if_indextoname'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(510): error
> C2059: syntax error: ';'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2513: ' ': no variable declared before '='
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(510): error
> C2065: 'apr_winapi_pfn_if_indextoname': undeclared identifier
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): warning
> C4047: '=': 'int' differs in levels of indirection from 'int *(__cdecl
> *)(NET_IFINDEX,PCHAR)'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(510): error
> C2146: syntax error: missing ';' before identifier 'apr_load_dll_func'
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2100: illegal indirection
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): error
> C2064: term does not evaluate to a function taking 0 arguments
> > C:\Devel\apr_1.7.4\apr\include\arch\win32\apr_arch_misc.h(507): warning
> C4033: 'apr_winapi_if_indextoname' must return a value
> > ]]]
> >
> > Editing include\apr.hw and changing _WIN32_WINNT to 0x0601 made the
> build go a lot further but it ended with:
> >
> > [[[
> >         link.exe /nologo /debug /subsystem:console /incremental:no
> /out:"LibR\testall.exe" LibR\testutil.obj LibR\testtime.obj
> LibR\teststr.obj LibR\testvsn.obj LibR\testipsub.obj LibR\testmmap.obj
> LibR\testud.obj LibR\testtable.obj LibR\testsleep.obj LibR\testpools.obj
> LibR\testfmt.obj LibR\testfile.obj LibR\testdir.obj LibR\testfileinfo.obj
> LibR\testrand.obj LibR\testdso.obj LibR\testoc.obj LibR\testdup.obj
> LibR\testsockets.obj LibR\testproc.obj LibR\testpoll.obj LibR\testlock.obj
> LibR\testsockopt.obj LibR\testpipe.obj LibR\testthread.obj
> LibR\testhash.obj LibR\testargs.obj LibR\testnames.obj LibR\testuser.obj
> LibR\testpath.obj LibR\testenv.obj LibR\testprocmutex.obj
> LibR\testfnmatch.obj LibR\testatomic.obj LibR\testflock.obj
> LibR\testshm.obj LibR\testsock.obj LibR\testglobalmutex.obj
> LibR\teststrnatcmp.obj LibR\testfilecopy.obj LibR\testtemp.obj
> LibR\testlfs.obj LibR\testcond.obj LibR\testescape.obj
> LibR\testskiplist.obj LibR\testencode.obj LibR\abts.obj ..\LibR\apr-1.lib
> kernel32.lib advapi32.lib ws2_32.lib wsock32.lib  ole32.lib shell32.lib
> rpcrt4.lib
> > testutil.obj : error LNK2019: unresolved external symbol
> __imp__CrtSetReportFile referenced in function initialize
> > testutil.obj : error LNK2019: unresolved external symbol
> __imp__CrtSetReportMode referenced in function initialize
> > LibR\testall.exe : fatal error LNK1120: 2 unresolved externals
> > NMAKE : fatal error U1077: 'link.exe /nologo /debug /subsystem:console
> /incremental:no /out:"LibR\testall.exe" LibR\testutil.obj LibR\testtime.obj
> LibR\teststr.obj LibR\testvsn.obj LibR\testipsub.obj LibR\testmmap.obj
> LibR\testud.obj LibR\testtable.obj LibR\testsleep.obj LibR\testpools.obj
> LibR\testfmt.obj LibR\testfile.obj LibR\testdir.obj LibR\testfileinfo.obj
> LibR\testrand.obj LibR\testdso.obj LibR\testoc.obj LibR\testdup.obj
> LibR\testsockets.obj LibR\testproc.obj LibR\testpoll.obj LibR\testlock.obj
> LibR\testsockopt.obj LibR\testpipe.obj LibR\testthread.obj
> LibR\testhash.obj LibR\testargs.obj LibR\testnames.obj LibR\testuser.obj
> LibR\testpath.obj LibR\testenv.obj LibR\testprocmutex.obj
> LibR\testfnmatch.obj LibR\testatomic.obj LibR\testflock.obj
> LibR\testshm.obj LibR\testsock.obj LibR\testglobalmutex.obj
> LibR\teststrnatcmp.obj LibR\testfilecopy.obj LibR\testtemp.obj
> LibR\testlfs.obj LibR\testcond.obj LibR\testescape.obj
> LibR\testskiplist.obj LibR\testencode.obj LibR\abts.obj ..\LibR\apr-1.lib
> kernel32.lib advapi32.lib ws2_32.lib wsock32.lib  ole32.lib shell32.lib
> rpcrt4.lib' : return code '0x460'
> > Stop.
> > ]]]
> >
> > I'm surely doing something wrong here... appreciating any advice and/or
> pointers!
> >
> > Kind regards,
> > Daniel Sahlberg
> >
> >
> > [1] https://apr.apache.org/compiling_win32.html
> > [2]
> https://learn.microsoft.com/en-us/cpp/porting/upgrading-projects-from-earlier-versions-of-visual-cpp?view=msvc-170
> >
>
> Hello Daniel,
>
> I want to recommend you to use CMake for building APR on Windows. I
> think it is simpler and more supported nowadays.
>
> The only commands you need to build:
>
> ```
> # Configure
> cmake -B out -G "Visual Studio 17 2022"
>
> # Build
> cmake --build out --config Release
>
> # Install
> cmake --install out
> # The default install dir is `C:/Program Files (x86)/APR` on Windows,
> but you can choose another by specifying the `--prefix` ARG.
> ```
>
> The script above is similar to the vcpkg port [1] and to the GitHub
> Actions script [2]. Additionally, as a follow-up to Stephen's answer,
> you can pass `-disableMetrics` ARG to the bootstrap-vcpkg command, if
> you want to prevent telemetry.
>
> If you are building APR Util, you have to do the same as for APR, but
> you have to specify the directory where APR is installed. You can do
> this by adding the `-DCMAKE_INSTALL_PREFIX=/apr/install/dir` argument
> to your CMake configure command.
>
> [1] vcpkg APR port:
>
> https://github.com/microsoft/vcpkg/blob/ad25766aefb5313b6bc4e2a4b78a2946f84fbf66/ports/apr/portfile.cmake#L23
> [2] https://github.com/apache/apr/blob/1.7.x/.github/workflows/windows.yml
>
> --
> Timofei Zhakov
>

Thanks Timofei, I will try this tomorrow!

Kind regards,
Daniel

(If only someone could commit a CMake build system to Subversion... oh,
wait, seems you recently submitted a patch for that - thanks! - now I have
the APR to review your patch ;-) )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.