-
linking to my own DLL
Oddly, I've always linked to other peoples DLLs and never my own. Now, I want to link to my own DLL, and I don't know why I can't.
I created the DLL with code::blocks and I'm linking to the .a file code::blocks outputs. I also have a header with all the functions the DLL has. The functions are showing up in the auto complete, but when I try to compile, any function in the DLL gives an error saying that it was not declared.
What do I need to do to get this working?
-
Code::blocks probably gets the prototypes from the header, so that is trivial information. Are your exports done properly? Is it a run-time error, or a linker error?
-
I get: "ld.exe cannot find -l"nameoflib.
-
what is the name of your .a file?
-
-
You need to be doing -lYsound. I am not sure how you specifically tell Code::blocks what which library to link in. But on whatever menu just tell it Ysound, not some exact file name.
-
It says the same thing. "ld.exe cannot find -lYsound." Do I have to have a lib file? All the other DLLs need to link to .libs, but Code::blocks doesn't give .lib files with the DLLs it compiles.
-
It could be a .lib. Or it could be a .a. They are funcitonally the same thing. Check your library include paths. What compiler are you running? gcc?
-
It is linking to the file that I want and including the header that I want. I'm using GCC.
Am I doing something wrong in the DLL?
Code:
// dll cpp file
#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT int foo(){ return 1; }
Code:
// header
int foo();
-
Ah ok. You need to move that #define to your header and put the DLLEXPORT in the prototype.
-
Hm, I figured I probably did something wrong. However, it still cannot find -lYsound. I think I need a lib file.
-
ok... then rename your .a file to .lib. If that will make you happy :) Just don't forget to change your header to
Code:
#ifdef DLL_BUILD
# define DLLEXPORT extern "C" __declspec(dllexport)
#else
# define DLLEXPORT extern "C" __declspec(dllimport)
#endif
DLLEXPORT int foo();
-
I'm still getting the same error. I get this any time I try to link to a dll I compiled with code::blocks to another project I'm compiling in code::blocks. Do I need to link to anything else other than that lib file?
-
Ok lets be PERFECTLY straight on this.
When you build the DLL you need to put -DDLL_BUILD=1 in your command line. When you are building your project that uses the DLL, you do not put that.
You probably need to recompile your DLL.
-
Well, it is working now, but I don't know why. I originally moved the files from where code::blocks had compiled them to the directory of the DLL I am currently working on. When I linked to the file there it couldn't find it. I moved them back to where code::blocks compiled it and linked to it from there and it worked. 0.o
Thank you.