Bug Python binding x64 / Windows 7 (Bug #3059)


Added by michel vidal-naquet almost 12 years ago. Updated over 11 years ago.


Status:Done Start date:2013-05-30
Priority:Normal Due date:
Assignee:michel vidal-naquet % Done:

0%

Category:python bindings
Target version:-
Affected version:branch 'master' (2.9) Operating System:Windows
Difficulty: HW Platform:Any
Pull request:

Description

I compiled OpenCV 2.4.9 on x64 / Windows 7, with Visual Studio 2012.

To use the python binding I copied cv2.pyd in the proper place on the python path, and then got the following error upon import :

>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initcv2)

I traced the bug back to cv2.cpp, and can make the code work by hard coding the declaration for the dll export:

I replaced
extern "C" CV_EXPORTS void initcv2();
by
extern "C" __declspec(dllexport) void initcv2();

This seems to mean there is a problem with the definition of CV_EXPORTS .


Related issues

duplicated by Bug #3170: opencv does not work in Python 2.7 Done 2013-07-23

History

Updated by Alexander Smorkalov almost 12 years ago

  • Category set to python bindings

Updated by Daniil Osokin almost 12 years ago

Hi, Michel!
Please, could you submit a pull request with bugfix (http://code.opencv.org/projects/opencv/wiki/How_to_contribute)?

  • Assignee set to michel vidal-naquet

Updated by michel vidal-naquet over 11 years ago

Daniil Osokin wrote:

Hi, Michel!
Please, could you submit a pull request with bugfix (http://code.opencv.org/projects/opencv/wiki/How_to_contribute)?

Hi Daniil, I am not sure I have a good solution yet, but I'll try to find something within the next week or so and if I do, I will submit a pull request.

Updated by be rak over 11 years ago

same problem here, today's pull (master)

the behaviour of CV_EXPORTS is dependant on another preprocessor-flag,

  • if CVAPI_EXPORTS is defined, CV_EXPORTS resolves to 'extern "C" __declspec(dllexport)'
  • if it is absent, CV_EXPORTS is an empty statement.

unfortunately, the cmake-generator does not generate a CVAPI_EXPORTS define, but another flag, called python_opencv_EXPORTS.

no idea, what this is for, it's never used/referenced in the codebase

imho, the fix would be, to generate a CVAPI_EXPORTS define instead of python_opencv_EXPORTS.

(shame on me, not enough cmake-fu to fix it myself)

Updated by Alexander Mordvintsev over 11 years ago

  • Status changed from Open to Done
  • HW Platform set to Any
  • Operating System set to Windows
  • Affected version changed from branch 'master' (2.4.9) to branch 'master' (2.9)

Also available in: Atom PDF