[MPICH] Compiling a program (john-mpi MPICH2) under cygwin / WinXP - a sample makefile

Jayesh Krishna jayesh at mcs.anl.gov
Fri Feb 22 11:19:41 CST 2008


 Hi,
  I am also providing you a sample makefile+source for an MPI helloworld
program which will help you modify your makefile accordingly.
  As Darius mentioned in his previous mail the correct ordering of the
object files is necessary for linking your program. In the example below
main.c calls a function in hello.c (So main.o is specified before hello.o in
$(OBJS)). Please notice that the libraries are provided in the linking stage
($(CC) -o) and the order of $(OBJS) to make the program compile+link
correctly. Also note the position of the LFLAGS containing the libs.

########### makefile #############
CC = gcc
CFLAGS = -Wall -O3 -fomit-frame-pointer
-I/cygdrive/c/Progra~1/MPICH2/include
LFLAGS = -L/cygdrive/c/Progra~1/MPICH2/lib -lmpi
OBJS = main.o hello.o

helloworld: $(OBJS)
        $(CC) -o helloworld $(OBJS) $(LFLAGS)
main.o: main.c
        $(CC) $(CFLAGS) -c main.c
hello.o: hello.c
        $(CC) $(CFLAGS) -c hello.c
clean:
        rm -f helloworld.exe $(OBJS)

##################################
############ main.c ##############
#include <stdio.h>
#undef SEEK_SET
#undef SEEK_CUR
#undef SEEK_END
#include <mpi.h>

int main(int argc, char *argv[]){
    MPI_Init(&argc, &argv);
    helloworld();
    MPI_Finalize();
}
##################################
############ hello.c ##############
#include <stdio.h>
#undef SEEK_SET
#undef SEEK_CUR
#undef SEEK_END
#include <mpi.h>

int helloworld(void ){
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    printf("[%d] hello world\n", rank);
}
##################################

	Type make in the command line to compile+link the program.
	Hope this helps...

Regards,
Jayesh
-----Original Message-----
From: owner-mpich-discuss at mcs.anl.gov
[mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Jayesh Krishna
Sent: Thursday, February 21, 2008 5:39 PM
To: 'madfran'
Cc: mpich-discuss at mcs.anl.gov
Subject: RE: [MPICH] Compiling a program (john-mpi MPICH2) under cygwin /
WinXP - correct ordering of args

Hi,
 The correct ordering of the gcc args for your program would be,
 
===================================

gcc -c -Wall -O3 -fomit-frame-pointer -I/cygdrive/c/Progra~1/MPICH2/include
-L/cygdrive/c/Progra~1/MPICH2/lib DES_bs_b.c -lmpicxx -lfmpich2 -lmpi 

===================================
 Please copy-paste the command above, execute it and let us know if it works
for you (If you pass "-c" to gcc, gcc will not link your programs with the
libraries provided. Remove the "-c" if you need to create an executable. See
the hello world program below for reference.).

(PS:The following functions/symbols are not provided by MPICH2 --- undefined
reference to `_mdfivemmx_no sizeupdate',`_mdfivemmx_no
init_uniformsizeupdate', `_mdfivemmx_no sizeupdate',
`_mdfivemmx_noinit_uniformsizeupdate'. You should fix this to get your
program to work.)

Regards,
Jayesh
-----Original Message-----
From: Jayesh Krishna [mailto:jayesh at mcs.anl.gov]
Sent: Thursday, February 21, 2008 5:25 PM
To: 'madfran'
Cc: 'mpich-discuss at mcs.anl.gov'
Subject: RE: [MPICH] Compiling a program (john-mpi MPICH2) under cygwin /
WinXP - specify libs after source file

Hi,
 I think the problem that you are having is due to improper ordering of the
compiler arguments.
 Please try compiling a simple MPI hello world program (given below)
following the instructions below,

1) MPI program (Copy-paste the code below)
   ---------------

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[]){
	int rank;
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	printf("[%d] Hello world\n", rank);
	MPI_Finalize();
}


2) Compile using the following command (Copy-paste the command below),

gcc -I/cygdrive/c/Progra~1/MPICH2/include -L/cygdrive/c/Progra~1/MPICH2/lib
world.c -lmpi

3) Run your program using the following command (Cygwin gcc defaults the
executable name to a.exe),

mpiexec -n 2 -localroot a.exe

4) If the above steps work, you can modify the compilation of your program
accordingly.

 Hope this helps...

Regards,
Jayesh

-----Original Message-----
From: madfran [mailto:madfran at set-ezine.org]
Sent: Thursday, February 21, 2008 5:06 PM
To: Jayesh Krishna
Cc: mpich-discuss at mcs.anl.gov
Subject: RE: [MPICH] Compiling a program (john-mpi MPICH2) under cygwin /
WinXP - specify libs after source file

I begin to think it is imposible :-(

*********************************************************************
........................
........................
gcc DES_bs_b.c -c -Wall -O3 -fomit-frame-pointer -
I/cygdrive/c/Progra~1/MPICH2/include -L/cygdrive/c/Progra~1/MPICH2/lib -
lmpicxx -lfmpich2 -lmpi -finline-functions
gcc: -lmpicxx: linker input file unused because linking not done
gcc: -lfmpich2: linker input file unused because linking not done
gcc: -lmpi: linker input file unused because linking not done gcc x86.o
x86-mmx.o  md4-sse2.o NTmmx_fmt.o md5-mmx.o sha1-mmx.o DES_fmt.o DES_std.o
DES_bs.o BSDI_fmt.o MD5_fmt.o MD5_std.o BF_fmt.o BF_std.o AFS_fmt.o LM_fmt.o
des.o MD5_apache_fmt.o BFEgg_fmt.o lotus5_fmt.o md5.o NSLDAP_fmt.o
NSLDAPS_fmt.o sha1.o base64.o MYSQL_fmt.o NT_fmt.o md4.o smbencrypt.o
rawMD5_fmt.o rawSHA1_ fmt.o mssql_fmt.o hmacMD5_fmt.o WPAPSK_fmt.o
mscash_fmt.o oracle_fmt.o batch.o bench.o charset.o common.o compiler.o
config.o cracker.o crc32.o external.o formats.o getopt.o idle.o inc.o john.o
list.o loader.o logger.o math.o memory.o misc.o options.o params.o path.o
recovery.o rpp.o rules.o signals.o single.o status.o tty.o wordlist.o
unshadow.o ryan.o unafs.o undrop.o unique.o DES_bs_b.o -lkernel32 -o
../run/john.exe
hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6c3): undefined reference to
`_mdfivemmx_no sizeupdate'
hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6db): undefined reference to
`_mdfivemmx_no init_uniformsizeupdate'
hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6ef): undefined reference to
`_mdfivemmx_no sizeupdate'
hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x703): undefined reference to
`_mdfivemmx_no init_uniformsizeupdate'
bench.o:bench.c:(.text+0x849): undefined reference to `_MPI_Reduce'
bench.o:bench.c:(.text+0x91f): undefined reference to `_MPI_Reduce'
bench.o:bench.c:(.text+0x9f2): undefined reference to `_MPI_Reduce'
bench.o:bench.c:(.text+0xab0): undefined reference to `_MPI_Reduce'
john.o:john.c:(.text+0x33): undefined reference to `_MPI_Init'
john.o:john.c:(.text+0x43): undefined reference to `_MPI_Comm_rank'
john.o:john.c:(.text+0x53): undefined reference to `_MPI_Comm_size'
john.o:john.c:(.text+0x6e3): undefined reference to `_MPI_Finalize'
john.o:john.c:(.text+0x721): undefined reference to `_MPI_Finalize'
john.o:john.c:(.text+0x741): undefined reference to `_MPI_Finalize'
john.o:john.c:(.text+0x8f1): undefined reference to `_MPI_Finalize'
john.o:john.c:(.text+0xa92): undefined reference to `_MPI_Finalize'
misc.o:misc.c:(.text+0x38): more undefined references to `_MPI_Finalize' 
follow
collect2: ld returned 1 exit status
make[1]: *** [../run/john.exe] Error 1
make[1]: Leaving directory `/tmp/john-mpi/john-1.7.2-bp17-mpi6/src'
make: *** [win32-cygwin-x86-sse2] Error 2


On Thu, 21 Feb 2008 12:51:30 -0600, Jayesh Krishna wrote
> Hi,
>  Please specify the libraries after the source file.
> 
> ========================================
> gcc -Wall -O3 -fomit-frame-pointer
> -I/cygdrive/c/Progra~1/MPICH2/include
> -L/cygdrive/c/Progra~1/MPICH2/lib -funroll-loops NTmmx_fmt.c -lmpicxx
> -lfmpich2 -lmpi
> ========================================
> 
> Regards,
> Jayesh
> -----Original Message-----
> From: madfran [mailto:madfran at set-ezine.org]
> Sent: Thursday, February 21, 2008 12:02 PM
> To: Jayesh Krishna
> Cc: mpich-discuss at mcs.anl.gov
> Subject: RE: [MPICH] Compiling a program (john-mpi MPICH2) under 
> cygwin / WinXP - use -lmpicxx
> 
> Hi,...
> 
> Not luck :-(
> 
> *****************************************************************
> ................................................
> gcc -c -Wall -O3 -fomit-frame-pointer 
> -I/cygdrive/c/Progra~1/MPICH2/include
> - L/cygdrive/c/Progra~1/MPICH2/lib -lmpicxx -lfmpich2 -lmpi -funroll- 
> loops NTmmx_fmt.c NTmmx_fmt.c:63: warning: alignment of 'saved_plain'
> is greater than maximum object file alignment.  Using
> 16 NTmmx_fmt.c:65: warning: alignment of 'output' is greater than 
> maximum object file alignment.  Using 16
> gcc: -lmpicxx: linker input file unused because linking not done
> gcc: -lfmpich2: linker input file unused because linking not done
> gcc: -lmpi: linker input file unused because linking not done gcc -c 
> -DUNDERSCORES md5-mmx.S gcc -c  -DUNDERSCORES sha1-mmx.S gcc DES_fmt.o 
> DES_std.o DES_bs.o BSDI_fmt.o MD5_fmt.o MD5_std.o BF_fmt.o BF_std. o 
> AFS_fmt.o LM_fmt.o des.o MD5_apache_fmt.o BFEgg_fmt.o lotus5_fmt.o 
> md5.o NSLDA P_fmt.o NSLDAPS_fmt.o sha1.o base64.o MYSQL_fmt.o NT_fmt.o 
> md4.o smbencrypt.o ra wMD5_fmt.o rawSHA1_fmt.o mssql_fmt.o 
> hmacMD5_fmt.o WPAPSK_fmt.o mscash_fmt.o ora cle_fmt.o batch.o bench.o 
> charset.o common.o compiler.o config.o cracker.o
> crc32 .o external.o formats.o getopt.o idle.o inc.o john.o list.o 
> loader.o logger.o ma th.o memory.o misc.o options.o params.o path.o 
> recovery.o rpp.o rules.o signals. o single.o status.o tty.o wordlist.o 
> unshadow.o ryan.o unafs.o undrop.o unique.o  DES_bs_b.o x86.o 
> x86-mmx.o  md4-sse2.o NTmmx_fmt.o md5-mmx.o sha1-mmx.o - lkerne l32 -o 
> ../run/john.exe
> hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6c3): undefined reference to 
> `_mdfivemmx_no sizeupdate' hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6db)
> : undefined reference to `_mdfivemmx_no init_uniformsizeupdate' 
> hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6ef): undefined reference to 
> `_mdfivemmx_no sizeupdate' hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x703)
> : undefined reference to `_mdfivemmx_no init_uniformsizeupdate' 
> bench.o:bench.c:(.text+0x849): undefined reference to `_MPI_Reduce' 
> bench.o:bench.c:(.text+0x91f): undefined reference to `_MPI_Reduce' 
> bench.o:bench.c:(.text+0x9f2): undefined reference to `_MPI_Reduce' 
> bench.o:bench.c:(.text+0xab0): undefined reference to `_MPI_Reduce' 
> john.o:john.c:(.text+0x33): undefined reference to `_MPI_Init' 
> john.o:john.c:(.text+0x43): undefined reference to `_MPI_Comm_rank' 
> john.o:john.c:(.text+0x53): undefined reference to `_MPI_Comm_size' 
> john.o:john.c:(.text+0x6e3): undefined reference to `_MPI_Finalize' 
> john.o:john.c:(.text+0x721): undefined reference to `_MPI_Finalize' 
> john.o:john.c:(.text+0x741): undefined reference to `_MPI_Finalize' 
> john.o:john.c:(.text+0x8f1): undefined reference to `_MPI_Finalize' 
> john.o:john.c:(.text+0xa92): undefined reference to `_MPI_Finalize' 
> misc.o:misc.c:(.text+0x38): more undefined references to 
> `_MPI_Finalize' follow collect2: ld returned 1 exit status make[1]:
> *** [../run/john.exe] Error 1 make[1]: Leaving directory `/tmp/john- 
> mpi/john-1.7.2-bp17-mpi6/src' make: *** [win32-cygwin-x86-sse2] Error
> 2
> 
> On Wed, 20 Feb 2008 15:24:18 -0600, Jayesh Krishna wrote
> > Hi,
> >  Try,
> > 
> > gcc -c ... -lmpicxx -lfmpich2 -lmpi ...
> > 
> > (Note: I used "-lmpicxx" instead of "-llibmpicxx" )
> > 
> > Regards,
> > Jayesh
> > 
> > -----Original Message-----
> > From: madfran [mailto:madfran at set-ezine.org]
> > Sent: Wednesday, February 20, 2008 3:16 PM
> > To: Jayesh Krishna
> > Cc: mpich-discuss at mcs.anl.gov
> > Subject: RE: [MPICH] Compiling a program (john-mpi MPICH2) under 
> > cygwin / WinXP - use libmpicxx.a
> > 
> > Hi,...
> > 
> > The problem is not solved.
> > 
> > ***************************
> > .............
> > gcc -c -Wall -O3 -fomit-frame-pointer 
> > -I/cygdrive/c/Progra~1/MPICH2/include
> > - L/cygdrive/c/Progra~1/MPICH2/lib -llibmpicxx -lmpi -lfmpich2 
> > -funroll-loops NTmmx _fmt.c
> > NTmmx_fmt.c:63: warning: alignment of 'saved_plain' is greater than 
> > maximum object file alignment.  Using 16
> > NTmmx_fmt.c:65: warning: alignment of 'output' is greater than 
> > maximum object file alignment.  Using 16 gcc: -llibmpicxx: linker 
> > input file unused because linking not done gcc: -lmpi: linker input 
> > file unused because linking not done gcc: -lfmpich2: linker input 
> > file unused because linking not done ...........
> > bench.o:bench.c:(.text+0x849): undefined reference to
> `_MPI_Reduce' ...........
> > **************************
> > 
> > On Tue, 19 Feb 2008 16:39:52 -0600, Jayesh Krishna wrote
> > > Hi,
> > >   If you want to compile MPI programs written in C++ from cygwin 
> > > use the libmpicxx.a library (not cxx.lib) in MPICH2\lib.
> > > 
> > > Regards,
> > > Jayesh
> > > 
> > > -----Original Message-----
> > > From: owner-mpich-discuss at mcs.anl.gov 
> > > [mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of madfran
> > > Sent: Tuesday, February 19, 2008 4:09 PM
> > > To: mpich-discuss at mcs.anl.gov
> > > Subject: [MPICH] Compiling a program (john-mpi MPICH2) under 
> > > cygwin / WinXP
> > > 
> > > Hi,...
> > > 
> > > Trying to build a program under cygwin / WinXP I had received 
> > > these messages.
> > > MPICH2 is installed only under WinXP.
> > > 
> > > Any idea?
> > > 
> > > ************************************************************
> > > .....
> > > gcc -c -Wall -O3 -fomit-frame-pointer 
> > > -I/cygdrive/c/Progra~1/MPICH2/include
> > > - L/c
> > > ygdrive/c/Progra~1/MPICH2/lib -lcxx.lib -lmpi -lfmpich2 -funroll-
> > > loops   NTmmx_f mt.c NTmmx_fmt.c:63: warning: alignment of 
> > > 'saved_plain' is greater than maximum obje ct file alignment.  
> > > Using
> > > 16 NTmmx_fmt.c:65: warning: alignment of 'output' is greater than 
> > > maximum object fi le alignment.  Using 16
> > > gcc: -lcxx.lib: linker input file unused because linking not done
> > > gcc: -lmpi: linker input file unused because linking not done
> > > gcc: -lfmpich2: linker input file unused because linking not done 
> > > gcc -c -DUNDERSCORES md5-mmx.S gcc -c  -DUNDERSCORES sha1-mmx.S 
> > > gcc
> > DES_fmt.o
> > > DES_std.o DES_bs.o BSDI_fmt.o MD5_fmt.o MD5_std.o BF_fmt.o BF_std.
> > > o AFS_fmt.o LM_fmt.o des.o MD5_apache_fmt.o BFEgg_fmt.o 
> > > lotus5_fmt.o md5.o NSLDA P_fmt.o NSLDAPS_fmt.o sha1.o base64.o 
> > > MYSQL_fmt.o NT_fmt.o md4.o smbencrypt.o ra wMD5_fmt.o 
> > > rawSHA1_fmt.o mssql_fmt.o
> > hmacMD5_fmt.o
> > > WPAPSK_fmt.o mscash_fmt.o ora cle_fmt.o batch.o bench.o charset.o 
> > > common.o compiler.o config.o cracker.o
> > > crc32
> > > .o external.o formats.o getopt.o idle.o inc.o john.o list.o 
> > > loader.o logger.o ma th.o memory.o misc.o options.o params.o 
> > > path.o recovery.o rpp.o rules.o signals. o single.o status.o tty.o 
> > > wordlist.o unshadow.o ryan.o unafs.o undrop.o unique.o  DES_bs_b.o 
> > > x86.o x86-mmx.o md4-sse2.o NTmmx_fmt.o md5-mmx.o sha1-mmx.o - 
> > > lkerne
> > > l32 -o ../run/john.exe
> > > hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6c3): undefined reference to 
> > > `_mdfivemmx_no sizeupdate'
> > > hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6db)
> > > : undefined reference to `_mdfivemmx_no init_uniformsizeupdate' 
> > > hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x6ef): undefined reference to 
> > > `_mdfivemmx_no sizeupdate'
> > > hmacMD5_fmt.o:hmacMD5_fmt.c:(.text+0x703)
> > > : undefined reference to `_mdfivemmx_no init_uniformsizeupdate' 
> > > bench.o:bench.c:(.text+0x849): undefined reference to `_MPI_Reduce' 
> > > bench.o:bench.c:(.text+0x91f): undefined reference to `_MPI_Reduce' 
> > > bench.o:bench.c:(.text+0x9f2): undefined reference to `_MPI_Reduce' 
> > > bench.o:bench.c:(.text+0xab0): undefined reference to `_MPI_Reduce' 
> > > john.o:john.c:(.text+0x33): undefined reference to `_MPI_Init' 
> > > john.o:john.c:(.text+0x43): undefined reference to `_MPI_Comm_rank' 
> > > john.o:john.c:(.text+0x53): undefined reference to `_MPI_Comm_size' 
> > > john.o:john.c:(.text+0x6e3): undefined reference to `_MPI_Finalize' 
> > > john.o:john.c:(.text+0x721): undefined reference to `_MPI_Finalize' 
> > > john.o:john.c:(.text+0x741): undefined reference to `_MPI_Finalize' 
> > > john.o:john.c:(.text+0x8f1): undefined reference to `_MPI_Finalize' 
> > > john.o:john.c:(.text+0xa92): undefined reference to `_MPI_Finalize' 
> > > misc.o:misc.c:(.text+0x38): more undefined references to 
> > > `_MPI_Finalize' follow collect2: ld returned 1 exit status make[1]:
> > > *** [../run/john.exe] Error 1 make[1]: Leaving directory
> > > `/tmp/john- mpi/john-1.7.2-bp17-mpi6/src' make: *** 
> > > [win32-cygwin-x86-sse2] Error
> > > 2






More information about the mpich-discuss mailing list