first my simple setup:
I’ve got 2 VS2012 projects. Now I want to use classes from Project B in Project A.
I added Project B to A’s project dependencie list and imported the headers where necessary. (e.g. #include”..\src-pool\Coords.h”;).
So far, so good – no compiler errors.
But when I try to build the project, I get some linker errors:
Fehler 1 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall Coords::Coords(double,double)" (??0Coords@@QAE@NN@Z)" in Funktion ""public: void __thiscall TileDownloader::calculateBounds(double *,int)const " (?calculateBounds@TileDownloader@@QBEXPANH@Z)". C:\Users\username\documents\visual studio 2012\Projects\CPPHA\project\TileDownloader.obj
I’m sorry, this is the german version of VS. “Verweis auf nicht aufgelöstes externes Symbol” means: Link to not resolved extern symbol.
Any ideas? =)
Done this (this is a class I want to export and use in the other project)
Coords.h
#pragma once
#include <iostream>
#ifdef EXPORT_MYCLASS
#define MYCLASSEXPORT __declspec(dllexport)
#else
#define MYCLASSEXPORT __declspec(dllimport)
#endif
class MYCLASSEXPORT Coords
{
public:
Coords(double lat, double lon);
~Coords(void);
double getLon() const;
void setLon(double val);
double getLat() const;
void setLat(double val);
void printInfos() const;
private:
double lat, lon;
};
But I get a warning “inconsistent dll export” and the same errors. Sorry, I’m new to C++
and I want to use it like this
#include "..\src-pool\Coords.h"
class TileDownloader
{
public:
TileDownloader(void);
~TileDownloader(void);
void calculateBounds(double* array, int zoomLevel) const;
void downloadTiles() const;
private:
double maxLat, maxLon, minLat, minLon;
};
There are 3 things that need to happen for the linker to find the a class method:
Common practice for declaring an export in a header:
Then you can just define that preprocessor argument in the exporting dll’s preprocessor definitions.
In Visual studio:
Project properties -> Configuration properties -> C/C++ -> Preprocessor -> Prerpocessor deffinitios