Dealing with multiple projects in visual studios

62 views Asked by At

I am trying to figure out how to deal with multiple projects under the banner of a single solution and how to correctly link projects in order to make things work in conjunction.

I began by making two projects in one solution - for simplicity's sake, ProjA and ProjB. ProjB is set as the StartUp project. Furthermore, ProjA is configured to be built as a .dll file which I am to link with ProjB, which in turn is configured to be built as a .exe file. So far I've linked ProjA to ProjB by adding a dependency to ProjB via referencing (RMB>Add>Reference).

With all that out of the way, I wanted to test whether the setup worked as intended. So I did the following. In ProjA, I wrote the following Test code:

Test.h

#pragma once

namespace ProjA {

    _declspec(dllexport) void Print();
}

Test.cpp

#include "Test.h"
#include <stdio.h>

namespace ProjA {

    void Print()
    {
        printf("Testing\n");
    }
}

And in ProjB:

TestEntry.cpp

#include <stdio.h>

namespace ProjA {

    _declspec(dllimport) void Print();
}

void main()
{
    ProjA::Print(); //breakpoint1
    printf("Testing (2)\n"); //breakpoint2
}

I set two breakpoints at the commented lines for debugging, built the projects and ran the program. At breakpoint1, I expected the console to print "Testing" and proceed to the next line, followed by breakpoint2 printing "Testing (2)" and proceeding to the next line before exiting. However, the console was blank at breakpoint1. It only printed the line from the main function at breakpoint2.

So what am I doing wrong here? Is there something wrong with the way I included the projects? Was there a linking procedure I skipped? Is there a specific way I need to set up Visual Studios 2017 in order for it to work? Are there other plugins/APIs I should be installing?

To test it out further, I commented out everything in ProjA. This time I expected a linking error when building the projects, but everything ran in the exact same manner. This confused me even more. It's as if I didn't even link the projects and the main function is not identifying the Test codes via the include. That's the only thing I could deduce so far.

1

There are 1 answers

0
Al Abrar On

As suggested by SoronelHaetir, I redid the whole thing using #defines and namespaces. It's working as intended now. In conclusion, the crude method was a bad idea from the getgo.