Makefile bad magic number (not a Mach-O file) convert Makefile from Linux

Discussion in 'Mac Programming' started by azureblue22, Aug 20, 2010.

  1. azureblue22 macrumors newbie

    Joined:
    Aug 20, 2010
    #1
    When I Make my software package I receive this error:


    g++ -Wall Makefile
    /usr/bin/ld: Makefile bad magic number (not a Mach-O file)

    However the documentation insist that I convert the Makefile from Linux to MacOSX, but does not say how.







    Code:
    # ######################################################################
    #  Makefile FES prediction software.
    # 
    #  File      : Makefile
    #  Developer : CLS
    #  Version   : 1.5
    #  Date      : 22 March 2007
    #  
    #  This software have been tested on Linux platform
    #  It is provided without any warranty.
    # 
    #  For bug reports, please contact :
    #  ---------------------------------
    #  Fabien LEFEVRE 
    # 
    #  CLS
    #  [url]http://www.cls.fr[/url]
    #  Direction OcÈanographie Spatiale
    #  8-10, rue HermËs - Parc Technologique du Canal
    #  31520 Ramonville Saint-Agne cedex - France
    #  Tel: +33 (0)5 61 39 37 45 Fax: +33 (0)5 61 39 37 82
    #  e-mail: [email]Fabien.Lefevre@cls.fr[/email]
    # 
    #  NOTE: This software is based on the former versions
    #        developed by CNRS (Jean-Marc MOLINES and
    #        Florent LYARD among others)
    # #####################################################################
    
    # --------------------------------------------------------------------
    # TO BE MODIFIED IF NEEDED !!!
    # 
    #CFLAGS=-march=pentium4 -mfpmath=sse -msse2 -mmmx -O3 -pipe -fomit-frame-pointer -Wall -Wpointer-arith -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Werror
    FFLAGS=-O
    # CFLAGS=-g
    # FFLAGS=-g
    #
    #-- If operating system is Linux
    # CC		= gcc
    # FC		= pgf77
    #
    #-- If operating system is Sun Solaris
    #CC 		= cc
    #FC		= f77
    #
    # End of TO BE MODIFIED IF NEEDED !!!
    # --------------------------------------------------------------------
    
    INCLUDE = -I../include
    LIB_DIR = ../lib
    LIB_FES = $(LIB_DIR)/libfes.a
    LDFLAGS = -L$(LIB_DIR)
    
    
    .SUFFIXES: .o .f .c
    
    .c.a:
    	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $*.o
    	$(AR) r $@ $*.o
    	$(RM) $*.o
    
    .c.o:
    	$(CC) -c $(CFLAGS) $(INCLUDE) $<
    
    .f.o:
    	$(FC) -c $(FFLAGS) $(INCLUDE) $<
    
    
    LIB_OBJS =	interp.o	\
    		error.o		\
    		grid.o		\
    		prediction.o	\
    		fes.o
    		
    BINARIES = ascii2bin testfes fcc_testfes
    
    #
    # all
    #
    all : bin lib bin test check
    
    #
    # ascii
    #
    ascii : lib test check
    
    #
    # clean
    #
    clean :
    	$(RM) $(LIB_FES) $(LIB_OBJS) *.o $(BINARIES) fes.output.fes2004.test
    #
    # lib
    #
    lib : $(LIB_FES)
    
    #
    # test
    #
    test : lib $(BINARIES)
    
    #
    # check
    #
    check : test
    	./testfes > fes.output.fes2004.test
    	cmp fes.output.fes2004 fes.output.fes2004.test
    
    
    #
    # library depends
    #
    $(LIB_FES)(interp.o) :		interp.c
    $(LIB_FES)(error.o) :		error.c
    $(LIB_FES)(grid.o) :		grid.c
    $(LIB_FES)(prediction.o) :	prediction.c
    $(LIB_FES)(lpeqmt.o) :		lpeqmt.c
    $(LIB_FES)(fes.o) :		fes.c
    
    $(LIB_FES) :	$(LIB_FES)(interp.o)
    $(LIB_FES) :	$(LIB_FES)(error.o)
    $(LIB_FES) :	$(LIB_FES)(grid.o)
    $(LIB_FES) :	$(LIB_FES)(prediction.o)
    $(LIB_FES) :	$(LIB_FES)(fes.o)
    
    #
    # testFes
    #
    testfes : testfes.o $(LIB_FES)
    	$(CC) -o $@ $(CFLAGS) testfes.o $(LDFLAGS) -lfes -lm	
    
    fcc_testfes : fcc_fes.o fcc_testfes.o $(LIB_FES)
    	$(FC) -o $@ $(FFLAGS) fcc_fes.o fcc_testfes.o $(LDFLAGS) -lfes -lm	
    
    #
    # ascii2bin
    #
    ascii2bin : ascii2bin.o
    	$(CC) -o $@ $(CFLAGS) ascii2bin.o -lm 
    
    DATA	= ../data
    
    #
    # converts ASCII to BIN
    #
    bin:	ascii2bin			\
    	$(DATA)/2N2_drfes2004.bin	\
    	$(DATA)/2N2_fes2004.bin		\
    	$(DATA)/K1_drfes2004.bin	\
    	$(DATA)/K1_fes2004.bin		\
    	$(DATA)/K2_drfes2004.bin	\
    	$(DATA)/K2_fes2004.bin		\
    	$(DATA)/M2_drfes2004.bin	\
    	$(DATA)/M2_fes2004.bin		\
    	$(DATA)/N2_drfes2004.bin	\
    	$(DATA)/N2_fes2004.bin		\
    	$(DATA)/O1_drfes2004.bin	\
    	$(DATA)/O1_fes2004.bin		\
    	$(DATA)/P1_drfes2004.bin	\
    	$(DATA)/P1_fes2004.bin		\
    	$(DATA)/Q1_drfes2004.bin	\
    	$(DATA)/Q1_fes2004.bin		\
    	$(DATA)/S2_drfes2004.bin	\
    	$(DATA)/S2_fes2004.bin		\
    	$(DATA)/M4_fes2004.bin		\
    	$(DATA)/S1_fes2004.bin		\
    	$(DATA)/Mf_fes2004.bin		\
    	$(DATA)/Mm_fes2004.bin		\
    	$(DATA)/Mtm_fes2004.bin 	\
    	$(DATA)/MSqm_fes2004.bin
    
    
    #
    # binary depends
    #
    $(DATA)/2N2_drfes2004.bin : $(DATA)/2N2_drfes2004.asc 
    	ascii2bin $(DATA)/2N2_drfes2004.asc $(DATA)/2N2_drfes2004.bin 0
    $(DATA)/2N2_fes2004.bin : $(DATA)/2N2_fes2004.asc 
    	ascii2bin $(DATA)/2N2_fes2004.asc $(DATA)/2N2_fes2004.bin 0
    $(DATA)/K1_drfes2004.bin : $(DATA)/K1_drfes2004.asc 
    	ascii2bin $(DATA)/K1_drfes2004.asc $(DATA)/K1_drfes2004.bin 0
    $(DATA)/K1_fes2004.bin : $(DATA)/K1_fes2004.asc 
    	ascii2bin $(DATA)/K1_fes2004.asc $(DATA)/K1_fes2004.bin 0
    $(DATA)/K2_drfes2004.bin : $(DATA)/K2_drfes2004.asc 
    	ascii2bin $(DATA)/K2_drfes2004.asc $(DATA)/K2_drfes2004.bin 0
    $(DATA)/K2_fes2004.bin : $(DATA)/K2_fes2004.asc 
    	ascii2bin $(DATA)/K2_fes2004.asc $(DATA)/K2_fes2004.bin 0
    $(DATA)/M2_drfes2004.bin : $(DATA)/M2_drfes2004.asc 
    	ascii2bin $(DATA)/M2_drfes2004.asc $(DATA)/M2_drfes2004.bin 0
    $(DATA)/M2_fes2004.bin : $(DATA)/M2_fes2004.asc 
    	ascii2bin $(DATA)/M2_fes2004.asc $(DATA)/M2_fes2004.bin 0
    $(DATA)/N2_drfes2004.bin : $(DATA)/N2_drfes2004.asc 
    	ascii2bin $(DATA)/N2_drfes2004.asc $(DATA)/N2_drfes2004.bin 0
    $(DATA)/N2_fes2004.bin : $(DATA)/N2_fes2004.asc 
    	ascii2bin $(DATA)/N2_fes2004.asc $(DATA)/N2_fes2004.bin 0
    $(DATA)/O1_drfes2004.bin : $(DATA)/O1_drfes2004.asc 
    	ascii2bin $(DATA)/O1_drfes2004.asc $(DATA)/O1_drfes2004.bin 0
    $(DATA)/O1_fes2004.bin : $(DATA)/O1_fes2004.asc 
    	ascii2bin $(DATA)/O1_fes2004.asc $(DATA)/O1_fes2004.bin 0
    $(DATA)/P1_drfes2004.bin : $(DATA)/P1_drfes2004.asc 
    	ascii2bin $(DATA)/P1_drfes2004.asc $(DATA)/P1_drfes2004.bin 0
    $(DATA)/P1_fes2004.bin : $(DATA)/P1_fes2004.asc 
    	ascii2bin $(DATA)/P1_fes2004.asc $(DATA)/P1_fes2004.bin 0
    $(DATA)/Q1_drfes2004.bin : $(DATA)/Q1_drfes2004.asc 
    	ascii2bin $(DATA)/Q1_drfes2004.asc $(DATA)/Q1_drfes2004.bin 0
    $(DATA)/Q1_fes2004.bin : $(DATA)/Q1_fes2004.asc 
    	ascii2bin $(DATA)/Q1_fes2004.asc $(DATA)/Q1_fes2004.bin 0
    $(DATA)/S2_drfes2004.bin : $(DATA)/S2_drfes2004.asc 
    	ascii2bin $(DATA)/S2_drfes2004.asc $(DATA)/S2_drfes2004.bin 0
    $(DATA)/S2_fes2004.bin : $(DATA)/S2_fes2004.asc 
    	ascii2bin $(DATA)/S2_fes2004.asc $(DATA)/S2_fes2004.bin 0
    $(DATA)/M4_fes2004.bin : $(DATA)/M4_fes2004.asc 
    	ascii2bin $(DATA)/M4_fes2004.asc $(DATA)/M4_fes2004.bin 0
    $(DATA)/Mf_fes2004.bin : $(DATA)/Mf_fes2004.asc 
    	ascii2bin $(DATA)/Mf_fes2004.asc $(DATA)/Mf_fes2004.bin 0
    $(DATA)/Mm_fes2004.bin : $(DATA)/Mm_fes2004.asc 
    	ascii2bin $(DATA)/Mm_fes2004.asc $(DATA)/Mm_fes2004.bin 0
    $(DATA)/Mtm_fes2004.bin : $(DATA)/Mtm_fes2004.asc 
    	ascii2bin $(DATA)/Mtm_fes2004.asc $(DATA)/Mtm_fes2004.bin 0
    $(DATA)/MSqm_fes2004.bin : $(DATA)/MSqm_fes2004.asc 
    	ascii2bin $(DATA)/MSqm_fes2004.asc $(DATA)/MSqm_fes2004.bin 0
    $(DATA)/S1_fes2004.bin : $(DATA)/S1_fes2004.asc 
    	ascii2bin $(DATA)/S1_fes2004.asc $(DATA)/S1_fes2004.bin 0
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    Run a makefile using the make tool, e.g.

    Code:
    make all
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    I'd "make clean" first, to hopefully whack any objects that came with this.

    -Lee
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    Yeah, the fact that it seems to be going straight to linking is suspect to say the least.

    azureblue22, do you usually call your Makefiles from g++ instead of make?

    You also didn't uncomment anything for CC and FC, it looks like you could use the Linux definition for CC (gcc), but do you have a FORTRAN installed?

    B
     
  5. jazzbo macrumors member

    Joined:
    Oct 11, 2008
    Location:
    Bangor, ME
    #5
    A makefile is a set of commands to your build chain (normally things like compilers and linkers, but could any set of things from parsers to tools which build man pages.)

    So Makefile calls your c compiler, not the other way around. You use the 'make' command to process your Makefile.

    If you edit the Makefile you will see the author very clearly marked the section that is to be modified:

    Code:
    # --------------------------------------------------------------------
    # TO BE MODIFIED IF NEEDED !!!
    # 
    #CFLAGS=-march=pentium4 -mfpmath=sse -msse2 -mmmx -O3 -pipe -fomit-frame-pointer -Wall -Wpointer-arith -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Werror
    FFLAGS=-O
    # CFLAGS=-g
    # FFLAGS=-g
    #
    #-- If operating system is Linux
    # CC		= gcc
    # FC		= pgf77
    #
    #-- If operating system is Sun Solaris
    #CC 		= cc
    #FC		= f77
    #
    # End of TO BE MODIFIED IF NEEDED !!!
    # --------------------------------------------------------------------
    Lines that begin with a # are a comment, and the sections for Linux and Solaris are templates you can use.

    So basically you need to edit the file and add, at minimum, the following:

    CC=<location of your gcc>
    FC=<location of your fortran compiler, presumably>

    There may be additional steps with relation to the flags or other steps that may also need to be edited.

    I would recommend getting in contact with someone else who has done a Mac compile of this software and asking if you can use their makefile, as the idea that you tried to run g++ on a Makefile would seem to point to you being very unfamiliar with this method of building.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    A bit more direct than my approach, but basically what I was asking. ;)

    NOTE: At least on my Macs CC is already defined by default as a link in /usr/bin so it doesn't actually need to be explicitly defined.

    Macs don't come with FORTRAN though, so you will need to have some FORTRAN compiler available to build this project. See e.g. http://forums.macrumors.com/showthread.php?t=851518

    B
     

Share This Page