How to include a "custom" library in Code::Blocks? (Windows 7)

3.8k views Asked by At

Ok, I've never did this before and I'm having problems to understand how it works (Especially the "include" part). Here's my code:

#include <joypp1.02/app.h>
#include <joypp1.02/objects.h>

void event_plot()
{
    if (App::event_type() == ALLEGRO_EVENT_DISPLAY_CLOSE)
    {
        App::shut_down();
    }
    if (App::event_type() == ALLEGRO_EVENT_KEY_DOWN)
    {
        if (App::event().keyboard.keycode == ALLEGRO_KEY_ESCAPE)
        {
            App::shut_down();
        }
        if (App::event().keyboard.keycode == ALLEGRO_KEY_ENTER)
        {
            cout << "Whatever! ";
        }
    }
}

void visual_plot()
{
    static Image x("sample.png");
    x.draw();
}

int main(int argc, char **argv)
{
    App app(800, 600);
    app.set_background_color(200, 0, 0);
    app.add_event_scene(Scene("Event Plot", event_plot));
    app.add_visual_scene(Scene("Visual Plot", visual_plot));
    app.run();
    return 0;
}

joypp1.02 is the dynamic-link library I've compiled, and it's in its own "output" folder (Together with the import file):

enter image description here

joypp1.02 has only two headers: app.h e objects.h. How do I import them? The library is in the linker (I want to keep it in the output folder of the library, because It's in constant development. BUT, I want to compile it only as a DLL, so I have a separate project that uses the DLL).

enter image description here

And the folder with the joypp1.02.dll is in the Search Directories of the compiler.

enter image description here

And if I try to include like this:

#include "joypp1.02.h"

I get:

fatal error: joypp1.02.h: No such file or directory

So, I'm lost. How to include a "custom" library in Code::Blocks in Windows? How do I know the include name? Why it's a header like "joypp1.02.h" if it's a .a file?

Disclaimer: I've used the word "custom" to emphasize that it was written and compiled by me (So, probably more problems than just importing some "official" and "pro" one).

1

There are 1 answers

0
Ericson Willians On

Well, I've solved it. I was missing the point of the actual function of a dynamic-link library. I was forgetting to include the header files (And I've remembered from other libraries that, indeed, I include their .h files apart from the .a or .lib import library files, and the binary .dll(s) (I thought they were inside the import library file or something, and that only the import library and .dll were required)).

So you, possible reader from the future, in face of the same problem: Hear me! You must make the header files of your library visible to the compiler (Include in the "search directories", in the compiler tab in Code::Blocks), and at the same time, link the import library .a or .lib file, AND, if no search directory is specified under the linker tab, have the .dll binary in the folder of your application.

If by any means, you're still lost, read this:

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(errors)#Q:_What_do_I_need_to_know_when_using_3rd_party_libs.3F