Calling a static library function from another dynamic link library project


Keywords:c++ 


Question: 

I have a static library and it has a class like below in its header file:

namespace MyNameSpace
{
    class MyClass
    {
    public:
        void Something();
    };
}

I linked above static library with my another dynamic link library project, and now I can call above function like below:

int Main()
{
    MyNameSpace::MyClass A;
    A.Something();
}

Although above works fine, I like to use my static library function like below, instead declaring classes:

int Main()
{
    MyNameSpace::Something();
}

But I am wondering about the correct way to do this.

I tried it in static library like:

namespace MyNameSpace
{
    void Something();
}

and after linking static library to the dynamic library, tried to use the function in it like:

MyNameSpace::Something();

But, IntelliSense doesn't see it and I already included my static library's header file and linked it properly.

What I want to do is declare a function in a static library outside classes and make it visible to another projects whose it linked into. In this case, to dynamic library.

Thanks in Advance.


1 Answer: 

I was finally able to do what I want by declaring the function like below:

In Static Library:

namespace MyNameSpace
{
    void Something();
}

In Dynamic Link Library:

MeNameSpace::Something();

Now the function is visible even outside file scope.