Sunday, August 2, 2009

In C++, how to compile your code to link in a certain library statically?

pls post code if ever thanks!

In C++, how to compile your code to link in a certain library statically?
Include the header file(s) for the library:





%26lt;include whatever.h%26gt;





Then to link in the library, look in your project options or settings for linker settings. There should be a place to type in the name of the library. There's often another place nearby to specify what directories to search for the libraries. For example, in MS Visual C++ 6.0, go to Project/Settings, click on the Link tab, and add the library to the ones listed in "Object/library modules". Choose "Input" from the "Category" drop-down list, and and put the library's directory in "Additional library path".
Reply:If you are using gcc, just add "-static" option to your compile command line.





For example,


gcc -static -g -Wall -o myprog myprog.c ...


No comments:

Post a Comment