Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link error on Windows #3566

Closed
Roottan opened this issue Aug 15, 2014 · 10 comments
Closed

Link error on Windows #3566

Roottan opened this issue Aug 15, 2014 · 10 comments

Comments

@Roottan
Copy link

Roottan commented Aug 15, 2014

When I recomiling and linking the code ,find some error ,like this:

Creating library build\temp.win32-2.7\Release\sklearn\linear_model\sgd_fast.l
ib and object build\temp.win32-2.7\Release\sklearn\linear_model\sgd_fast.exp
sgd_fast.obj : error LNK2019: unresolved external symbol _isfinite referenced in
 function ___pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite
build\lib.win32-2.7\sklearn\linear_model\sgd_fast.pyd : fatal error LNK1120: 1 u
nresolved externals
error: Command "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.e
xe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\P
Cbuild /LIBPATH:build\temp.win32-2.7 /EXPORT:initsgd_fast build\temp.win32-2.7\R
elease\sklearn\linear_model\sgd_fast.obj /OUT:build\lib.win32-2.7\sklearn\linear
_model\sgd_fast.pyd /IMPLIB:build\temp.win32-2.7\Release\sklearn\linear_model\sg
d_fast.lib /MANIFESTFILE:build\temp.win32-2.7\Release\sklearn\linear_model\sgd_f
ast.pyd.manifest" failed with exit status 1120

OS: windows7 64bit
python: 2.7 32bit
VC: 2008 express version

@larsmans larsmans changed the title compiling&linking error Link error on Windows Aug 15, 2014
@ogrisel
Copy link
Member

ogrisel commented Aug 28, 2014

It is probably caused by the fact that we generated the windows wheel against a more recent version of numpy than the one you have installed.

Could you please tell us which version of numpy (and scipy) are installed on your system? Can you please try to upgrade to the latest stable version of numpy and scipy and see if that fixes the problem?

@ogrisel
Copy link
Member

ogrisel commented Aug 28, 2014

I think this is the same problem as #3548 but for Windows.

@ogrisel
Copy link
Member

ogrisel commented Aug 29, 2014

Actually this is not the same problem as #3548 as the issue reported by @Roottan is a compile time problem and not a runtime problem.

I think this is a problem in numpy. I found this issue numpy/numpy#2099 that seems related but was fixed a long time ago in numpy. I can reproduce @Roottan's error when building against the current official numpy 1.8.1 for windows. However I don't have the problem when I build against @cgohlke's numpy from http://www.lfd.uci.edu/~gohlke/pythonlibs/ so it seems that @cgohlke's version of numpy has been patched in some way to workaround this issue.

@ogrisel
Copy link
Member

ogrisel commented Aug 29, 2014

@cournape @asmeurer didn't you encounter a similar issue when building your own scikit-learn package for 32 bit Python on Windows?

@cournape
Copy link
Member

@ogrisel nope. Which binary installer did you use exactly for numpy ?

@cgohlke
Copy link
Contributor

cgohlke commented Aug 29, 2014

I think the issue is that npy_isfinite, used by sgd_fast.pyx, is a macro. The definition of the macro depends on configuration settings in _numpyconfig.h, which is generated when building numpy and depends on the compiler used to build numpy. In this case, if numpy is build with mingw, NPY_HAVE_DECL_ISFINITE is defined in _numpyconfig.h and npy_isfinite(x) is isfinite((x)), which does not work with msvc...

@cournape
Copy link
Member

@cgohlke's analysis is correct. One cannot currently build numpy with one compiler and other extensions with another. It may be fairly hard to fix in numpy.

@ogrisel
Copy link
Member

ogrisel commented Aug 31, 2014

Alright thanks for you analysis @cgohlke and @cournape.

I will just redefine the _isfinite macro in scikit-learn then. @larsmans do you have a suggestion where we should put that? Just in the sgd module or do you want to mutualize those kind of macros in a common project level header file for scikit-learn?

@larsmans
Copy link
Member

I would put it in a little header file next to SGD for now. We can then move that elsewhere if the need arises.

#ifdef _MSC_VER
# include <float.h>
# define isfinite _finite
#else
# include <numpy/npy_math.h>
# define isfinite npy_isfinite
#endif

ogrisel added a commit to ogrisel/scikit-learn that referenced this issue Aug 31, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
@ogrisel
Copy link
Member

ogrisel commented Aug 31, 2014

@larsmans I just saw your comment. I will do what you suggest in #3611.

ogrisel added a commit to ogrisel/scikit-learn that referenced this issue Aug 31, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
ogrisel added a commit to ogrisel/scikit-learn that referenced this issue Aug 31, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
@ogrisel ogrisel closed this as completed in 455f415 Sep 1, 2014
GaelVaroquaux added a commit that referenced this issue Sep 1, 2014
[MRG+1] FIX #3566: redefine isfinite alias in sklearn
ogrisel added a commit that referenced this issue Sep 2, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
kashif pushed a commit to kashif/scikit-learn that referenced this issue Sep 12, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
IssamLaradji pushed a commit to IssamLaradji/scikit-learn that referenced this issue Oct 13, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
IssamLaradji pushed a commit to IssamLaradji/scikit-learn that referenced this issue Oct 13, 2014
SaurabhJha pushed a commit to SaurabhJha/scikit-learn that referenced this issue Oct 15, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
SaurabhJha pushed a commit to SaurabhJha/scikit-learn that referenced this issue Oct 15, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
IssamLaradji pushed a commit to IssamLaradji/scikit-learn that referenced this issue Nov 22, 2014
npy_isfinite from npy_math.h depends on the compiler used to build
numpy. If we build scikit-learn with a different compiler (e.g. MSVC
vs MinGW) this can cause link errors.

Therefore we redefine the isfinite macro in a scikit-learn specific header
file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants