Click to See Complete Forum and Search --> : DLL won't build! Please help!


haroldsoh
September 2nd, 1999, 03:27 AM
Hi, I am trying to write a DLL which contain the quicksort function as an excercise. I can't seem to build this dll. The code for the dll is as follows


// Sort DLL.
////////////

#include <windows.h>

template <class Stype> void qsort(Stype *item, int count);
template <class Stype> void quicksort(Stype *item, int left, int right);

BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{

break;
}

case DLL_PROCESS_DETACH:
{

break;
}

}

return TRUE;

}


//Sort Function : Quicksort Entry function
template <class Stype> void qsort(Stype *item, int count)
{
quicksort(item,0,count-1);
}

//Quicksort Function : Actual Quicksort algorithm
template <class Stype> void quicksort(Stype *item, int left, int right)
{
register int p,q;
Stype x,y;

p = left;
q = right;
x = item[(left+right)/2];

do {

while (item[p] <x && p <right) {
p++;
}

while (item[q] && q>left) {
q--;
}

if (p<=q) {
y = item[p];
item[p] = item[q];
item[q] = y;
p++;
q--;
}

} while (p<=q);

if (left<q) {
quicksort(item, left, q);
}

if (p<right) {
quicksort(item, p, right);
}

}





The DEF file is as follows

;Sort.def
;
; Definition File for Sort.dll

LIBRARY sort

CODE PRELOAD MOVABLE DISCARDABLE
DATA PRELOAD SINGLE

EXPORTS
qsort
quicksort
;end

I get the following error when I try to build the DLL.

--------------------Configuration: Sort - Win32 Release--------------------
Linking...
.\Sort.def : warning LNK4017: CODE statement not supported for the target platform; ignored
.\Sort.def : warning LNK4017: DATA statement not supported for the target platform; ignored
Sort.def : error LNK2001: unresolved external symbol quicksort
Release/Sort.lib : fatal error LNK1120: 1 unresolved externals
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.

Sort.dll - 3 error(s), 2 warning(s)

I would really appreciate any help. Thank you.

Harold Soh

Burlacu Ovidiu
September 2nd, 1999, 03:41 AM
try this:

extern "C" template <class Stype> void qsort(Stype *item, int count);
extern "C" template <class Stype> void quicksort(Stype *item, int left, int right);
//Sort Function : Quicksort Entry function
extern "C" template <class Stype> void qsort(Stype *item, int count)
{
quicksort(item,0,count-1);
}
//Quicksort Function : Actual Quicksort algorithm
extern "C" template <class Stype> void quicksort(Stype *item, int left, int right)
{
//.......
}




Let me know if this help u
Regards,
Ovidiu