I have a C++ project developed on Linux that I would like to pass to my Windows-user colleagues by giving them the executable file.
I searched into the problem and found that one way could be to compile by using i586-mingw32msvc-g++
instead of g++
. I also understood that this solution would trail the problem of linked libraries that need to be rebuilt, I hoped to solve this by using the MXE script (http://mxe.cc/).
My makefile is (I'm new at this, suggestions are welcome):
#main.make
CC = i586-mingw32msvc-g++
CFLAGS = -Wall -O2
LDFLAGS =
SOURCES = <list of cpp files>
LDLIBS = -L/usr/i586-mingw32msvc/lib/ -llapack -lblas -lgsl -lgslcblas -lm -lmingw32
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE = main_simple.exe
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)
.cpp.o:
$(CC) $(CFLAGS) -c $<
clean:
rm *.o main_simple.exe ./Output/* ./Output/*/* ./Output/*/*/*
If I try to make
I get a bunch of gsl-related errors like:
utilities.o:utilities.cpp:(.text+0x2d1): undefined reference to `_gsl_matrix_alloc'
utilities.o:utilities.cpp:(.text+0x2dc): undefined reference to `_gsl_vector_alloc'
....
utilities.o:utilities.cpp:(.text+0x42e): undefined reference to `_gsl_matrix_free'
utilities.o:utilities.cpp:(.text+0x70f): undefined reference to `_gsl_fit_linear'
utilities.o:utilities.cpp:(.text+0x722): undefined reference to `_gsl_stats_correlation'
collect2: ld returned 1 exit status
Does this mean that the compiler really find the libraries I thought I had cross-built with MXE? What can I do?
Alternatively, would cmake
be a cleaner solution? Can I use it to create an .exe
file from my Linux machine? Or in that case I should ask my colleagues to recompile on their machine?
Thank you for any help you can give me!