Sign in to follow this  
tonyaim83

Problem in creating Dll file

Recommended Posts

Hi My current editor is Dev-Cpp 4.9.2.2 .My test program which runs fine looks like dll.h [code=c++] #include <windows.h> #include <stdio.h> #include <stdlib.h> #ifdef __cplusplus extern "C" { #endif __declspec(dllexport) void HelloWorld(); #ifdef __cplusplus } #endif [/code] And dll.cpp [code=c++] #include"dll.h" void HelloWorld () { MessageBox (0, "This is a sample application!\n", "Hi", MB_ICONINFORMATION); } [/code] This code runs fine. Now i tried the same thing with my program where i'm using boostlib. so my dll.h changed to [code=c++] /*List of header files */ using namespace boost; using namespace std; //Contains vertex properties of a graph struct Vertex_Prop { string name; }; //Contains edge properties of a graph struct Edge_Prop { int weight; }; typedef graph_traits <adjacency_list<> >::vertex_descriptor Vertex; struct Graph_Prop { std::map<string,Vertex> nodes; }; typedef adjacency_list <setS, vecS, bidirectionalS, Vertex_Prop, Edge_Prop,Graph_Prop > Graph; [B]#ifdef __cplusplus extern "C" { #endif __declspec(dllexport) int CreateGraph(Graph &g); #ifdef __cplusplus } #endif [/B] [/code] This code gives a linking error. Even if you are not well versed with boost i just want to know what is the correct way to write code for bold part if i want to create a dll of this. The above code is running fine when i have created exe or a console application for this. Where in the header i have simply declared the function without any __declspec(dllexport). Kindly help

Share this post


Link to post
Share on other sites
While this doesn't answer your question; it's a really bad idea to share STL objects across a DLL boundary like that. The EXE and DLL might use different heaps, meaning you could get random crashes inside [de]allocation functions in STL code. It also means that the EXE and the DLL must use the exact same STL version and compiler, or it'll all blow up. If you're using boost, then both the DLL and EXE will need to use the same boost version too.

It's a better idea to wrap up functionality completely in the DLL, so you never expose the STL or boost innards to the EXE, and instead handle it all with accessors on the Graph class.

I'm not saying it's impossible, but it's likely to cause some headaches at some point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this