Another GSL linking error in Windows

时光毁灭记忆、已成空白 提交于 2019-12-11 21:02:17

问题


I've done everything, and it's payed off. Trying to compile a mex file from MATLAB using the Windows 7.1 SDK.

~ I've created an compiled my C source code on GCC

~ I've created a MEX file that links and compiles fine via GCC on both Linux and OS X. Does not crash MATLAB, gateway function works fine

~ After much confusion, I switched my dev platform form 64-bit to x86 Win7

~ I've found .dll built files, but they do not link. Linking libs in MATLAB using MATLAB's linker flags will default to .lib, so...

~ I've found--after much googling--simple, pre-compiled x86 GSL .lib's and source files and linked them with MATLAB, eliminating any gsl_blas.h-and-it's-dependencies unrecognized external symbol errors

~ I've re-written every single variable declaration in my source code such that it is C89 standard compatible

~ I've set linker flags appropriately to avoid LIBCMT and any other LIB conflicts

~ I've installed the 2010 and 2012 VC C Runtime libraries

~ I've checked to make sure I have msvcrt.dll and msvcp60.dll in my System files

~ I've followed multiple tutorials online on how supposedly link everything together, most of which had nothing broken links or un-replicable results. I didn't find much to go off of for Cygwin or MinGW.

~ I've tried using the Lcc-win32 2.4.1 compiler

If I was doing basic matrix and vector operations, I'd be set, but unfortunately the various decomposition routines I'm utilizing require parts from the cblas library, which I linked as well, but I get ~30 errors all reporting the same thing...

cblas.lib(ctrsv.obj) : error LNK2001: unresolved external symbol __libm_sse2_sqrt_precise 

Here's my MATLAB command.

mex -largeArrayDims -IC:\gsl\include -LC:\gsl\lib -lgsl -lcblas LINKFLAGS="$LINKFLAGS /NODEFAULTLIB:libcmt.lib" file1.c file2.c

So, out of options and frustrated out of my mind, I (naturally) come to stack overflow. Anyone have any idea how to solve this one? The only thing I've foudn on google points to wineHQ errors, not very helpful.

And, if possible, I'd rather not try to compile first on VS201X. I have access to whatever version I need, if necessary, but to me that just seems like a redundant step. Maybe I'm spoiled with Unix-based file system management and linking, though.


回答1:


It's easy to compile the GSL library under MinGW, in fact the process of compiling from sources is exactly identical to that in Linux. Here are the steps I took:

  1. Setup MinGW for Windows. I am using MinGW-w64 but there is also the popular TDM-GCC distribution which comes with a friendly web-installer.

  2. Obtain GSL sources, and extract the tarball (gsl-1.16.tar.gz is the latest as of now)

  3. Compile as usual, I've used the following commands:

    $ ./configure --host=x86_64-w64-mingw32 --prefix=/mingw/local --enable-shared --enable-static
    $ make
    $ make install
    

    It should take several minutes to finish. Maybe you can enable parallel builds to speed up compilation (make -j)

    You'll end up with the necessary files installed in /mingw/local with the usual structure underneath (bin, lib, include).

  4. Finally you can compile an example program with:

    $ export PATH=/mingw/local:$PATH
    $ gcc `gsl-config --cflags` -o main main.c `gsl-config --libs`
    

Of course if you prefer using Visual C++ as compiler, people out there have prepared solutions to build GSL using Visual Studio (either manually created project files, or using a build system like CMake and the like). See this question for such projects.

A third option is using Cygwin.



来源:https://stackoverflow.com/questions/24603065/another-gsl-linking-error-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!