0

I am using Windows Vista, and have downloaded a folder of files in C++ with a Makefile. I would like to run the makefile to compile the source files with header files under Windows. In the end I would like to be able to call this C++ function from MATLAB's command prompt afterwards, so I assume that if I use cygwin this will not be possible because it only allows the compilation to be run from within cygwin.

I installed the Windows SDK 7.1 and from its commond prompt moved into the directory where the makefile and source lies and nmake -f Makefile and got the response Makefile(13) : fatal error U1001: syntax error : illegal character '^' in macro Stop. I installed visual studio express 2010 and from its command prompt tried the same. Thes functions are widely known and have been used from here - link to page hosting the c++ files. So I doubt that there is an error with the functions themselves.

How can I run the makefile to compile these files and subsequently run them?

EDIT: this is the makefile:

#!/bin/bash
CC=g++
CFLAGS= -ansi -O5 -Wall
LDFLAGS= -ansi -lm -Wall
EXEC=community convert hierarchy
OBJ1= graph_binary.o community.o
OBJ2= graph.o
all: $(EXEC)
community : $(OBJ1) main_community.o
$(CC) -o $@ $^ $(LDFLAGS)
convert : $(OBJ2) main_convert.o
$(CC) -o $@ $^ $(LDFLAGS)
hierarchy : main_hierarchy.o
$(CC) -o $@ $^ $(LDFLAGS)
##########################################
# Generic rules
##########################################
%.o: %.cpp %.h
$(CC) -o $@ -c $< $(CFLAGS)
%.o: %.cpp
$(CC) -o $@ -c $< $(CFLAGS)
clean:
rm -f *.o *~ $(EXEC)

EDIT2: I installed make from gnu and this is the output: Here is the dir

09/04/2013  17:13    <DIR>          .
09/04/2013  17:13    <DIR>          ..
24/09/2008  13:45             7,742 community.cpp
10/07/2008  13:41             4,386 community.h
10/07/2008  13:41             3,919 graph.cpp
10/07/2008  13:41             1,329 graph.h
10/07/2008  13:41             5,957 graph_binary.cpp
10/07/2008  13:41             3,434 graph_binary.h
23/07/2008  17:08             4,071 main_community.cpp 
10/07/2008  13:41             2,110 main_convert.cpp
10/07/2008  13:41             3,449 main_hierarchy.cpp
10/07/2008  13:43               565 Makefile
23/07/2008  17:13             2,959 readme.txt
09/04/2013  17:13    <DIR>          sample_networks
              11 File(s)         39,921 bytes
               3 Dir(s)  25,152,544,768 bytes free

And running the make -f Makefile gives:

g+++ -o graph_binary.o -c graph_binary.cpp -ansi -05 -Wall
process_begin: CreateProcess(NULL, g++ -o graph_binary.o -c graph_binary.cpp -ansi -05 -Wall, ...) failed. 
make (e=2): The system cannot find the file specified.
make: *** [graph_binary.o] Error 2

but these files are listed in the dir so I do not know why there is an error.

Vass
  • 2,682
  • 13
  • 41
  • 60
  • I believe GNU `make` and Microsoft `nmake` require slightly different syntax in makefiles. – lapk Apr 10 '13 at 09:33
  • 2
    You could try compiling with mingw – user657267 Apr 10 '13 at 09:38
  • 2
    Mind you, that the Makefile as such might not be your biggest problem. Makesfiles usually contain lots of command and calls to other (external) tools, like the compiler, linker, archiver, various _UNIX_ command line utilities, etc. Also, the default shell, that `make` expects is the Bourne shell (`sh`). So all in all there is whole "toolchain" that you usually need to make this happen. Without Cygwin or another package that contains your "typical slew" of UNIX tools, you probably won't get very far. You might want to post your Makefile here, so we can see if this endeavor is feasible. – Christian.K Apr 10 '13 at 09:40
  • @Christian.K, I added the **makefile** for you to see, thanks – Vass Apr 10 '13 at 09:45
  • I think you can still run the makefile with cygwin, but the compiler and linker set to the MSVC ones. The generated code will have nothing to do with cygwin. – Min Lin Apr 10 '13 at 09:55
  • @MinLin, so I can just use cygwin and I can run it as if compiled under Windows, and not need cygwin to run it? – Vass Apr 10 '13 at 09:57
  • Yes, but your compiler should be set to CL – Min Lin Apr 10 '13 at 10:00

2 Answers2

1

I don't have idea about C++ function call from MATLAB. But if you want to build using make in windows environment with VC compiler here is the steps.

  1. Install make: go to http://gnuwin32.sourceforge.net/packages/make.htm and download Complete package, except sources and install it according to instruction of the same page.
  2. Set the bin(C:\Program Files (x86)\GnuWin32\bin;) directory path to windows environment variable PATH
  3. restart computer them open command prompt and type make and hit enter. if everything ok then it should shows make: *** No targets specified and no makefile found. Stop.
  4. If everything ok go to make file location using cd command and execute command make -f yourFileName

NOTE: you should have VC compiler already installed. this may hep you to find that

Community
  • 1
  • 1
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
  • Thanks for this, I have completed steps 1-3, for some reason there is a complaint on the list of files available. I have posted it in the EDITS2 in the question above to see the output given by using make. I don't understand why it cannot find the files needed. – Vass Apr 10 '13 at 11:00
  • I found a file for sys/mman.h and created a file for it but it is not found when running make `http://stackoverflow.com/questions/1810568/c-include-sys-mman-h` – Vass Apr 10 '13 at 11:58
  • this works its just that there are dependency issues in the code im trying to compile – Vass Apr 10 '13 at 12:34
1

You can build it with MinGW (Windows port of gcc)

Mingw builds link

inkooboo
  • 2,904
  • 1
  • 19
  • 24