Help Accessing Functions in a Dll
-
Hi, I recently started my first project based around DLLs and have run into a little trouble. I followed this tutorial: http://www.codeguru.com/cpp/cpp/cpp\_mfc/tutorials/article.php/c9855 The code is split up into a header file and a source file. It consists of a namespace, which contains variables and a class. I am linking implicitly. In a test program I can access the variables fine, no problems there, but when I use a function from the class, I get linker errors, eg:
1>ELQTest.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl ELQ::Functions::CreateRot(void)" (?CreateRot@Functions@ELQ@@SA_NXZ) referenced in function _SDL_main
= sin((x-360)*0.017); } } } #include "stdafx.h" #include "ELQDLL.h" #include SDL_Surface *screen; int main(int argc, char *argv[]){ if(ELQ::Functions::CreateRot()) system("PAUSE"); return 0; } Any idea what could be wrong? I've played around with all sorts of combinations of class definitions, export/import symbols etc, yet cannot get this to work. Look forward to your input, Thanks, Nat. PS: Oh, I should say that when I compile the DLL, I get a stream of inconsistency messages, could this be related? "Sir, I protest. I am NOT a merry man!" -
Hi, I recently started my first project based around DLLs and have run into a little trouble. I followed this tutorial: http://www.codeguru.com/cpp/cpp/cpp\_mfc/tutorials/article.php/c9855 The code is split up into a header file and a source file. It consists of a namespace, which contains variables and a class. I am linking implicitly. In a test program I can access the variables fine, no problems there, but when I use a function from the class, I get linker errors, eg:
1>ELQTest.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl ELQ::Functions::CreateRot(void)" (?CreateRot@Functions@ELQ@@SA_NXZ) referenced in function _SDL_main
= sin((x-360)*0.017); } } } #include "stdafx.h" #include "ELQDLL.h" #include SDL_Surface *screen; int main(int argc, char *argv[]){ if(ELQ::Functions::CreateRot()) system("PAUSE"); return 0; } Any idea what could be wrong? I've played around with all sorts of combinations of class definitions, export/import symbols etc, yet cannot get this to work. Look forward to your input, Thanks, Nat. PS: Oh, I should say that when I compile the DLL, I get a stream of inconsistency messages, could this be related? "Sir, I protest. I am NOT a merry man!"Those
extern "C"
statements look wrong - especially as a) you're using namespaces and b) you're enclosing class definitions in them. Now, namespaces and classes are C++ features - they really aren't compatible withextern "C"
, which specifies that the names enclosed by theextern "C"
are exported as undecorated, C names rather than decorated C++ names. BTW - a decorated C++ name is something like?CreateRot@Functions@ELQ@@SA_NXZ
, your missing symbol... So - try removing allextern "C"
things. The only reason forextern "C"
is to export functions compiled with a C++ compiler in a form compatible with C. You're exporting namespaced functions and classes - they will never be compatible with C...Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Those
extern "C"
statements look wrong - especially as a) you're using namespaces and b) you're enclosing class definitions in them. Now, namespaces and classes are C++ features - they really aren't compatible withextern "C"
, which specifies that the names enclosed by theextern "C"
are exported as undecorated, C names rather than decorated C++ names. BTW - a decorated C++ name is something like?CreateRot@Functions@ELQ@@SA_NXZ
, your missing symbol... So - try removing allextern "C"
things. The only reason forextern "C"
is to export functions compiled with a C++ compiler in a form compatible with C. You're exporting namespaced functions and classes - they will never be compatible with C...Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thank you very much! I feel like a total fool now, though. Classes in C?! They should revoke my C++ licence for that. :laugh:
"Sir, I protest. I am NOT a merry man!"
-
Thank you very much! I feel like a total fool now, though. Classes in C?! They should revoke my C++ licence for that. :laugh:
"Sir, I protest. I am NOT a merry man!"
Don't sweat it man - we've all done it one time or another!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p