PHP - VS linker errors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PHP - VS linker errors

Allan Haddad
I am new to Swig.  Here's the description of my problem.. Essentially if I add includes to my header I get already defined linker errors.  Files in VS project:

interface.i

%module crypt

%{
#include "crypt.h" 
%}

%include "std_vector.i"
namespace std {
  %template(IntVector) vector<int>;
}
%include "crypt.h"


crypt.h

#pragma once

#include <vector>

class CCrypt
{
public:
    CCrypt();
    virtual ~CCrypt();
    virtual bool EncryptFile(char* sPlainPath, char* sCipherPath, std::vector<int> keys);
};


crypt.cpp

bool EncryptFile(char* sPlainPath, char* sCipherPath, std::vector<int> keys){
  // implementation
};

I run 'swig -c++ -php crypt.i' to generate crypt_wrap.cpp.  I compile all source and generated wrapper code in the project and I get these linker errors:
  
Error 3 error LNK2005: "void __cdecl std::_Init_atomic_counter(unsigned long &,unsigned long)" (?_Init_atomic_counter@std@@YAXAEAKK@Z) already defined in crypt.obj C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 4 error LNK2005: "void __cdecl operator delete(void *,void *)" (??3@YAXPEAX0@Z) already defined in crypt.obj C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 5 error LNK2005: "void * __cdecl operator new(unsigned __int64,void *)" (??2@YAPEAX_KPEAX@Z) already defined in crypt.obj C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 6 error LNK2005: "public: void __cdecl std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QEAAXXZ) already defined in crypt_wrap.obj C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\cryptlib.lib(filters.obj) cqcrypt
Error 7 error LNK2005: "public: void __cdecl std::_Container_base12::_Swap_all(struct std::_Container_base12 &)" (?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z) already defined in crypt_wrap.obj C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\cryptlib.lib(mqueue.obj) cqcrypt
Error 8 error LNK2001: unresolved external symbol "int __cdecl std::_Atomic_compare_exchange_weak_4(unsigned long volatile *,unsigned long *,unsigned long,enum std::memory_order,enum std::memory_order)" (?_Atomic_compare_exchange_weak_4@std@@YAHPECKPEAKKW4memory_order@1@2@Z) C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 9 error LNK2001: unresolved external symbol "unsigned long __cdecl std::_Atomic_fetch_sub_4(unsigned long volatile *,unsigned long,enum std::memory_order)" (?_Atomic_fetch_sub_4@std@@YAKPECKKW4memory_order@1@@Z) C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 10 error LNK2001: unresolved external symbol "unsigned long __cdecl std::_Atomic_load_4(unsigned long volatile *,enum std::memory_order)" (?_Atomic_load_4@std@@YAKPECKW4memory_order@1@@Z) C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 11 error LNK2001: unresolved external symbol "unsigned long __cdecl std::_Atomic_fetch_add_4(unsigned long volatile *,unsigned long,enum std::memory_order)" (?_Atomic_fetch_add_4@std@@YAKPECKKW4memory_order@1@@Z) C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\crypt\crypt_wrap.obj cqcrypt
Error 12 error LNK1120: 4 unresolved externals C:\Users\Allan\Documents\Visual Studio 2013\Projects\crypt\x64\Release\php_cqcrypt.dll cqcrypt

If I redo the interface like this it all works fine (except I would like to use vectors):

crypt.i

%module crypt

%{
#include "crypt.h" 
%}

%include "carrays.i"
%array_class(int, intArray);

%include "crypt.h"


crypt.h

#pragma once

class CCrypt
{
public:
    CCrypt();
    virtual ~CCrypt();
    virtual bool EncryptFile(char* sPlainPath, char* sCipherPath, int* keys);
    virtual bool DecryptFile(char* infile, char* outfile);
};

So the only difference I can see is #include <vector> is tripping this up, but not sure why.

-Allan

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user