我有一個在Linux上開發的C++項目,我想通過給他們的可執行文件傳遞給我的Windows用戶同事。使用MXE在Linux上進行交叉編譯 - GSL鏈接?
我搜索了這個問題,發現有一種方法可以通過使用i586-mingw32msvc-g++
而不是g++
進行編譯。我也明白這個解決方案會解決需要重建的鏈接庫的問題,我希望通過使用MXE腳本(http://mxe.cc/)來解決這個問題。
我的Makefile(我在這個新的建議,歡迎):
#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 [email protected] $(LDLIBS)
.cpp.o:
$(CC) $(CFLAGS) -c $<
clean:
rm *.o main_simple.exe ./Output/* ./Output/*/* ./Output/*/*/*
如果我嘗試make
我得到像一堆GSL相關的錯誤:
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
這是否意味着編譯器真的找到了我認爲我已經與MXE交叉構建的庫?我能做什麼?
或者,cmake
會是一個更清潔的解決方案嗎?我可以用它從我的Linux機器創建一個.exe
文件嗎?或者在這種情況下,我應該讓我的同事們在他們的機器上重新編譯?
謝謝你給我的任何幫助!
我檢查並提交已合併,很好! – crobar 2017-06-20 13:52:17