Can you remind me of how to make linking between C++ and C++/CLI?
I have it like this:
"hashtable" is a native code file with header where i do sample BIG RAM allocation, it compiles ok.
"BPSW" is mixed code file with header, which I use as glue between native and managed code. It compiled ok before I referenced native function Allocate();
Also, managed and native files have their precompiled header files (assume they were just autogenerated).
Hashtable.h
#include <vector>
#include <iostream>
using namespace std;
namespace Allocation
{
void Allocate();
}
Hashtable.cpp
#include "stdafx.h"
#include "Hashtable.h"
namespace Allocation
{
void Allocate()
{
// test RAM allocation in native code
vector<int>* v = new vector<int>( 250 * 1000000 );
cout << "Ready" << endl;
int a;
cin >> a;
delete v;
}
}
BPSW.hxx
#pragma once
#pragma unmanaged
#include <vector>
#pragma managed
namespace BPSW
{
public value class Wrapper
{
public:
static void AllocateHashtable();
};
}
BPSW.cxx
#pragma once
#pragma unmanaged
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include "../Hashtable/Hashtable.h"
using namespace std;
#pragma managed
#using <System.dll>
#include "BPSW.hxx"
//namespace Allocation
//{
// void Allocate();
//}
namespace BPSW
{
// some more code
// not interesting here
void Wrapper::AllocateHashtable()
{
::Allocation::Allocate();
}
}
Build log looks like this:
1>------ Build started: Project: Hashtable, Configuration: Debug Win32 ------
1> Hashtable.cpp
1> Hashtable.vcxproj -> C:\Users\Denis\documents\visual studio 2010\Projects\NivalApp\Debug\Hashtable.dll
2>------ Build started: Project: BPSW, Configuration: Debug Win32 ------
2>BPSW.obj : error LNK2028: unresolved token (0A000327) "void __cdecl Allocation::Allocate(void)" (?Allocate@Allocation@@$$FYAXXZ) referenced in function "public: static void __clrcall BPSW::Wrapper::AllocateHashtable(void)" (?AllocateHashtable@Wrapper@BPSW@@$$FSMXXZ)
2>BPSW.obj : error LNK2019: unresolved external symbol "void __cdecl Allocation::Allocate(void)" (?Allocate@Allocation@@$$FYAXXZ) referenced in function "public: static void __clrcall BPSW::Wrapper::AllocateHashtable(void)" (?AllocateHashtable@Wrapper@BPSW@@$$FSMXXZ)
2>C:\Users\Denis\documents\visual studio 2010\Projects\NivalApp\Debug\BPSW.dll : fatal error LNK1120: 2 unresolved externals
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========