This topic is 3205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi folks I want to be able to link to library files that reside on C:\sdk\lib such as: - C:\sdk\lib\foo.lib, C:\sdk\lib\bar.lib etc.. This is easily achieved in MSVC by filling up the "C:\sdk\lib" in project's setting for Debug|Release(within the linking section). However, is there any way to do this programmatically using various directives (#ifdefs, #defines)? Or, even a different way(although programmatically)? Thanks tons! :-)

##### Share on other sites

If you choose to ignore all of the above, or have considered it and decided you don't care, however, the way to do what you are asking is

#pragma comment(lib,"libraryfile")

which is used like

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

more details at http://msdn.microsoft.com/en-us/library/7f0aews7(VS.80).aspx

##### Share on other sites
Steve132
Hi. Yep I do understand the consequence of using this on a "real" project. I asked because it was ridiculously boring to create projects mundanely for various examples I am working on to teach myself about Boost. Boost::any is superb! :-) So is the asynch io. wow! :-)

Rest assured, I will never ever using this on production code. :-)

##### Share on other sites
if its dynamic libraries you could use the loadlibrary method from the win32 api, it might work on static libraries too but i have never tried. also have to know the name of the methods or objects in the file.

##### Share on other sites
Below does the job perfectly(for a code doing asynch io):

//debug#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_system-vc90-mt-gd-1_40.lib")#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_date_time-vc90-mt-gd-1_40.lib")#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_regex-vc90-mt-gd-1_40.lib")//release#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_system-vc90-mt-1_40.lib")#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_date_time-vc90-mt-1_40.lib")#pragma comment(lib,	"C:\\Boost\\boost_1_40_0\\stage\\lib\\libboost_regex-vc90-mt-1_40.lib")

thanks Steve132 and owiley :-)
owiley, with regards to the ::LoadLibrary(...), I moved on because absolute lib paths weren't being loaded. I am more than happy with #pragma directive :-) Thanks for the pointer though.

As previously noted, I will never use #pragma on production code. Thanks Steve132 :-)

##### Share on other sites
Incidentally, since it is boost you are trying to get working, I should inform you that boost autolinks in the header-file already, and you shouldn't need to do this at all unless your boost installation is fubar. Try making a project that uses the boost libs you want only with incldue directives, and only set the link directory to the boost installation lib directory, but do not set any specific libs, and see if the header autolinking code works correctly.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×