Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

Automatically linking with libs

Is it possible to have code in a header file etc so that when the program is compiled it is automatically linked with a required library?

I am using Visual C++ 6.

Thanks
Norman
0
Norman_SK
Asked:
Norman_SK
1 Solution
 
thienpnguyenCommented:
Using

#pragma comment( lib, "YourLib.lib")



Example


#ifdef _DEBUG
#pragma comment( lib, "YourLib_Debug.lib")
#else
#pragma comment( lib, "YourLib_Release.lib")
#endif

0
 
antoinebfCommented:
and you can wrap this in YOURPROJECT_EXPORTS macro which is usually defined as a preprocessor definition in your project's setting (C++ tab):

#ifdef YOURPROJECT_EXPORTS
#ifdef _DEBUG
#pragma comment( lib, "YourLib_Debug.lib")
#else
#pragma comment( lib, "YourLib_Release.lib")
#endif//_DEBUG
#endif//YOURPROJECT_EXPORTS

This way, you can put this directly in a header file used in you lib, and reuse the same file for other projects that use it. For example, you could define your exported functions and classes (with an macro below) in this file.

i.e.:
#ifdef YOURPROJECT_EXPORTS
#define YOURPROJECT_API __declspec(dllexport)
#else
#define YOURPROJECT_API __declspec(dllimport)
#endif//YOURPROJECT_EXPORTS


class YOURPROJECT_API CRoger
{
...
};


hth
A.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now