Ok, with Dror's and William's help I'm up and running with APR.  Now, what
about static linking with APRICONV?

Starting with Dror's HelloWorld DSW (which compiles, links, and runs fine
with just APR), I added the lines:

# #include "apr_iconv.h"
# ...
# apr_iconv_open( 0, 0, 0, 0 );

I also added the "apriconv-1/include" directory to the search path, and
static library ("/libd/apriconv-1.lib").  Compiled fine, but linker produced
this error:

# Main.obj : error LNK2019: unresolved external symbol "int __stdcall
apr_iconv_open(char const *,char const *,struct apr_pool_t *,void * *)"
(?apr_iconv_open@@YGHPBD0PAUapr_pool_t@@[EMAIL PROTECTED]) referenced in 
function
_main
# .\Debug/AprHelloWorld.exe : fatal error LNK1120: 1 unresolved externals

I tried declaring API_DECLARE_STATIC, but that doesn't seem to change
things.  Any suggestions?

-david

> -----Original Message-----
> From: Dror Shilo [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 27, 2004 1:08 AM
> To: David Barrett
> Cc: dev@apr.apache.org
> Subject: RE: Static Linked on Linux and Win32
> 
> On win32 to link statically you have to add the flag APR_DECLARE_STATIC
> 
> I send you this sample
> the apr is installed at
> c:\Ericom++\apr
> 
> Dror Shilo
> Ericom Software
> 
> 
> -----Original Message-----
> From: David Barrett [mailto:[EMAIL PROTECTED]
> Sent: Sunday, September 26, 2004 9:22 PM
> To: dev@apr.apache.org
> Subject: Static Linked on Linux and Win32
> 
> 
> Hi, I'm really excited to use APR, but I'm having trouble getting my
> "Hello
> World" application to work with static linkage, on both Linux and Win32.
> 
> Basically, I have a single-file application:
> 
> # // Main.cpp
> # #include <iostream>
> # #include "apr.h"
> # #include "apr_general.h"
> #
> # using namespace std;
> #
> # // main
> # int main( int argc, char const* const* argv )
> # {
> #     cout << "Hello world!";
> #
> #     // Start APR
> #     apr_app_initialize( &argc, &argv, 0 );
> #
> #     unsigned char buf[10];
> #     apr_generate_random_bytes( buf, 10 );
> #
> #     // Done
> #     apr_terminate( );
> #     return 0;
> # }
> 
> I can successfully compile, link, and execute the file on Win32 with APR
> 1.0.0 when linking with the dynamic library:
> 
> # $APRBASE\Debug\libapr-1.lib
> # $APRBASE\Debug\libapr-1.dll
> 
> However, if I try to link with the static library on Win32:
> 
> # $APRBASE\libd\apr-1.lib
> 
> I get the following linker errors:
> 
> # Linking...
> # main.obj : error LNK2019: unresolved external symbol
> __imp__apr_terminate
> referenced in function _main
> # main.obj : error LNK2019: unresolved external symbol
> [EMAIL PROTECTED] referenced in function _main
> # main.obj : error LNK2019: unresolved external symbol
> [EMAIL PROTECTED] referenced in function _main
> # Debug/APRtest.exe : fatal error LNK1120: 3 unresolved externals
> 
> Likewise, I can compile and link on Linux (Fedora Core 2) using the shared
> library using the following Ant build file:
> 
> # <project name="aprtest" default="compile">
> #     <target name="compile">
> #             <exec executable="g++">
> #                     <arg value="-oaprtest"/>
> #                     <arg value="-I./unixlibs/apr-1/include/apr-1"/>
> #                     <arg value="-L./unixlibs/apr-1/lib"/>
> #                     <arg value="-lapr-1"/>
> #                     <arg value="-shared"/>
> #                     <arg file="main.cpp"/>
> #             </exec>
> #     </target>
> # </project>
> 
> But if I change line 8 from "-shared" to "-static", I get the following
> linker errors:
> 
> # compile:
> #      [exec] /tmp/ccNWTzJF.o(.text+0x33): In function `main':
> #      [exec] : undefined reference to `apr_app_initialize'
> #      [exec] /tmp/ccNWTzJF.o(.text+0x44): In function `main':
> #      [exec] : undefined reference to `apr_generate_random_bytes'
> #      [exec] /tmp/ccNWTzJF.o(.text+0x4c): In function `main':
> #      [exec] : undefined reference to `apr_terminate'
> #      [exec] collect2: ld returned 1 exit status
> 
> So, I'm seeing the exact same problem on both platforms.  Obviously I'm
> doing something wrong, and I'm hoping it's something simple.  Does anyone
> see what I should do differently to get static linkage to work?
> 
> -david


Reply via email to