tag:blogger.com,1999:blog-375315255567275930.post5151808872477733309..comments2024-02-15T13:53:46.555+05:30Comments on I Think Tech: #pragma comment(lib, "libfilename") -- A cool way to indicate dependency.Brahmana (Srirang)http://www.blogger.com/profile/10677241604486586254noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-375315255567275930.post-38469803215823533032015-12-10T14:06:28.140+05:302015-12-10T14:06:28.140+05:30I realize I'm way late with this response, but...I realize I'm way late with this response, but I just thought I'd point out that you can also use this functionality with the __pragma keyword, allowing it to be used from a preprocessor macro:<br /><br />#define XSTR2(X) #X<br />#define XSTR(X) XSTR2(X)<br /><br />#define REDIRECT_EXPORT(DLL,NAME) \<br /> __pragma(comment(linker, "/export:" XSTR(NAME) "=" DLL "." XSTR(NAME)))<br /><br />#define IMPORT_LIB(BASENAME) \<br /> __pragma(comment(lib, XSTR(BASENAME) COMMON_SUFFIX ".lib"))<br />Charleshttps://www.blogger.com/profile/13973817363508559470noreply@blogger.comtag:blogger.com,1999:blog-375315255567275930.post-72890289848200481942011-06-11T15:28:59.895+05:302011-06-11T15:28:59.895+05:30TemporalBeing,
Agree with you on the 1st point. T...TemporalBeing,<br /><br />Agree with you on the 1st point. This is totally MSVC specific. Though, admittedly it is a pretty cool feature.<br /><br />But as I mention at the end of my post, this feature suits library developers very well. And as a library developer you know which compiler and platform you support. So you can do this selectively with a #ifdef. The logic is applicable for different environments -- debug, release, test, etc. #ifdef again works.<br /><br />This is just one additional measure to make sure users of your library will not get those weird looking long linker error messages because they forgot to include your library in the necessary libraries list for their project. The moment they include your header file, your library is also linked (sort of).Brahmana (Srirang)https://www.blogger.com/profile/10677241604486586254noreply@blogger.comtag:blogger.com,1999:blog-375315255567275930.post-57651469660360222262011-06-10T03:09:04.746+05:302011-06-10T03:09:04.746+05:30#pragma comment(lib, "libfilename") has ...#pragma comment(lib, "libfilename") has a couple problems:<br /><br />1) It is VC++ only, or at best heavily compiler/linker dependent as you are specifying the linker file name based on how you expect it for your compiler. Move to another compiler and that may no longer hold true - e.g. libFileName.a versus fileName.lib.<br /><br />2) You lose all ability to change which libs you are linking against based on your build. For example, you might want to have one set of libs for debug and another set for release. This is more easily handled via the project linker options.TemporalBeinghttps://www.blogger.com/profile/06247647473502902350noreply@blogger.comtag:blogger.com,1999:blog-375315255567275930.post-47648270318353119512009-03-06T15:02:00.000+05:302009-03-06T15:02:00.000+05:30Hi JAB,Good to know my blog post helped you.And I ...Hi JAB,<BR/><BR/>Good to know my blog post helped you.<BR/><BR/>And I am sorry but I could not recognize you and neither could I see your profile. A little more info would be helpful. :)<BR/><BR/>Regards,<BR/>Brahmana (Srirang)Brahmana (Srirang)https://www.blogger.com/profile/10677241604486586254noreply@blogger.comtag:blogger.com,1999:blog-375315255567275930.post-77686738617573124152009-03-04T19:03:00.000+05:302009-03-04T19:03:00.000+05:30Hey Brahmana remember me??I was just searching for...Hey Brahmana remember me??<BR/>I was just searching for that pragma and yours was the hit!!JABhttps://www.blogger.com/profile/11180668220975175568noreply@blogger.com