Question

I two base projects. Proj1.lib and Proj2.exe. Now Proj2.exe is the startup projects and it will invoke Proj1.lib. Now when i will add another Test.lib to my main project, which contains Gtest. Now, to make Gtest to accumulate all the test cases in GTest, we need to call a function from Test.lib and that function name and header file need to be included in Proj2.exe. Then Proj.exe will get compiled and then it will compile Test.lib and then it will execute test cases. But now my requiremnet is not to disturb Proj2.exe. When ever I want I will attach/deachTest.lib or Test2.lib ... and so on.

Below will show, how we are doing it currently.

Proj1.lib

x.c file
y.c file {/*App_Main_function()*/}

Proj2.exe

A.cpp
B.cpp file {/*Call App_Main_function();*/}
AttachTest.cpp {Test_Main();}

Test.lib

Test.cpp
{
    TestMain()
    {/*Body*/
        InitilizeGoogleTest();
        TEST_F(abc, ab)
        {}
    }
}

Tomorrow if there will be more or new test libraries then I have to open AttachTest.cpp file from Proj.exe and add the function name and header files name. Then Proj2.exe will compile again.

But I want now I will keep Proj1.lib and Proj2.exe fix they won't get compile except new Test.lib How to do that,

I have thought of a way to do it as, I will have .xml file, which will have function name. In Proj2.exe, I will have function pointers it will call them at run time. But how to include header file then??

Please help me.

Was it helpful?

Solution

You will need to build Dynamic-Link libraries (DLL) for doing what you want. .lib libraries can't be loaded dynamically.

Below some example code how to use such libraries, from Wikipedia:

#include <windows.h>
#include <stdio.h>

// DLL function signature
typedef double (*importFunction)(double, double);

int main(int argc, char **argv)
{
        importFunction addNumbers;
        double result;
        HINSTANCE hinstLib;

        // Load DLL file
        hinstLib = LoadLibrary(TEXT("Example.dll"));
        if (hinstLib == NULL) {
                printf("ERROR: unable to load DLL\n");
                return 1;
        }

        // Get function pointer
        addNumbers = GetProcAddress(hinstLib, "AddNumbers");
        if (addNumbers == NULL) {
                printf("ERROR: unable to find DLL function\n");
                FreeLibrary(hinstLib);
                return 1;
        }

        // Call function.
        result = addNumbers(1, 2);

        // Unload DLL file
        FreeLibrary(hinstLib);

        // Display result
        printf("The result was: %f\n", result);

        return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top