?
Solved

Automatically linking with libs

Posted on 2003-02-21
2
Medium Priority
?
725 Views
Last Modified: 2011-09-20
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
Comment
Question by:Norman_SK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
thienpnguyen earned 150 total points
ID: 7994895
Using

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



Example


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

0
 
LVL 2

Expert Comment

by:antoinebf
ID: 7994953
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question