2

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!

Giulia
  • 297
  • 1
  • 2
  • 11

2 Answers2

1

The problem is that currently (Nov. 2016) the compilation of gsl as a shared library is deactivated in mxe. That is why your linker cannot find the references to these functions and you get this error.

You can now either compile gsl yourself using the mxe cross compiler or activate the shared build (look at src/gsl.mk in the mxe source code).

Since I need gsl for my own project I tried to enable the shared build in a pull request to mxe (https://github.com/mxe/mxe/pull/1568). You could try your luck with this modification, it did work for me.

Daniel
  • 112
  • 1
  • 8
0

To diganose, I would suggest the following

  1. Provide complete 'build dump' of the actual compiler being called and the flags being called

  2. provide complete error log

  3. use some binary exploration tools like 'objdump' (perhaps it will be under the mingw folder built by MXE under something like 'i686-pc-mingw32-objdump') to peer into the libraries you have built and see if they contain the missing symbols.

in other words, if you built a library that should have the `_gsl_matrix_alloc' function inside of it, then look at the library you built to make sure it is there. if you dont know which library should contain that function, then do some shell work to search all the libraries looking for that symbol name.

Yes, a build system like cmake or qmake would probably make things easier, although every time you use a build system you will have to learn a great deal about the build system first.

Lastly, what might help you the most, is to find another program out there that uses the same libraries as yours, and that you know cross-compiles to windows, and then copy what they did. A good source of such programs is to go to mxe.cc and look at the 'projects using mxe' list in their webpages, and see if any of them use GSL, then see how they did it. Another way to find projects is to look for open source projects using GSL and see if they advertise windows binary downloads on their main webpage. If so, its probable they are using cross compilation.

good luck!

don bright
  • 1,113
  • 1
  • 11
  • 15