LINK1104 cannot open boost static library using visual studio 2008 command prompt

故事扮演 提交于 2019-12-13 03:10:32

问题


I'm trying to compile a cpp file which uses static boost libraries. I'm using the visual studio 2008 command prompt as I have not set up a VS project file.

The command I'm using is (run from the folder containing my source code):

cl /EHsc /I "C:\Program Files\boost\boost_1_53_0" Client.cpp

The error is:

LINK: fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-s-1_53.lib'

However, the file 'libboost_system-vc90-mt-s-1_53.lib' can be found in "C:\Program Files\boost\boost_1_53_0\stage\lib" so my understanding is that I've installed boost properly and I'm just failing to link to it?

I've tried including it directly using

cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /I "C:\Program Files\boost\boost_1_53_0\stage\lib\" Client.cpp which gives the same error.

I've also tried linking to it directly using /link as follows: cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib" Client.cpp

Which returns a different error: cl : Command line error D8003 : missing source filename

I seem to be calling the compiler flags wrong? But I can't see where/how.

There is a similar question here,but the solution involves issues with how visual studio/ the project file is set up. Since I don't have a project file, is there an easy solution for the above that I can't see or would I need to set up a project?

Thanks for any help in advance!


回答1:


The linker needs to be told where the library file is located. You were very close with the last command line, but the file name needs to precede the /link option. This should work:

cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib"

Also, when linking to multiple libraries in the same directory, it is more concise to use the LIBPATH option to tell the linker where to look for .lib files.

cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "libboost_system-vc90-mt-s-1_53.lib" /LIBPATH:"C:\Program Files\boost\boost_1_53_0\stage\lib\"



来源:https://stackoverflow.com/questions/17017041/link1104-cannot-open-boost-static-library-using-visual-studio-2008-command-promp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!