dll linking failure

ok, here's the deal, I'm working with a dll I've created that defines a number of classes and inherited functions for use with a command shell. The dll compiles fine, but when I compile the main file, with dll linked at compile time, it gives me the "<class/function name> does not name a type" error, replacing the class/function name with the classes and fucntions that arent being found

Here's the source code for the main file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <ctime>
#include <conio.h>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>

using std::vector;
#ifndef USER 
#define USER current_user
#endif /*USER_DEFINED*/ 

#ifndef L_HOST
	#define L_HOST local_host
#endif /* L_HOST_DEFINED */

#ifndef DEF_TIMEOUT
	#define DEF_TIMEOUT 120000
#endif /* Defalut timeout defined */




cmd start; //not naming a type
cmd loop; //still no type named

int main(void)
{
USER = default_user; //default_user not defined, but should be in the dll
L_HOST = default_host; //same here

	start.login(); //errors due to the dll not being linked
	while(!end)
	{
		loop.parseCmd(loop.prompt(DEF_TIMEOUT)); //same same
		loop.execCmd(); //still
		end = true; //and here too, not defined
	}
	
	system("PAUSE");
}


and here is the source code for the dll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <ctime>
#include <conio.h>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
using std::vector;
#ifndef USER 
#define USER current_user
#endif /*USER_DEFINED*/ 

#ifndef L_HOST
	#define L_HOST local_host
#endif /* L_HOST_DEFINED */

#ifndef DEF_TIMEOUT
	#define DEF_TIMEOUT 120000
#endif /* Defalut timeout defined */

typedef char* user;
typedef char* host;
typedef int timer;



bool end;
timer tmPrompt;
char  _in_pass[50];
user current_user;
host local_host;
host default_host = "Local.host";
user default_user  = "User";
vector <char> console_in(1);
template <class prntclss> void con_out(prntclss &outString);
vector <char> con_in(bool alias) //Console input
{
	int i,j;
	i=1;
	j = 0;
	char ch;
	while(j!=1)
	{
		ch=getch();
		if(ch=='\r')
		{
		j = 1;
		} if(ch=='\b')
		{
			con_out("\b ");
		}
			console_in.push_back(ch);
		if(alias == true)
		{
			con_out("*");
			if(ch=='\b')
		{
			con_out("\b ");
		}
		} else 
		PRINT:
		con_out(ch);
		i++;
	
	}

	return console_in;
}

template <class prntclss> void con_out(prntclss &outString)
{
	std::cout << outString; //todo...fsking find something to replace this...
}


void preout(void)
{
	printf("%s", USER);
	printf( "%s", "@");
	printf("%s", L_HOST);
	printf( "! ");
}


class cmd{

	int _return; 
	public:
		vector<char> prompt(int timeOut)
				{
					//TODO test timer
					for(tmPrompt = 0; tmPrompt <= timeOut+1; tmPrompt++)
					{
					if(tmPrompt==timeOut)
					{
						con_out("Are you still there?");
						tmPrompt = 0;
					}
					preout();
					con_in(false);
					return con_in(false);
					}
				}
		void login()
				{
					preout();
					printf("%s", "Username:");
					con_in(false);
					preout();
					printf("%s", "\nPassword:");
					con_in(true);
				}
		int parseCmd(vector <char> cmdIn)
				{
					//TODO code rest of parse cmd
					con_out("This is a test");
					_return = 0;
				}
		void execCmd(int cmdcode)
				{
					//_return;
					con_out("Again a test");
				}
};


Yes I know that a lot of things go unused, this code isnt nearly complete yet.

I use the mingw command line compiler, and I use this command to link at compile time

gcc -L./ -lcmd main.cpp -o test.exe

exact errors are here:

main.cpp:33: error: `cmd' does not name a type
main.cpp:34: error: `cmd' does not name a type
main.cpp: In function `int main()':
main.cpp:38: error: `current_user' was not declared in this scope
main.cpp:38: error: `default_user' was not declared in this scope
main.cpp:39: error: `local_host' was not declared in this scope
main.cpp:39: error: `default_host' was not declared in this scope
main.cpp:41: error: `start' was not declared in this scope
main.cpp:42: error: `end' was not declared in this scope
main.cpp:44: error: `loop' was not declared in this scope
main.cpp:52:2: warning: no newline at end of file
----------------------


thusly I assume my dll isnt being linked. Both files are saved as .cpp, So if any one can help me understand why they arent being linked?
Last edited on
I have never tried to stuff in C++ classes into a DLL, other than COM dll's, so I am unsure as to the appropriate steps.

However, I can say that I don't see the DLL main entry point (called DllMain()). Besides that, I don't see an #include or #import in your main executable CPP file that references the created DLL. Without any of these, your main executable cannot possibly find your DLL.

Your compiler seems to be very forgiving when compiling DLL's.

Like I said, I have never tried to export pure C++ classes via a DLL, so I am unsure about the right steps. However, a tip: I would start with a static library. If I can get a static library that properly export my classes, then I would attempt DLL.
Thanks webJose.

I was informed by my compiler providers faq that to link the dll i could do so at compile time by using the -L./ -l<dll_name> trigger before the main source. And I succeeded in doing so with a simple program. But now that I'm playing arround with a slightly more complex program...I've failed, I'm quite new to windows programming so dll's a bit foreign to me. Thank you though again for the responce. I will try at your tip.
You have to export your class from the DLL that defines it, and import it into the module that uses it.
Topic archived. No new replies allowed.