I need following function (from C++ dll) available in C++/CLI
extern "C" _declspec(dllexport) void __stdcall DestroyInstance(CKeyManagerServerApp *ptr);
My try:
[DllImport("KeyManagerServer.dll", CallingConvention=CallingConvention::StdCall)]
void DestroyInstance(CKeyManagerServerApp IntPtr);
The C++/CLI wrapper is compiled with /clr and stdcall (C++ dll also with stdcall)!
I got following errors:
MKeyManagerInterface.obj : error LNK2028: unresolved token (0A000585) "extern "C" void __stdcall DestroyInstance(class CKeyManagerServerApp *)" (?DestroyInstance##$$J14YGXPAVCKeyManagerServerApp###Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" (??1ManagedKeyInterface#MKeyManagerInterface##$$FA$AAM#XZ)
1>MKeyManagerInterface.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall DestroyInstance(class CKeyManagerServerApp *)" (?DestroyInstance##$$J14YGXPAVCKeyManagerServerApp###Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" (??1ManagedKeyInterface#MKeyManagerInterface##$$FA$AAM#XZ)
1>..\Debug\Bin\KeyManagerInterfaceD.dll : fatal error LNK1120: 2 unresolved externals
How can I solve this linker errors?
Thx
You shouldn't need to use P/Invoke from C++/CLI. You should be able to include the usual C/C++ header files that declare the imported function. Just make sure to link your C++/CLI assembly against the export library from the native-code DLL that exports the function in question.
Related
in my current c++ project I need to use avro c++ serializer. Firstly I built boost 1.6.2 and based on it I build via Visual Studio 2015 the Avro-cpp.sln file as it is mentioned in avro relevant site. In my code I'm using the following include files
#include "avro/DataFile.hh"
#include "avro/Compiler.hh"
#include "avro/ValidSchema.hh"
#include "avro/Schema.hh"
#include "avro/Generic.hh"
#include "avro/Specific.hh"
However when I'm trying to build the project I get the following errors
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::syncIfNeeded(void)
error LNK2019: unresolved external symbol "public: __thiscall avro::DataFileWriterBase::DataFileWriterBase(char const *,class avro::ValidSchema const &,unsigned int,enum avro::Codec)"
error LNK2019: unresolved external symbol "public: __thiscall avro::DataFileWriterBase::~DataFileWriterBase(void)" (??1DataFileWriterBase#avro##QAE#XZ) referenced in function "public: void * __thiscall avro::DataFileWriterBase::`scalar deleting destructor'(unsigned int)"
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::close(void)"
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::close(void)"
error LNK2019: unresolved external symbol "void __cdecl avro::compileJsonSchema(class std::basic_istream<char,struct std::char_traits<char> > &,class avro::ValidSchema &)"
error LNK2019: "public: void __thiscall avro::DataFileWriterBase::flush(void)"
I assume that the linker does not find the definition of the the specific classes DataFileWriterBase and compileJsonSchema .Since I'haven't worked with AVRO before I'd like to ask what libraries should I add in order for this problem to be solved? Do I have to insert the relevant cc files in my source code? I also built from Avro-cpp.sln file the avrocpp.dll and the avrocpp_s.dll, included them in my project but the problem remained the same. Does anyone has any idea since I haven't found any hint in either avro site or similar forums.
Hi again these are the new findings
I searched thoroughly and I probably found a possible cause , but I don't know how to move on. The problem seems to be in file Config.hh
#ifndef avro_Config_hh
#define avro_Config_hh
// Windows DLL suport
#ifdef _WIN32
#pragma warning (disable: 4275 4251)
#if defined(AVRO_DYN_LINK)
#ifdef AVRO_SOURCE
# define AVRO_DECL __declspec(dllexport)
#else
# define AVRO_DECL __declspec(dllimport)
#endif // AVRO_SOURCE
#endif // AVRO_DYN_LINK
#endif // _WIN32
#ifndef AVRO_DECL
#define AVRO_DECL
#endif
#endif
I think that AVRO_DYN_LINK is not defined and __declspec(dllexport) is not executed. So AVRO_DECL is defined and even though library lib is build with the function definitions they are exported and the error occur. Do you have any hint on the above analysis?
i was trying to wrap cimg library inside c++/clr and when i try to build it i get a bunch of Link errors.
Error 20 error LNK2028: unresolved token (0A0002AC) "extern "C" int __stdcall DestroyWindow(struct HWND__ *)" (?DestroyWindow##$$J14YGHPAUHWND__###Z) referenced in function "public: void __thiscall cimg_library::CImgDisplay::_desinit_fullscreen(void)" (?_desinit_fullscreen#CImgDisplay#cimg_library##$$FQAEXXZ) c:\Users\serakpc\documents\visual studio 2012\Projects\CimgWrapper\CimgWrapperCLI\Stdafx.obj CimgWrapperCLI
source code in Stdafx.h
#pragma once
#include "cimgheader\CImg.h"
Just including the header isn't enough. If you have a static compiled library, you need to include it in your solution so the linker will be able to find the binary code and produce an executable. If you have source code of the library, you need to include it in the solution and compile it with your own code.
I am having a LNK2028 error when I try to build my C++/CLI dll. I am using a static lib called pano13 in my program, and I am using one method of it. Everything in my program is fine except the one method call I make to the library, where I get these exact two exceptions.
Error 21 error LNK2028: unresolved token (0A00013B) "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
Error 22 error LNK2019: unresolved external symbol "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
I am including the lib file in the project settings, and I even added the #pragma comment statement for including the library, however I am getting this error. I understand that it has to do with the mixing of native and managed C++, however I am not compiling the program with clr/pure, it is being compiled with the default clr compilation of /clr. Anyone have any ideas how to fix it?
By the way, I solved this a WHILE ago, but I should probably say what the issue was. The panotools library is a C library, not a C++ library. I didn't know that C libraries needed the extern C directive to be used in C++. So all I had to do to fix my problem was
extern "C"
{
#include <panorama.h>
}
Where panorama.h is the include file for the panotools C library. I've always wondered what extern C was for and now I finally understand its purpose.
I am having difficulty figuring out my unresolved external errors.
I have 2 different solutions that both share a core project. Solution #1 is called SnapGame and Solution #2 is called SnapEditor. The core project is called SnapCore.
My SnapGame solution is a Win32 application. It compiles, references, and links the SnapCore project with no issues.
The SnapEditor solution is a Windows Forms Application. It compiles and references the SnapCore project. However, it will not link with it properly. I get unresolved external errors any time I try to reference anything from the SnapCore project.
The SnapCore project has some GDI+ support classes. All classes in the SnapCore project are under the SnapCore namespace.
Here is the file Form1.cpp:
#include "stdafx.h"
#include "App.h"
#include "Orient.h"
using namespace SnapCore;
using namespace SnapEdit;
void Form1::Init()
{
SnapCore::Orient orient;
new App();
}
Here are the linker errors I get:
1>Form1.obj : warning LNK4248: unresolved typeref token (01000049) for 'Gdiplus.GpCachedBitmap'; image may not run
1>Form1.obj : error LNK2028: unresolved token (0A000019) "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2028: unresolved token (0A00001A) "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>C:\Work\PC\SnapEdit\SnapEdit\Debug\SnapEdit.exe : fatal error LNK1120: 4 unresolved externals
I can't figure out why my SnapGame solution links with no troubles, but the SnapEditor solution will not.
Any help would be appreciated.
If I understand you right, SnapEditor is a managed application. It can't simply refer to a native library, like SnapCore. Use P/Invoke, or write a managed wrapper.
I'm back to C/C++ after some break.
I've a following problem:
I've a solution where I've several projects (compilable and linkable).
Now I need to add another project to this solution which depends on some sources from other projects.
My new project compiles without any problems (I've added "existing sources" to my project).
the error:
1>Linking...
1>LicenceManager.obj : error LNK2019: unresolved external symbol "int __cdecl saveLic(char *,struct Auth *)" (?saveLic##YAHPADPAUAuth###Z) referenced in function "public: void __thiscall LicenceManager::generateLicence(int,char *)" (?generateLicence#LicenceManager##QAEXHPAD#Z)
1>LicenceManager.obj : error LNK2019: unresolved external symbol "void __cdecl getSysInfo(struct Auth *)" (?getSysInfo##YAXPAUAuth###Z) referenced in function "public: void __thiscall LicenceManager::generateLicence(int,char *)" (?generateLicence#LicenceManager##QAEXHPAD#Z)
Functions saveLic, and getSysInfo are defined in files which I've added to my new project from existing ones. There is object file created during compilation with those functions in target dir, but my LicenceManager class doesn't want to link.
I use some
extern "C" , and #pragma pack
somewhere, but no more fancy stuff. I think every directory, lib and other necessary dependencies are visible in settings for this project.
Thanks for any advice.
Seems like you need to make sure the functions are declared properly as C functions:
#ifdef __cplusplus
extern "C" {
#endif
int saveLic(char *,struct Auth *);
void getSysInfo(struct Auth *);
#ifdef __cplusplus
}
#endif
In a header file included by LicenceManager.cpp.