mingw-w64
도구를 사용하여 Linux에서 Windows 64 비트 용 C++ 프로젝트를 컴파일하고 싶습니다. (실제로 mingw-w64를 기반으로하는 M Cross Environment을 사용하고 있지만이 질문과 관련이 없습니다.) 필자의 경우 최종 단계에서는 여러 타사 컴파일 링 된 DLL에 연결해야합니다. 나는이 dll의 소스 코드가 없으며 헤더 파일과 컴파일 된 바이너리만을 사용하여 컴파일했다. 잘 모르겠지만 Visual Studio 가능성.리눅스에서 크로스 컴파일 할 때 타사 DLL에 링크하는 방법은 무엇입니까?
정확하게 내가하고있는 것을 설명하기 위해, 나는 리눅스에서 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++
컴파일 단계는 확인을 진행하지만, 연결 단계는 다음과 같은 오류와 함께 실패합니다
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
내가 정적으로 링크 할이 컴파일의 결과에 대한 기쁘게 생각합니다.
제 질문은 리눅스에서 Windows 용 크로스 컴파일을 할 때 제 3 자 dll에 연결하기 위해해야 할 일이 무엇인지, 그리고이 경우 연결 단계가 실패 할 수있는 이유는 무엇입니까?
그러나이 특별한 예제는 간단한 C 파일 예제입니다. 실제로는 C++ 파일을 연결하려고합니다. C 및 C++ 빌드 프로세스에 대해 혼란 스러울 때 내 프로세스에서 명백한 결함을 지적하십시오!
고마워요, 결국 해결책을 찾았습니다. 최근의 matlab 버전은 Windows에서 mingw를 지원하고 크로스 컴파일 할 때 연결할 수있는 적절한 라이브러리를 제공합니다. 그것은 여전히 고통 스럽지만 컴파일러 설정 방법을 바꾸고 있습니다. 설정 한 시스템이 무엇이든 작동을 멈출 수 있습니다. 방금 만든 Windows VM이 있고 [buildbot] (https://buildbot.net)을 사용하여 자동화 할 생각입니다. 나는 당신의 대답을 조사하려고 노력할 것이지만, 그것은 시간이 걸릴 수 있습니다. – crobar