Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

Visual C++: Library Pragma

πŸ“… 2006-May-26 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ libraries, pragma, visual cpp ⬩ πŸ“š Archive

I find myself having to indicate the libraries I want linked in every time I do this. I found a neat (non-portable) trick in Visual Studio to do this.

Use the #pragma comment(lib, β€œlibfile”) [1] preprocessor directive to hint your compiler/linker to include these library files for linking. For example:

// Link cg libraries
#pragma comment(lib, "cg.lib")
#pragma comment(lib, "cggl.lib")

[1] msdn.microsoft.com/library/en-us/vclang/html/_predir_comment.asp

(via Adding MSDEV Libraries)


Β© 2023 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 Mastodon β€’ πŸ“§ Email