How do I create a Library in Visual Studio 2015

Apr 18, 2016 at 7:44pm
I have the following code that was written in VC6:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

#include "ThreadLib/ThreadLib.h"

void PrintThread( void* data )
{
    // convert the data passed in into a character.
    char c = (int)data;

    for( int i = 0; i < 10000; i++ )
    {
        cout << c;
        cout.flush();
    }
}


int main()
{
    ThreadLib::ThreadID a, b;

    a = ThreadLib::Create( PrintThread, (void*)'a' );
    b = ThreadLib::Create( PrintThread, (void*)'b' );


    ThreadLib::WaitForFinish( b );
    ThreadLib::WaitForFinish( a );

    char c;
    cin >> c;

    return 0;
}


I'm getting an error here:

#include "ThreadLib/ThreadLib.h"
cannot open source file "ThreadLib/ThreadLib.h"

Which I'm assuming is due to a deprecated method used in VC6. There is a folder in the Solution Explorer called ThreadLib that has the following files:

ThreadException.h
ThreadLib.h
ThreadLibFunctions.cpp
ThreadLibFunctions.h
ThreadLibMutex.h

I'm sure there's a way in Visual Studio 2015 to make a Library but I don't know how. When I try to open the solution I'm getting the following migration warning:

"Due to the requirement that Visual C++ projects produce an embedded (by default) Windows SxS manifest, manifest files in the project are now automatically built with the Manifest Tool. You may need to change your build in order for it to work correctly. For instance, it is recommended that the dependency information contained in any manifest files be converted to "#pragma comment(linker,"<insert dependency here>")" in a header file that is included from your source code. If your project already embeds a manifest in the RT_MANIFEST resource section through a resource (.rc) file, the line may need to be commented out before the project will build correctly."
Apr 18, 2016 at 7:57pm
I haven't used that particular version of VS, but I'd be very surprised if it's deprecated the #include statement. What's more likely is that you haven't set up your include paths properly in your project.
Apr 18, 2016 at 8:21pm
closed account (E0p9LyTq)
Implementing a user-created library in VS is a two-step process:

1. create/compile the library.

2. add the .lib file to another project that uses the library.

VS allows combining separate but related projects into a single solution, there are differences if you are creating a static or dynamic library.

Walkthrough: Creating and Using a Static Library (C++)
https://msdn.microsoft.com/en-us/library/ms235627.aspx

Walkthrough: Creating and Using a Dynamic Link Library (C++)
https://msdn.microsoft.com/en-us/library/ms235636.aspx

The biggest stumbling block to getting user-created libraries to work is forgetting to add the path(s) to the library to your solution/project path statements.
Last edited on Apr 18, 2016 at 8:23pm
Apr 19, 2016 at 11:01pm
This worked once I figured out to add the path correctly. Thanks for your help!
Last edited on Apr 19, 2016 at 11:33pm
Topic archived. No new replies allowed.