From: Patrick Scheibe on
Hi,

now you have a MathLink program. You could use it either by:

- starting it as you did. the window pops up, asking you for a name for
your link. My favorite one is "blub". So type in a name and klick ok.

- go in a Mathematia-notebook and call

lnk=Install[LinkConnect["blub"]]

and you get a LinkObject. You can look what functions are provided by
the link with

LinkPatterns[lnk]

you should now be able to call

AddTwo[1,2]

and to uninstall the link with

Uninstall[lnk]

The other possibility (which you should use when your program is bugfree
and finished) is to Install the link directly with

lnk=Install["full\path\to\link\addtwo.exe"]

Thats it. Please check in the documentation-center the doc for

Install
Uninstall
LinkConnect

Cheers
Patrick



On Tue, 2010-07-27 at 22:03 -0300, Eduardo M. A. M.Mendes wrote:
> Hi there
>
> -mwindows did the trick. Running addtwo.exe resulted in a pop-up window
> which asks me for a link (I have no idea what to do with it!).
>
> Many Many thanks.
>
> I will try to run some examples and then back to fortran.
>
> Cheers
>
> Ed
>
>
> -----Original Message-----
> From: Patrick Scheibe [mailto:pscheibe(a)trm.uni-leipzig.de]
> Sent: Tuesday, July 27, 2010 7:58 PM
> To: Eduardo M. A. M.Mendes
> Cc: mathgroup(a)smc.vnet.net
> Subject: RE: Problems compiling addrow with gcc-mingw (windows).
>
> Hi,
>
> I don't know from here what exactly is required for compiling under
> cygwin but you maybe have the wrong subsystem defined. Does your
> main-function in the addtwo.tm look like that:
>
> int __stdcall WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
> LPSTR lpszCmdLine, int nCmdShow)
> {
> char buff[512];
> char FAR * buff_start = buff;
> char FAR * argv[32];
> char FAR * FAR * argv_end = argv + 32;
>
> if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;
> MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
> return MLMain( argv_end - argv, argv);
> }
>
> Then you maybe need to set -mwindows or -mwin32 or you substitute
>
> int main(int argc; char* argv[])
> {
> return MLMain(argc, argv);
> }
>
> as main function and create a console application.
> I'm not sure if this really is the problem but you could additionally
> read this here
>
> http://forums.wolfram.com/mathgroup/archive/2007/Jun/msg01337.html
> http://forums.wolfram.com/mathgroup/archive/2010/May/msg00452.html
>
> Cheers
> Patrick
>
>
> On Tue, 2010-07-27 at 10:52 -0300, Eduardo M. A. M.Mendes wrote:
> > Hi again
> >
> > Thanks for the patience.
> >
> > I don't know if I got what you meant so I tied the following commands
> >
> > a) mprep addtwo.tm -o addtwotm.c (page 48 of MathLink Development in C)
> > b) then I try
> >
> > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > -Ic:/msys/1.0/home/eduardo/include
> > addtwotm.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -lML32i3 -lML32i2
> > -lML3
> > i1
> > C:\Users\eduardo\AppData\Local\Temp\ccelsS8E.o:addtwotm.c:(.text+0x15b):
> > undefi
> > ed reference to `GetStockObject@4'
> > collect2: ld returned 1 exit status
> >
> > c) and
> >
> > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > -Ic:/msys/1.0/home/eduardo/include
> > addtwo.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -lML32i3 -lML32i2
> > -lML32i
> >
> > C:\Users\eduardo\AppData\Local\Temp\cc2EukU7.o:addtwo.c:(.text+0x3a):
> > undefined
> > reference to `MLInitializeIcon'
> > C:\Users\eduardo\AppData\Local\Temp\cc2EukU7.o:addtwo.c:(.text+0x96):
> > undefined
> > reference to `MLMain'
> > collect2: ld returned 1 exit status
> >
> >
> > Which one is the right one? The Documentation is too convoluted and there
> > is no help with cygwin.
> >
> > Many thanks
> >
> > Ed
> >
> >
> > -----Original Message-----
> > From: Patrick Scheibe [mailto:pscheibe(a)trm.uni-leipzig.de]
> > Sent: Tuesday, July 27, 2010 10:17 AM
> > To: Eduardo M. A. M.Mendes
> > Cc: mathgroup(a)smc.vnet.net
> > Subject: Re: Problems compiling addrow with gcc-mingw
> (windows).
> >
> > Hi,
> >
> > why are you giving
> >
> > > addtwo.c addtwotm.c
> >
> >
> > both files? You mprep addtwo.tm into addtwo.c and
> > then use only addtwo.c to compile. This should kill the
> > multiple references error message.
> >
> > Cheers
> > Patrick
> >
> > Am Jul 27, 2010 um 1:53 PM schrieb Eduardo M. A. M.Mendes:
> >
> > > Hello
> > >
> > >
> > >
> > > I am trying to get addwo.exe using gcc (or g++) that comes with
> > > mingw. I
> > > have all libs and includes from cygwin that come with Mathematica
> > > (Mathlink)
> > > installed in a different dir structure but unfortunately I got the
> > > following
> > > error
> > >
> > >
> > >
> > >
> > >
> > > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > > -Ic:/msys/1.0/home/eduardo/include
> > >
> > > addtwo.c addtwotm.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -
> > > lML32i3
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x285):
> > > multip
> > >
> > > e definition of `addtwo(int, int)'
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccNPhnOo.o:addtwo.c:(.text+0x0):
> > > first
> > > defi
> > >
> > > ed here
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x293):
> > > multip
> > >
> > > e definition of `WinMain(a)16'
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccNPhnOo.o:addtwo.c:(.text+0xe):
> > > first
> > > defi
> > >
> > > ed here
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x15b):
> > > undefi
> > >
> > > ed reference to `GetStockObject@4'
> > >
> > > collect2: ld returned 1 exit status
> > >
> > >
> > >
> > > Does anyone know what to sort this out?
> > >
> > >
> > >
> > > Many thanks
> > >
> > >
> > >
> > > Ed
> > >
> > >
> >
> >
>
>


From: Eduardo M. A. M.Mendes on
Hi

Unfortunately neither option works. LinkPatterns[lnk] return [] in both
cases even though I can see that there is addtwo.exe program running.

I tried with the PreBuiltExamples and it worked. The problem is with the
addtwo.exe created by gcc-mingw.

I went back to your previous post and decided to install cygwin. Following
Rolf Mertig's post (first one on your list), I have modified his Makefile
and included cygwin1.dll on a dir that Windows can search (Rolf did not talk
about his but I had to do it in order to get addtwo.exe working). Voila,
addtow.exe works with Mathematica as the precompiled version did.

The big thing that makes it work is that one should not use anything that
comes from C:\Program Files\Wolfram
Research\Mathematica\7.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\Com
pilerAdditions\cygwin. Instead copy everything from C:\Program Files\Wolfram
Research\Mathematica\7.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\Com
pilerAdditions\mldev2. Go figure! (I am getting used to the idea that
Mathematica documentation is not be trusted entirely - it never ever shows
the true story.)

With that information, I went back to my gcc-mingw and changed the libs,
includes and exe to mldev32 (not cygwin). I then modified the previous
Makefile to use gcc-mingw and now addtwo.exe compiled with mingw works
within Mathematica.

Many thanks for your help and patience.

Regards

Ed

PS. Now I can start figuring out what to do with my fortran code.



-----Original Message-----
From: Patrick Scheibe [mailto:pscheibe(a)trm.uni-leipzig.de]
Sent: Wednesday, July 28, 2010 6:49 AM
To: Eduardo M. A. M.Mendes
Cc: mathgroup(a)smc.vnet.net
Subject: RE: Problems compiling addrow with gcc-mingw (windows).

Hi,

now you have a MathLink program. You could use it either by:

- starting it as you did. the window pops up, asking you for a name for
your link. My favorite one is "blub". So type in a name and klick ok.

- go in a Mathematia-notebook and call

lnk=Install[LinkConnect["blub"]]

and you get a LinkObject. You can look what functions are provided by
the link with

LinkPatterns[lnk]

you should now be able to call

AddTwo[1,2]

and to uninstall the link with

Uninstall[lnk]

The other possibility (which you should use when your program is bugfree
and finished) is to Install the link directly with

lnk=Install["full\path\to\link\addtwo.exe"]

Thats it. Please check in the documentation-center the doc for

Install
Uninstall
LinkConnect

Cheers
Patrick



On Tue, 2010-07-27 at 22:03 -0300, Eduardo M. A. M.Mendes wrote:
> Hi there
>
> -mwindows did the trick. Running addtwo.exe resulted in a pop-up window
> which asks me for a link (I have no idea what to do with it!).
>
> Many Many thanks.
>
> I will try to run some examples and then back to fortran.
>
> Cheers
>
> Ed
>
>
> -----Original Message-----
> From: Patrick Scheibe [mailto:pscheibe(a)trm.uni-leipzig.de]
> Sent: Tuesday, July 27, 2010 7:58 PM
> To: Eduardo M. A. M.Mendes
> Cc: mathgroup(a)smc.vnet.net
> Subject: RE: Problems compiling addrow with gcc-mingw
(windows).
>
> Hi,
>
> I don't know from here what exactly is required for compiling under
> cygwin but you maybe have the wrong subsystem defined. Does your
> main-function in the addtwo.tm look like that:
>
> int __stdcall WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
> LPSTR lpszCmdLine, int nCmdShow)
> {
> char buff[512];
> char FAR * buff_start = buff;
> char FAR * argv[32];
> char FAR * FAR * argv_end = argv + 32;
>
> if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;
> MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
> return MLMain( argv_end - argv, argv);
> }
>
> Then you maybe need to set -mwindows or -mwin32 or you substitute
>
> int main(int argc; char* argv[])
> {
> return MLMain(argc, argv);
> }
>
> as main function and create a console application.
> I'm not sure if this really is the problem but you could additionally
> read this here
>
> http://forums.wolfram.com/mathgroup/archive/2007/Jun/msg01337.html
> http://forums.wolfram.com/mathgroup/archive/2010/May/msg00452.html
>
> Cheers
> Patrick
>
>
> On Tue, 2010-07-27 at 10:52 -0300, Eduardo M. A. M.Mendes wrote:
> > Hi again
> >
> > Thanks for the patience.
> >
> > I don't know if I got what you meant so I tied the following commands
> >
> > a) mprep addtwo.tm -o addtwotm.c (page 48 of MathLink Development in C)
> > b) then I try
> >
> > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > -Ic:/msys/1.0/home/eduardo/include
> > addtwotm.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -lML32i3
-lML32i2
> > -lML3
> > i1
> > C:\Users\eduardo\AppData\Local\Temp\ccelsS8E.o:addtwotm.c:(.text+0x15b):
> > undefi
> > ed reference to `GetStockObject@4'
> > collect2: ld returned 1 exit status
> >
> > c) and
> >
> > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > -Ic:/msys/1.0/home/eduardo/include
> > addtwo.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -lML32i3 -lML32i2
> > -lML32i
> >
> > C:\Users\eduardo\AppData\Local\Temp\cc2EukU7.o:addtwo.c:(.text+0x3a):
> > undefined
> > reference to `MLInitializeIcon'
> > C:\Users\eduardo\AppData\Local\Temp\cc2EukU7.o:addtwo.c:(.text+0x96):
> > undefined
> > reference to `MLMain'
> > collect2: ld returned 1 exit status
> >
> >
> > Which one is the right one? The Documentation is too convoluted and
there
> > is no help with cygwin.
> >
> > Many thanks
> >
> > Ed
> >
> >
> > -----Original Message-----
> > From: Patrick Scheibe [mailto:pscheibe(a)trm.uni-leipzig.de]
> > Sent: Tuesday, July 27, 2010 10:17 AM
> > To: Eduardo M. A. M.Mendes
> > Cc: mathgroup(a)smc.vnet.net
> > Subject: Re: Problems compiling addrow with gcc-mingw
> (windows).
> >
> > Hi,
> >
> > why are you giving
> >
> > > addtwo.c addtwotm.c
> >
> >
> > both files? You mprep addtwo.tm into addtwo.c and
> > then use only addtwo.c to compile. This should kill the
> > multiple references error message.
> >
> > Cheers
> > Patrick
> >
> > Am Jul 27, 2010 um 1:53 PM schrieb Eduardo M. A. M.Mendes:
> >
> > > Hello
> > >
> > >
> > >
> > > I am trying to get addwo.exe using gcc (or g++) that comes with
> > > mingw. I
> > > have all libs and includes from cygwin that come with Mathematica
> > > (Mathlink)
> > > installed in a different dir structure but unfortunately I got the
> > > following
> > > error
> > >
> > >
> > >
> > >
> > >
> > > C:\msys\1.0\home\eduardo\MATHLI~1\addtwo>g++
> > > -Ic:/msys/1.0/home/eduardo/include
> > >
> > > addtwo.c addtwotm.c -o addtwo.exe -Lc:/msys/1.0/home/eduardo/lib -
> > > lML32i3
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x285):
> > > multip
> > >
> > > e definition of `addtwo(int, int)'
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccNPhnOo.o:addtwo.c:(.text+0x0):
> > > first
> > > defi
> > >
> > > ed here
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x293):
> > > multip
> > >
> > > e definition of `WinMain(a)16'
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccNPhnOo.o:addtwo.c:(.text+0xe):
> > > first
> > > defi
> > >
> > > ed here
> > >
> > > C:\Users\eduardo\AppData\Local\Temp\ccYUOj6v.o:addtwotm.c:(.text
> > > +0x15b):
> > > undefi
> > >
> > > ed reference to `GetStockObject@4'
> > >
> > > collect2: ld returned 1 exit status
> > >
> > >
> > >
> > > Does anyone know what to sort this out?
> > >
> > >
> > >
> > > Many thanks
> > >
> > >
> > >
> > > Ed
> > >
> > >
> >
> >
>
>