943,815 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2756
  • C++ RSS
Apr 4th, 2007
-1

pragma

Expand Post »
i was just going through some source code and came across the directive

C++ Syntax (Toggle Plain Text)
  1. #pragma comment( lib, "irrlicht.lib" );

I got mixed and confusing answers when i read about it in the vc++ documentation. Could someone please explain clearly the purpose or necessity for such code? I do have a hunch it has something to do with linking !!
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
Apr 4th, 2007
0

Re: pragma

>Could someone please explain clearly the purpose or necessity for such code?
If you're using code from an external library, you usually have to link a special .lib file. Usually how it's done in most IDEs is there's special configuration options, which allow you to specify the .libs to link with.

The #pragma is a compiler-specific feature to allow you to link the libs without going into the linker config.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Apr 4th, 2007
0

Re: pragma

Ah, now i get it. instead of that statement, i added the .lib file in the linker input options of the solution in vc++ express and commented the statement. It built and ran normally.

Now what you said would suffice for lib files. How do i link a dll file? is there a directive to link a dll file using compiler specific feature or is it a setting in the IDE. And would it be possible to elaborate the difference between a lib file and dll (.so in linux ).

i already vaguely understand! but im confused about which calls which. does the dll call lib files or lib calls dll files. Or do neither call each other, but for the source code... which calls either one or both.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
Apr 5th, 2007
0

Re: pragma

>Now what you said would suffice for lib files. How do i link a dll file?
DLL stands for Dynamic Link Library. So they aren't linked at compile time, they are dynamically linked when you run the program.

Usually how it tends to work is that a library will come with 2 parts: .lib and .dll. You add the .lib to the linker options, and the operating system takes care of the rest. Of course, there are other situations where the entire library is statically linked, in which case no DLL is necessary (just the .lib). But I have never used statically-linking libraries in the Windows environment, so I may not be entirely correct.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Apr 5th, 2007
0

Re: pragma

>
Usually how it tends to work is that a library will come with 2 parts: .lib and .dll. You add the .lib to the linker options, and the operating system takes care of the rest.
how does the OS know that the dll can be found in a particular place, may i ask?. In the IDE settings I explicitly set the extra include directories and extra lib directories. But i see no provision for extra dll directories. so how does the OS know where to search for the dll file it requires ?
Last edited by desijays; Apr 5th, 2007 at 12:35 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
Apr 5th, 2007
0

Re: pragma

Click to Expand / Collapse  Quote originally posted by desijays ...
how does the OS know that the dll can be found in a particular place, may i ask?. In the IDE settings I explicitly set the extra include directories and extra lib directories. But i see no provision for extra dll directories. so how does the OS know where to search for the dll file it requires ?
I'm not entirely sure of the technical details, but there are some default directories where the system's DLLs are located. Windows checks these when looking for the DLL. The OS also checks in the directory that the executable is located in.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Apr 5th, 2007
0

Re: pragma

The fact that the OS checks in the directory of the .exe is the only thing im sure off. cos up until now, thats the only way i solve the "xxxxx.exe cannot run cos xxxxxx.dll could not be found" dialogs when they pop up.

thanks for clearing some of my doubts mate. I know, that I know more about lib and dll files than 5 posts ago ;-). albeit i also know there is truck loads to learn yet.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
Apr 5th, 2007
0

Re: pragma

It's probably best to leave the Irrlicht dll file in the directory that your application resides in. I couldn't find any information on Irrlicht's web page on where to install the dll, and I haven't used Windows recently enough to remember the directory where all of them are stored.

And I wouldn't worry about it too much, having dlls with your program's executable is fine.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Apr 5th, 2007
0

Re: pragma

Ah, that answers a few questions. Thanks for the link mate. that cleared a few more doubts !
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: User-Defined Function - part 2
Next Thread in C++ Forum Timeline: Linker Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC