Compiling a PHP extension with OpenCV in Visual Studio 2017 RRS feed

  • Question

  • I've been successfully developing several PHP extensions for data processing both on Windows and Linux. In addition to that, I have many OpenCV projects on both operating systems fully working.

    Recently I've been trying to create a PHP extension for PHP 7.2 using the official SDK on Windows. I could easily compile it with nmake and it loaded without any problem. Then I compiled an OCR library of my own that uses OpenCV 3.2 and linked it to an exe and it worked too.

    The I try linking the dll of the extension to both the PHP SDK library file and the library I made using OpenCV, but no matter what I try I always get these errors only when I link both libs to the dll:

    1>my_ocr_lib.lib(my_ocr_lib.obj) : error LNK2005: "public: void __cdecl std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QEAAXXZ) already defined in php_my_ocr.obj
    1>my_ocr_lib.lib(my_ocr_lib.obj) : error LNK2005: "public: void __cdecl std::_Container_base12::_Swap_all(struct std::_Container_base12 &)" (?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z) already defined in php_my_ocr.obj
    1>my_ocr_lib.lib(my_ocr_lib.obj) : error LNK2005: "void * __cdecl std::_Allocate(unsigned __int64,unsigned __int64,bool)" (?_Allocate@std@@YAPEAX_K0_N@Z) already defined in php_my_ocr.obj
    1>my_ocr_lib.lib(my_ocr_lib.obj) : error LNK2005: "void __cdecl std::_Deallocate(void *,unsigned __int64,unsigned __int64)" (?_Deallocate@std@@YAXPEAX_K1@Z) already defined in php_my_ocr.obj
    1>   Creating library C:/cpp/my_ocr/build/Debug/php_my_ocr.lib and object C:/cpp/my_ocr/build/Debug/php_my_ocr.exp
    1>C:\cpp\my_ocr\build\Debug\php_my_ocr.dll : fatal error LNK1169: one or more multiply defined symbols found /MDd flag

    Any suggestions?

    • Moved by Baron Bi Wednesday, August 23, 2017 5:46 AM Third party issues
    Wednesday, August 2, 2017 3:41 AM

All replies

  • Hi Ahmed Yarub,

    thanks for posting here.

    >>Compiling a PHP extension with OpenCV in Visual Studio 2017

    This error means the given symbol, displays in its decorated form, is multiply defined. For this case, I suggest you check these things below.

    1. Check if the symbols are defined differently in two member objects in different libraries, and both member objects are used.

    2. Check if you mix the static and dynamic libraries.

    3. Check if rebuilding your OCR library could be help.

    This forum is about c++ development with Microsoft products. For your case, I suggest you post on OpenCV forum for better support.

    Your understanding and cooperation will be grateful.

    Best Regards,
    Sera Yu

    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href=""></a>.

    Thursday, August 3, 2017 7:32 AM
  • thank you Yu

    it worked when compiled as Release, so at least I have a clue now

    I think that the first mentioned is relevant

    I've already asked on the OpenCV forum and they closed the topic because this is not a bug in OpenCV itself!

    Thursday, August 3, 2017 11:08 AM