views:

421

answers:

1

I'm using code::blocks on a linux system with the gcc compiler, and I want to be able to use the shared library template to make a shared library with classes, then make another project that accesses that shared library(at compile time, not dynamically) and classes. I'm sure that code::blocks has simple way of doing this without making custom makefiles and manually setting link options, but I don't know how. How do I do this.

Thanks

ps(please stick to the question).

Example of what I want to do

Shared Library

sl.h

class clsClass
{
    public:
    static bool bolReturnTrue(char * chWhatever);
};

sl.cpp

bool clsClass::bolReturnTrue(char * chWhatever)
{
    return true;
}

Program Accessing Shared Library

main.cpp

int main(int argc, char * argv[])
{
    bool Face = clsClass::bolReturnTrue(argv[0]);
    if(Face)
    {
        printf("True.\n");
    }
    else
    {
        printf("False.\n");
    }
    return 0;
}
A: 

You can have more then one project in your workspace and set project dependencies, there are no custom makefiles needed.

The basic steps with Code::Blocks are the following:

  • make sure your shared library project generates an import library (project properties->build targets)
  • make the shared lib project a dependency of the project in question (project settings->project dependencies)
  • link to the import library
  • include your shared libraries headers in the relevant source files
Georg Fritzsche
doesn't seem to work
kelton52
Could you be less specific? ;) By the way, i tested it before posting.
Georg Fritzsche
it just won't link, no matter where I add a reference to the library.
kelton52
Maybe you are trying to link the dll? You should link to the import library instead (per default .a in code::blocks i believe), it will load the dll for you etc.
Georg Fritzsche