I've been testing things with multiple project setups where a console application accesses functions from several DLLs.
I thought about how to include the DLLs' headers in the console application. My current implementation is as follows but it's being a headache to manage and even sometimes runs into errors:
- Each DLL project has a folder called "Include"
- The Console application project references the Include folder of each DLL project (as suggested by msdn guide to working with DLLs)
- Each DLL project contains a single header that includes all the headers in that one project
- The console application then #includes these "master headers"
- Every project uses the pre-compiled header "stdafx" and each file #includes it.
It worked out fine until I started overloading operators. I believe the grief is caused by the pre-compiled header somehow, here's and example of my current usage of stdafx:
#define DLL // Found in every DLL, not in the console project
#ifdef DLL
#define DLLEI __declspec(dllexport)
#else
#define DLLEI __declspec(dllimport)
#endif
#include <iostream>
#include <vector>
#include "Include\Engine.h"
using namespace std;
With this I sometimes get some irrelevant random compiler errors that I can hackfix by excluding the header from the "master header" and including the troublemaker separately in the console app.
Suggestions what could be done better?
This article answered quite a few of my questions.
http://www.codeproject.com/Articles/6351/Regular-DLL-Tutor-For-Beginners
__declspec(dllexport)
and__declspec(dllimport)
definitions should be placed in every public Dll include file, or at least in the main Dll public include file, which includes all other files. These definitions should not be instdafx.h
.This is incorrect, every Dll must have unique preprocessor definition. In your case, of one Dll depends on another, it always compiles another Dll functions as
__declspec(dllexport)
Ensure that every header has
#pragma once
in the beginning.Consider using common
Include
directory for all projects.As already mentioned in the comments,
using namespace
can be used only in source files.