[MS]
Steve Petrie, P.Eng. wrote:
[...]
I use the following MSYS console shell command, to compile the
test_stdcxx_1.cpp program:

 g++.exe -I./include -nostdinc++ -nostdinc -nostdlib -c -o
test_stdcxx_1.o
test_stdcxx_1.cpp

You also need -I./include/ansi. Its also a good idea to avoid
using the g++ command and use gcc instead just to make it 100%
clear that the native C++ Standard Library should not be linked
(unless you know better , I don't think you want -nostdlib as
it normally prevents linking with files you want to link with).
[...]
That's because you're missing -Iinlude/ansi -- that's where
our cwchar lives. All the errors after this one should clear
up after you add it.


[SP]
OK -- I now have a test program that compiles, links and runs using stdcxx
under MinGW+MSYS.

There's more to it than adding -I./include/ansi to the compile as Martin
suggested, but the -I./include/ansi is definitely necessary.

Here's the test program (it's based on the sample that Farid provided at my
request, designed to conclusively PROVE that it's using stdcxx and not only
the standard library shipped with MinGW+MSYS (The __rw_atomic_add32()
function is SPECIFIC to stdcxx, there's no _atomic-x86.h in MinGW) :

  // test_stdcxx_2.cpp ...

  // standard library includes...
       #include <iostream>
  // ...standard library includes.

      using std::cout;

  // app includes...
      #include "rw/_atomic-x86.h"
  //...  app includes.

      using __rw::__rw_atomic_add32;

  int main (void)
  {
      cout << "Hello from test_stdcxx_2.cpp!\n";

      int ret = -1;

  // dependency on stdcxx library
      ret = __rw::__rw_atomic_add32 (&ret, 1);

      return ret;
  }
  // ... test_stdcxx_2.cpp.

* * *
* * *

Here is an MSYS console shell command that successfully compiles the
test_stdcxx_2.cpp program:

  gcc.exe -D_RWSTDDEBUG -I./include -I./include/ansi -c -o test_stdcxx_2.o
test_stdcxx_2.cpp

I use the -D_RWSTDDEBUG parameter, because my stdcxx library was built for
debugging.

* * *
* * *

The link is more complicated.

I could NOT find any way to use gcc.exe or g++.exe, to get a successful
link. So I analyzed the various forms of the parameters used with the
following intermediate command (generated by gcc.exe and g++.exe from my
parameters used with them):

  i:/apps/mingw/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe ...
parameters ...

Here is the MSYS console shell command, that successfully links the
test_stdcxx_2.o object file (the key items are flagged "**n" here for
convenient reference below):

  ld.exe \
    -Bstatic \   **1
    -o test_stdcxx_2.exe \ **2
    i:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../crt2.o \
    i:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o \
    -L./lib \ **3
    -Li:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5 \
    -Li:/apps/mingw/bin/../lib/gcc \
    -Li:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib \
    -Li:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5/../../.. \
    test_stdcxx_2.o \ **4
    -lstd11s \ **5
    -lstdc++ \ **6
    -lmingw32 \
    -lgcc \
    -lmoldname \
    -lmingwex \
    -lmsvcrt \
    -luser32 \
    -lkernel32 \
    -ladvapi32 \
    -lshell32 \
    -lmingw32 \
    -lgcc \
    -lmoldname \
    -lmingwex \
    -lmsvcrt \
    i:/apps/mingw/bin/../lib/gcc/mingw32/3.4.5/crtend.o

The key points in the above are:

 **1 => either -Bstatic or -Bdynamic works (omitting the -B parameter
entirely also works).

 **2 => -o test_stdcxx_2.exe is the executable to be generated.

 **3 =>-L./lib is the directory containing the libstd11s.a build of Apache
stdcxx, built with MinGW_MSYS
              (it's FIRST in the list of -L parameters, as I assume this
will give it search priority).

 **4=> test_stdcxx_2.o is the object input (it MUST precede the -lstd11s
parameter).

 **5 => -lstd11s is the reference to the libstd11s.a build of Apache stdcxx
               (it's FIRST in the list of -l parameters, as I assume this
will give it search priority).

 **6 => -lstdc++  is the reference to the standard library shipped with
MinGW
               (it's NECESSARY to resolve references in some of the
MinGW-supplied object modules)

* * *
* * *

I have a shell script file, that compiles, links and runs the C++ test
program. If you would like to have the script file, and the C++ source file,
just let me know.

For purposes of performing this test, the MSYS console current directory is
where the source program test_stdcxx_2.cpp is:

  i:/USR/ASP/stdcxx/

and the libstdcxx.a library is in:

  i:/USR/ASP/stdcxx/lib/

* * *
* * *

There are now only two OUTSTANDING ISSUES:

 (1) The link produces a HUGE (4.9 MB) test_stdcxx_2.exe executable:

      (1.1) I've tried the ld "--gc-sections" parameter, which the
ld --help says will "Remove unused sections (on some targets)"
                but it doesn't shrink the executable.

      (1.2) compiling without the "-D_RWSTDDEBUG" parameter, doesn't help
to shrink the executable.

      (1.3) Removing the "__rw_atomic_add32()" function call, doesn't help
to shrink the executable.

      (1.4) By contrast with stdcxx, a similar test program (minus the
__rw_atomic_add32() function call)
               compiled and linked using g++.exe and the MinGW_MSYS
standard library, produces
              an executable ONLY 486 KB in size.

 (2) I will now proceed to work on getting my NetBeans 6.5 IDE (with C++
plugin) to use the Apache stdcxx.

* * *
* * *

Any suggestions, for how to shrink the sixe of executable files, would be
greatly appreciated.

Although I have used open source "products" before, this is my first time
working actively with an open source community, and it's proving to be a
very pleasant and productive experience.

Thanks to Farid and Martin, for all your help.

Steve

----- Original Message ----- From: "Martin Sebor" <[EMAIL PROTECTED]>
To: <user@stdcxx.apache.org>
Sent: Thursday, December 04, 2008 5:29 PM
Subject: Re: Building stdcxx-4.2.2 Using MinGW+MSYS On Windows XP (SP2)


Steve Petrie, P.Eng. wrote:
[...]
I use the following MSYS console shell command, to compile the
test_stdcxx_1.cpp program:

 g++.exe -I./include -nostdinc++ -nostdinc -nostdlib -c -o
test_stdcxx_1.o
test_stdcxx_1.cpp

You also need -I./include/ansi. Its also a good idea to avoid
using the g++ command and use gcc instead just to make it 100%
clear that the native C++ Standard Library should not be linked
(unless you know better , I don't think you want -nostdlib as
it normally prevents linking with files you want to link with).


(Note the dot "." between "-I" and "/include". I have an stdcxx "include"
directory, with all its sub-directories, as a sub-directory of the
directory
where the test_stdcxx_1.cpp source program is located, because I haven't
yet
been able to figure out how to get g++.exe to respect a "-I" parameter
pointing to a more complex path description. The "include" directory,
with
all its sub-directories, is a copy of what is shipped with stdcxx-4.2.2.)

g++.exe displays the following compile errors on the MSYS console:

  In file included from ./include/rw/_traits.h:40,
                   from ./include/rw/_strref.h:48,
                   from ./include/string:43,
                   from ./include/loc/_locale.h:36,
                   from ./include/rw/_iosbase.h:36,
                   from ./include/streambuf:39,
                   from ./include/ostream:39,
                   from ./include/istream:38,
                   from ./include/iostream:33,
                   from test_stdcxx_1.cpp:4:
  ./include/rw/_mbstate.h:195:27: cwchar: No such file or directory

That's because you're missing -Iinlude/ansi -- that's where
our cwchar lives. All the errors after this one should clear
up after you add it.

Martin

Reply via email to