You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joachim Ziegler <zi...@mpi-sb.mpg.de> on 2008/01/25 09:36:59 UTC

Newbie question: Compiling helloworld-APR.c under Windows

Hello,

we are evaluating APR as a possible base for a multi-platform server 
project.

I have successfully compiled and executed the following APR-"Hello 
world!" program under Unix:

#include <stdio.h>
#include <apr_general.h>

int main(int argc, const char *argv[])
{
     apr_status_t rv;
     rv = apr_initialize();
     printf( "Hello APR world!\n");
     apr_terminate();
     return 0;
}


Now I try to compile this with Visual Studio 8 (2005). I have 
successfully built the APR libs and the test suite with Studio.

But when compiling the above program, I get the following error message:

------ Build started: Project: TestAPR, Configuration: Debug Win32 ------
Compiling...
try-helloworld-APR.c
d:\apr\apr\include\apr_errno.h(52) : error C2061: syntax error : 
identifier 'apr_strerror'
d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : ';'
d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : 'type'

The respective line in apr_errno.c reads

APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
                                  apr_size_t bufsize);

It seems that the macro APR_DECLARE is not defined.

I have spent one day to read all available documentation on APR and have 
searched the mailing list archive for messages concerning how to compile 
with APR under windows, but I just could not find out what settings I 
have to specify to use the APR libs with Visual Studio.

The page http://apr.apache.org/compiling_win32.html just says

>  Integrating the Library
> 
>     We should tell ya'll 'bout this, no?

:-)

Can you please help me? Any hints are highly appreciated.

Thank you and kind regards,
Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Joachim Ziegler <zi...@mpi-sb.mpg.de>.
I just want to tell you that some kind soul sent me the following 
advices, which solved the problems for me:

> this should fix your problems:
> 
> 1. Add ws2_32.lib and mswsock.lib to your depend libraries (fixes unresolved symbols)
> 2. Check the runtime library for APR/ApU and your project, they should be the same (e. g. multithread or multithread dll) (fixes multible symbols)

Now, what I still do not know, is: Should I have known this? Is there 
some documentation missing or is it my missing experience with 
development under Windows?

Thank you all,
Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Joachim Ziegler <zi...@mpi-sb.mpg.de>.
Let me tell you exactly what I did.

I tried to follow as much as possible the information given on

http://apr.apache.org/compiling_win32.html

Again, I must admit that I have not used Visual Studio much in the past. 
I come from a UNIX background. Maybe I do wrong something very basic.

I try to compile and link the following minimal program against the 
static APR libraries within visual Studio 2005:

#include <apr.h>
#include <apr_general.h>
int main(int argc, const char *argv[])
{
   apr_initialize();
   apr_terminate();
   return 0;
}

My installation of APR resides below D:\apr.

I created a new project APRTest in Visual Studio. On the properties 
pages of this project, I entered:

- C/C++/General/Additional Include Directories:

D:\apr\apr\include;D:\apr\apr-util\include

- C/C++/Preprocessor/Preprocessor definitions:

WIN32
APR_DECLARE_STATIC
APU_DECLARE_STATIC

- Linker/Input/Additional dependencies:

D:\apr\apr\LibD\apr-1.lib
D:\apr\apr-util\LibD\aprutil-1.lib


Now I got the following error messages:


------ Build started: Project: APRTest, Configuration: Debug Win32 ------
Linking...
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _free already defined in 
LIBCMT.lib(free.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isupper already defined in 
LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _atoi already defined in 
LIBCMT.lib(atox.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isdigit already defined in 
LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strchr already defined in 
LIBCMT.lib(strchr.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _malloc already defined in 
LIBCMT.lib(malloc.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _getenv already defined in 
LIBCMT.lib(getenv.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isspace already defined in 
LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: ___doserrno already defined 
in LIBCMT.lib(dosmap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _memmove already defined in 
LIBCMT.lib(memmove.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strncmp already defined in 
LIBCMT.lib(strncmp.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __strtoi64 already defined in 
LIBCMT.lib(strtoq.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __errno already defined in 
LIBCMT.lib(dosmap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _islower already defined in 
LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isalpha already defined in 
LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strtol already defined in 
LIBCMT.lib(strtol.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __stricmp already defined in 
LIBCMT.lib(stricmp.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __strnicmp already defined in 
LIBCMT.lib(strnicmp.obj)
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other 
libs; use /NODEFAULTLIB:library
apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
__imp__WSACleanup@0 referenced in function _apr_initialize@0
apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
__imp__WSAStartup@8 referenced in function _apr_initialize@0
apr-1.lib(apr_snprintf.obj) : error LNK2019: unresolved external symbol 
__imp__ntohl@4 referenced in function _conv_in_addr
apr-1.lib(sockaddr.obj) : error LNK2001: unresolved external symbol 
__imp__ntohl@4
apr-1.lib(select.obj) : error LNK2019: unresolved external symbol 
___WSAFDIsSet@8 referenced in function _apr_poll@20
apr-1.lib(select.obj) : error LNK2019: unresolved external symbol 
__imp__WSAGetLastError@0 referenced in function _apr_poll@20
apr-1.lib(sockaddr.obj) : error LNK2001: unresolved external symbol 
__imp__WSAGetLastError@0
apr-1.lib(select.obj) : error LNK2019: unresolved external symbol 
__imp__select@20 referenced in function _apr_poll@20
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__htons@4 referenced in function _apr_sockaddr_vars_set
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__ntohs@4 referenced in function _get_local_addr
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__getsockname@12 referenced in function _get_local_addr
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__getpeername@12 referenced in function _get_remote_addr
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__gethostbyname@4 referenced in function _find_addresses
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__inet_addr@4 referenced in function _find_addresses
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__gethostbyaddr@12 referenced in function _apr_getnameinfo@12
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__getservbyname@8 referenced in function _apr_getservbyname@8
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__htonl@4 referenced in function _apr_ipsubnet_create@16
D:\APRTest\Debug\APRTest.exe : fatal error LNK1120: 15 unresolved externals
Build log was saved at "file://d:\APRTest\APRTest\Debug\BuildLog.htm"
APRTest - 36 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Joachim Ziegler wrote:
> 
> I'm not quite sure to understand what you mean by this. Yes, I have 
> downloaded the win32-src.zip file and followed the instructions in the 
> section "Developer Studio Workspace/Microsoft Development Environment 
> IDE Build" on
> 
> http://apr.apache.org/compiling_win32.html
> 
> to build the libs.

Sounds great - give me a day or two to freshen that document, and I'll
post when it's good to follow.

I'll be sure to add something about consuming libapr on win32 as well.

Bill

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Issac Goldstand <ma...@beamartyr.net>.
William A. Rowe, Jr. wrote:
> Issac Goldstand wrote:
>> Sounds like the liker wants Winsock linked in (ws2_32.lib).  Not sure 
>> why your application wants it, as it should have been linked into 
>> apr-1.dll already - maybe someone else can chime in.
> 
> You must mean libapr-1.lib/libapr-1.dll, yes, it is.
> 
> But no, it's not linked to apr-1.lib (static).

Good point - I missed that.  Now the original email makes more sense.

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Issac Goldstand wrote:
> Sounds like the liker wants Winsock linked in (ws2_32.lib).  Not sure 
> why your application wants it, as it should have been linked into 
> apr-1.dll already - maybe someone else can chime in.

You must mean libapr-1.lib/libapr-1.dll, yes, it is.

But no, it's not linked to apr-1.lib (static).

I'm contemplating some trickery which would ensure that the user doesn't
have to call out dependent libs, but not till apr 1.3.0

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Issac Goldstand <ma...@beamartyr.net>.
Sounds like the liker wants Winsock linked in (ws2_32.lib).  Not sure 
why your application wants it, as it should have been linked into 
apr-1.dll already - maybe someone else can chime in.

   Issac

Joachim Ziegler wrote:
> Hello William,
> 
> thank you for your quick reply last week.
> 
> Unfortunately I still cannot get helloworld-APR.c running under Windows.
> 
> William A. Rowe, Jr. wrote:
>> If you used a -win32-src.zip file, and run nmake against the
>> makefile.win, you shouldn't be having problems.
> 
> I'm not quite sure to understand what you mean by this. Yes, I have 
> downloaded the win32-src.zip file and followed the instructions in the 
> section "Developer Studio Workspace/Microsoft Development Environment 
> IDE Build" on
> 
> http://apr.apache.org/compiling_win32.html
> 
> to build the libs.
> 
> I have also successfully built and run the apr/test/aprtest.dsw project.
> 
>>
>> If you import into VS2005/2008, there are dependency hassles,
>> but you can usually work those out by reviewing the build
>> target and it's dependencies.  APR alone is pretty easy.
> 
> Sorry, I do not understand what you say here. It might well be that I 
> just know too little about Windows programming in general. (I come from 
> a UNIX background.)
> 
>> Finally, apr.h defines those APR_DECLARE macros to be .dll
>> imports if you do nothing.  You do need to declare -D WIN32
>> of course.
> 
> I have found out by myself that I have to declare this WIN32 macro by 
> following the compiler's error messages into the apr.h file. You say "of 
> course": Is this something I should have known beforehand because it is 
> customary in Windows development? If not so: I cannot read anything 
> about this in the official documentation!?
> 
> Anyway, now my helloworld compiles, but it does not link. I get the 
> following error messages:
> 
> ------ Build started: Project: TestAPR, Configuration: Debug Win32 ------
> Linking...
> try-helloworld-APR.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' 
> due to '/OPT:ICF' specification
> apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
> __imp__WSACleanup@0 referenced in function _apr_initialize@0
> apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
> __imp__WSAStartup@8 referenced in function _apr_initialize@0
> apr-1.lib(apr_snprintf.obj) : error LNK2019: unresolved external symbol 
> __imp__ntohl@4 referenced in function _conv_in_addr
> apr-1.lib(sockaddr.obj) : error LNK2001: unresolved external symbol 
> __imp__ntohl@4
> apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
> __imp__htons@4 referenced in function _apr_sockaddr_vars_set
> apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
> __imp__ntohs@4 referenced in function _get_local_addr
> apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
> __imp__WSAGetLastError@0 referenced in function _get_local_addr
> [...]
> 
> Can someone please help me?
> 
> Thank you very much,
> Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Joachim Ziegler <zi...@mpi-sb.mpg.de>.
Hello William,

thank you for your quick reply last week.

Unfortunately I still cannot get helloworld-APR.c running under Windows.

William A. Rowe, Jr. wrote:
> If you used a -win32-src.zip file, and run nmake against the
> makefile.win, you shouldn't be having problems.

I'm not quite sure to understand what you mean by this. Yes, I have 
downloaded the win32-src.zip file and followed the instructions in the 
section "Developer Studio Workspace/Microsoft Development Environment 
IDE Build" on

http://apr.apache.org/compiling_win32.html

to build the libs.

I have also successfully built and run the apr/test/aprtest.dsw project.

> 
> If you import into VS2005/2008, there are dependency hassles,
> but you can usually work those out by reviewing the build
> target and it's dependencies.  APR alone is pretty easy.

Sorry, I do not understand what you say here. It might well be that I 
just know too little about Windows programming in general. (I come from 
a UNIX background.)

> Finally, apr.h defines those APR_DECLARE macros to be .dll
> imports if you do nothing.  You do need to declare -D WIN32
> of course.

I have found out by myself that I have to declare this WIN32 macro by 
following the compiler's error messages into the apr.h file. You say "of 
course": Is this something I should have known beforehand because it is 
customary in Windows development? If not so: I cannot read anything 
about this in the official documentation!?

Anyway, now my helloworld compiles, but it does not link. I get the 
following error messages:

------ Build started: Project: TestAPR, Configuration: Debug Win32 ------
Linking...
try-helloworld-APR.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' 
due to '/OPT:ICF' specification
apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
__imp__WSACleanup@0 referenced in function _apr_initialize@0
apr-1.lib(start.obj) : error LNK2019: unresolved external symbol 
__imp__WSAStartup@8 referenced in function _apr_initialize@0
apr-1.lib(apr_snprintf.obj) : error LNK2019: unresolved external symbol 
__imp__ntohl@4 referenced in function _conv_in_addr
apr-1.lib(sockaddr.obj) : error LNK2001: unresolved external symbol 
__imp__ntohl@4
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__htons@4 referenced in function _apr_sockaddr_vars_set
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__ntohs@4 referenced in function _get_local_addr
apr-1.lib(sockaddr.obj) : error LNK2019: unresolved external symbol 
__imp__WSAGetLastError@0 referenced in function _get_local_addr
[...]

Can someone please help me?

Thank you very much,
Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Joachim Ziegler wrote:
> Hello Ruben,
> 
>  > Try including <apr.h> before apr_general.
> 
> I still get the same error.

If you used a -win32-src.zip file, and run nmake against the
makefile.win, you shouldn't be having problems.

If you import into VS2005/2008, there are dependency hassles,
but you can usually work those out by reviewing the build
target and it's dependencies.  APR alone is pretty easy.

You MUST end up with apr.h derived from apr.hw fixed-file,
not the ./configure gunk.

Finally, apr.h defines those APR_DECLARE macros to be .dll
imports if you do nothing.  You do need to declare -D WIN32
of course.

You only define APR_DECLARE_STATIC etc if you want to bind
to a static library of apr, and don't want to see all sorts
of noisy "importing exported symbol" warnings.

Bill

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Joachim Ziegler <zi...@mpi-sb.mpg.de>.
Hello Ruben,

 > Try including <apr.h> before apr_general.

I still get the same error.

Joachim

Re: Newbie question: Compiling helloworld-APR.c under Windows

Posted by Mr...@area99.dk.
Quoting Joachim Ziegler <zi...@mpi-sb.mpg.de>:

Hi Joachim.

Try including <apr.h> before apr_general.

/Ruben

> Hello,
>
> we are evaluating APR as a possible base for a multi-platform server project.
>
> I have successfully compiled and executed the following APR-"Hello
> world!" program under Unix:
>
> #include <stdio.h>
> #include <apr_general.h>
>
> int main(int argc, const char *argv[])
> {
>     apr_status_t rv;
>     rv = apr_initialize();
>     printf( "Hello APR world!\n");
>     apr_terminate();
>     return 0;
> }
>
>
> Now I try to compile this with Visual Studio 8 (2005). I have
> successfully built the APR libs and the test suite with Studio.
>
> But when compiling the above program, I get the following error message:
>
> ------ Build started: Project: TestAPR, Configuration: Debug Win32 ------
> Compiling...
> try-helloworld-APR.c
> d:\apr\apr\include\apr_errno.h(52) : error C2061: syntax error :
> identifier 'apr_strerror'
> d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : ';'
> d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : 'type'
>
> The respective line in apr_errno.c reads
>
> APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
>                                  apr_size_t bufsize);
>
> It seems that the macro APR_DECLARE is not defined.
>
> I have spent one day to read all available documentation on APR and
> have searched the mailing list archive for messages concerning how to
> compile with APR under windows, but I just could not find out what
> settings I have to specify to use the APR libs with Visual Studio.
>
> The page http://apr.apache.org/compiling_win32.html just says
>
>> Integrating the Library
>>
>>    We should tell ya'll 'bout this, no?
>
> :-)
>
> Can you please help me? Any hints are highly appreciated.
>
> Thank you and kind regards,
> Joachim



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


RE: Newbie question: Compiling helloworld-APR.c under Windows

Posted by "Myers, Gary - 43" <ga...@rainhail.com>.
Another possibility is to use MSYS from http://www.mingw.org/ I've use
that on Windows to compile APR with not much trouble.  Since you want to
port you code to multiple platforms you would probably be better served
using something like that anyway.  There are two problems with using
MSYS, there is no perfect IDE for it, and for some reason the build
system as provided doesn't build the dll's, but it does build the
assemblies so you can get the dll's out of them.  (It could also be
because I couldn't figure out how to make the build system do it.)

The log4cxx guys have some good instructions on compiling with MSYS and
Mingw
http://wiki.apache.org/logging-log4cxx/MSWindowsBuildInstructions

And if you want a pretty good C/C++ IDE that is free there is a good one
from the eclipse project that plays nice with the Mingw port of GCC.
The only thing you need that the log4cxx instructions don't tell you is
that you'll probably want 
pkg-config so you don't have to type out the long list of linking flags.

Hope this helps. 

-----Original Message-----
From: Joachim Ziegler [mailto:ziegler@mpi-sb.mpg.de] 
Sent: Friday, January 25, 2008 2:37 AM
To: dev@apr.apache.org
Subject: Newbie question: Compiling helloworld-APR.c under Windows

Hello,

we are evaluating APR as a possible base for a multi-platform server 
project.

I have successfully compiled and executed the following APR-"Hello 
world!" program under Unix:

#include <stdio.h>
#include <apr_general.h>

int main(int argc, const char *argv[])
{
     apr_status_t rv;
     rv = apr_initialize();
     printf( "Hello APR world!\n");
     apr_terminate();
     return 0;
}


Now I try to compile this with Visual Studio 8 (2005). I have 
successfully built the APR libs and the test suite with Studio.

But when compiling the above program, I get the following error message:

------ Build started: Project: TestAPR, Configuration: Debug Win32
------
Compiling...
try-helloworld-APR.c
d:\apr\apr\include\apr_errno.h(52) : error C2061: syntax error : 
identifier 'apr_strerror'
d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : ';'
d:\apr\apr\include\apr_errno.h(52) : error C2059: syntax error : 'type'

The respective line in apr_errno.c reads

APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
                                  apr_size_t bufsize);

It seems that the macro APR_DECLARE is not defined.

I have spent one day to read all available documentation on APR and have

searched the mailing list archive for messages concerning how to compile

with APR under windows, but I just could not find out what settings I 
have to specify to use the APR libs with Visual Studio.

The page http://apr.apache.org/compiling_win32.html just says

>  Integrating the Library
> 
>     We should tell ya'll 'bout this, no?

:-)

Can you please help me? Any hints are highly appreciated.

Thank you and kind regards,
Joachim