2016-09-13 6 views
1

mingw-w64ツールを使用してLinuxからWindows 64ビット用のC++プロジェクトをコンパイルするにはどうすればいいですか(実際はmingw-w64に基づいてM Cross Environmentを使用していますが、これは問題には関係しません)。私の場合、最終ステップでは、いくつかのサードパーティのコンパイル済みDLLにリンクする必要があります。私は、これらのDLLのソースコードを持っていない、ヘッダーファイルとコンパイルされたバイナリのみ何を使用してコンパイル?私は知りませんが、おそらくVisual Studio。linuxからクロスコンパイルするとサードパーティのDLLにリンクするには?

私がやっていることを正確に説明するために、私はLinuxからMatlabのmexファイルをクロスコンパイルし、Matlabライブラリlibmex.dll、libmx.dll、libmat.dllにリンクする必要があります。しかし、私は質問に答えるためにMatlabの知識は必要ないと思います。

私は、dllから、.defファイルに定義を抽出する必要があることを漠然としています。実際にリンクするには、別のリンクライブラリを作成する必要があります。

私は、次のコマンドを使用していたこれらの手順は、各ライブラリの定義ファイルの最初の作成、の両方を試みてきた。ここで

gendef libmx.dll 

た定義ファイルの抜粋だがlibmx.def

; 
; Definition file of libmx.dll 
; Automatic generated by gendef 
; written by Kai Tietz 2008 
; 
LIBRARY "libmx.dll" 
EXPORTS 
; public: __cdecl <struct mxArray_tag,class Mprotected_mxArray_helper>::<struct mxArray_tag,class Mprotected_mxArray_helper>(class <struct mxArray_tag,class Mprotected_mxArray_helper> const &__ptr64)__ptr64 
[email protected][email protected]@[email protected]@@@[email protected]@@Z 
; public: __cdecl <struct mxArray_tag,class Mprotected_mxArray_helper>::<struct mxArray_tag,class Mprotected_mxArray_helper>(struct mxArray_tag *__ptr64,bool)__ptr64 
[email protected][email protected]@[email protected]@@@[email protected][email protected]@[email protected] 
; public: __cdecl <struct mxArray_tag,class Mprotected_mxArray_helper>::<struct mxArray_tag,class Mprotected_mxArray_helper>(void)__ptr64 
[email protected][email protected]@[email protected]@@@[email protected] 
; public: __cdecl matrix::serialize::Exception::Exception(class matrix::serialize::Exception const &__ptr64)__ptr64 
[email protected]@[email protected]@[email protected]@@Z 
; public: __cdecl matrix::serialize::Exception::Exception(int,__int64)__ptr64 
[email protected]@[email protected]@[email protected][email protected] 
; public: __cdecl matrix::serialize::FailedUCNV::FailedUCNV(class matrix::serialize::FailedUCNV const &__ptr64)__ptr64 
[email protected]@[email protected]@[email protected]@@Z 
; public: __cdecl matrix::serialize::FailedUCNV::FailedUCNV(int,__int64,int)__ptr64 
[email protected]@[email protected]@[email protected][email protected] 
; public: __cdecl Mprotected_mxArray::Mprotected_mxArray(class Mprotected_mxArray const &__ptr64)__ptr64 
[email protected]@[email protected]@@Z 
; public: __cdecl Mprotected_mxArray::Mprotected_mxArray(struct mxArray_tag *__ptr64,bool)__ptr64 
[email protected]@[email protected][email protected]@[email protected] 
; public: __cdecl Mprotected_mxArray::Mprotected_mxArray(void)__ptr64 
[email protected]@[email protected] 
; public: __cdecl RRTableVisitor::RRTableVisitor(class RRTableVisitor const &__ptr64)__ptr64 
[email protected]@[email protected]@@Z 

次に、Mingw hereの指示に基づいてインポートライブラリを作成しようとしました。私はmingwの-W64を使用していますしかし、私のコマンドは、私はこれらのライブラリにリンクされている簡単な例を構築しようとすると、私はエラーを取得し、実際に

しかし
x86_64-w64-mingw32.static-dlltool -d libmx.def -l libmx.a 

ました。 libsをビルドしてリンクするのに使用される実際のコマンドを以下に示します。

/opt/mxe/usr/bin/x86_64-w64-mingw32.static-gcc -c -I/usr/local/MATLAB/R2015a/extern/include -I/usr/local/MATLAB/R2015a/simulink/include -DMATLAB_MEX_FILE -std=c99 -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -I/opt/mxe/usr/bin/include -DMX_COMPAT_32 -O -DNDEBUG "/home/rcrozier/yprime.c" 
/opt/mxe/usr/bin/x86_64-w64-mingw32.static-gcc -O -L/home/rcrozier/Sync/work/matlab_windows_libs/r2013a -L/opt/mxe/usr/bin/lib -pthread -Wl,--version-script,/usr/local/MATLAB/R2015a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -I/usr/local/MATLAB/R2015a/extern/include -o "yprime.mexw64" yprime.o -Wl,-rpath-link -L/home/rcrozier/Sync/work/matlab_windows_libs/r2013a -lmx -lmex -lmat -L/opt/mxe/usr/bin/lib -lm -lstdc++ 

コンパイルステップはOKになりますが、リンクのステップは、次のエラーで失敗します。

yprime.o:yprime.c:(.text+0x53): undefined reference to `mxGetM' 
yprime.o:yprime.c:(.text+0x5f): undefined reference to `mxGetN' 
yprime.o:yprime.c:(.text+0x6b): undefined reference to `mxIsDouble' 
yprime.o:yprime.c:(.text+0x78): undefined reference to `mxIsComplex' 
yprime.o:yprime.c:(.text+0xbe): undefined reference to `mxCreateDoubleMatrix_700' 
yprime.o:yprime.c:(.text+0xca): undefined reference to `mxGetPr' 
yprime.o:yprime.c:(.text+0xd5): undefined reference to `mxGetPr' 
yprime.o:yprime.c:(.text+0xde): undefined reference to `mxGetPr' 
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/4.9.4/../../../../x86_64-w64-mingw32.static/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main': 
/opt/mxe/tmp-gcc-x86_64-w64-mingw32.static/gcc-4.9.4/mingw-w64-v4.0.6/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain' 
collect2: error: ld returned 1 exit status 

私は静的にリンクするには、このコンパイルの結果について満足しています。

私の質問は、LinuxからWindows用のクロスコンパイル時にサードパーティ製のDLLにリンクするためにはどうしたらよいのでしょうか。なぜこの場合リンクするステップが失敗するのでしょうか?

ところで、この特定の例は単純なCファイルの例ですが、実際にはC++ファイルもリンクしたいと考えています。 CおよびC++のビルドプロセスについて混乱することに関連して、私のプロセスで明白な欠陥を指摘してください。

答えて

0

静的ライブラリに変換した3つのライブラリは、Windowsに付属していない他のDLLに依存していないことを確認してください(ワインでdep walker、http://www.dependencywalker.com/で見ることができます)?

私はまた、mexファイルをコンパイルしたいと思っていましたが、Linuxで完全に機能する解決策を見つけることができませんでした。

だから何私がやったことは、単一の独立したとして私のプロジェクトをコンパイル横断dllファイル、最終的にはMATLABからMEXを使用してDLLにリンクするウィンドウ上のMEXファイルの「メイン」をコンパイルすることです。

Windowsコンピュータにアクセスできない場合は、matlabとmingwをワインにインストールしてみてください。

+0

ありがとう、私は最後に解決策を見つけました、最近のmatlabのバージョンではWindows上でmingwをサポートし、クロスコンパイル時にリンクできる適切なライブラリが付属しています。それはまだあなたにとって心苦しいプロセスですが、コンパイラの設定方法を変更しているため、設定したシステムが動作しなくなる可能性があります。私は今すぐビルドするWindows VMを持っており、[buildbot](https://buildbot.net)で自動化することを考えています。私はあなたの答えを調査しようとしますが、それは時間がかかることがあります。 – crobar

関連する問題