Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C code for Windows 64 [closed]

Tags:

c

makefile

I haven't touched C for years but need to compile some C source code for Windows 7 64. The source comes with a makefile. Can someone please recommend a C compiler with make?

PS:

The make file:

POSTFIX="_amd64"
CC = CC="cc -Wall"
RANLIB=RANLIB="ranlib"
INSTALLDIR=/usr/local/bin
LIBINSTALLDIR=/usr/local/lib

VERSION=4.12
DATE=10/10/10

PROGRAMS=bib2xml ris2xml end2xml endx2xml med2xml isi2xml copac2xml \
    biblatex2xml ebi2xml wordbib2xml \
    xml2ads xml2bib xml2end xml2isi xml2ris xml2wordbib modsclean

all : FORCE
    cd lib; make -k $(CC) -k $(RANLIB); cd ..
    cd bin; make -k $(CC) -k VERSION="$(VERSION)" -k DATE="$(DATE)"; cd ..

clean: FORCE
    cd lib     ; make clean ; cd ..
    cd bin     ; make clean ; cd ..
    cd test    ; make clean ; cd ..

realclean: FORCE
    cd lib     ; make realclean ; cd ..
    cd bin     ; make realclean ; cd ..
    cd test    ; make realclean ; cd ..
    rm -rf update lib/bibutils.pc

test: all FORCE
    cd lib    ; make test; cd ..
    cd bin    ; make test; cd ..

install: all FORCE
    cd lib ; make -k LIBINSTALLDIR=$(LIBINSTALLDIR) install; cd ..
    sed 's/VERSION/${VERSION}/g' packageconfig_start > lib/bibutils.pc
    @for p in ${PROGRAMS}; \
        do ( cp bin/$$p ${INSTALLDIR}/$$p ); \
    done

package: all FORCE
    csh -f maketgz.csh ${VERSION} ${POSTFIX}

deb: all FORCE
    csh -f makedeb.csh ${VERSION} ${POSTFIX}

FORCE:
like image 402
cs0815 Avatar asked May 12 '11 13:05

cs0815


1 Answers

Since everyone here is oblivious to your clear 64-bit statement, I'll give a correct answer:

  1. If the makefile is an Nmake makefile, you can install the Visual Studio Express for Windows Desktop, open a command prompt from the start menu (choose the one targetting 64-bit Windows), cd to your project's directory, and run nmake. You'll need to modify the makefile to call cl and link.

  2. If the Makefile is a MinGW makefile, you will need mingw-w64's toolchains targetting Win64 (note also 32-bit toolchains are provided). I recommend the official builds provided through an installer or the ones installable from MSYS2 (see point 3). Install, open the MinGW-w64 command prompt, cd to your projects directory, and run mingw32-make.

  3. If the Makefile is a Unix/MSYS makefile, I suggest using MSYS2. You can use the above toolchain, or do pacman -S mingw-w64-x86_64-gcc to install a toolchain from the MSYS2 shell. Be sure to either add /mingw64/bin to PATH or launch from the "MSYS2 MinGW-w64 64-bit" shortcut to use it. Note you can use MSYS2 as a package management tool only: install any dependency you want (there are tons of 3rd party library binaries ready for use) and just add the <MSYS2 root>/mingw64/bin directory to PATH and call the compiler from anywhere.

  4. If the project uses Unix functionality (like fork() or other Unix system calls), you can use 64-bit Cygwin, install its compiler, and link with the Cygwin dll. This is not recommended as there is a performance (well, relative to porting the code to Win32 APIs) and license penalty (The Cygwin DLL is GPL, which forces your program to be licensed in a GPL-compatible way).

These are four ways of compiling a C source file for 64-bit Windows with free tools. If you are a student, you can probably use the following ways as well:

  1. Download Visual Studio Professional from Dreamspark (if your university/college/school has an agreement with Microsoft for this) and use that. Pretty much equivalent to point 1 except if you use stuff like MFC/ATL and/or VS plugins, which don't work in the express version.

  2. Download the Intel compiler from their Education offerings website. Requires Visual Studio Professional from point 5 though. You'll need to modify the Makefile to use the Intel compiler though.

  3. Download the LLVM/Clang compiler from here (the Windows snapshot builds) and use it in conjunction with point 5. You'll need to modify the makefile to call clang.

I know this is more than what you asked for, but my high-rated answers need to be complete, right?

like image 193
rubenvb Avatar answered Sep 22 '22 07:09

rubenvb