Thread: linking to my own DLL

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    137

    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?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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?

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    I get: "ld.exe cannot find -l"nameoflib.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    what is the name of your .a file?

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    libYsound.a

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    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.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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?

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    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();

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ah ok. You need to move that #define to your header and put the DLLEXPORT in the prototype.

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    Hm, I figured I probably did something wrong. However, it still cannot find -lYsound. I think I need a lib file.

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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();

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    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?

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resources on linking to a dll
    By Luciferek in forum C++ Programming
    Replies: 4
    Last Post: 07-30-2008, 11:22 AM
  2. Linking a DLL
    By ThorntonReed in forum C Programming
    Replies: 3
    Last Post: 04-29-2006, 10:00 AM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM