简体   繁体   English

CMake C ++库链接

[英]CMake c++ library linking

I have Fortran target in CMake which relies on C++ libraries. 我在CMake中有Fortran目标,它依赖于C ++库。 What is portable way to include STDC++ into linking? 将STDC ++包含在链接中的便携式方法是什么?

If you're linking with gfortran, add -lstdc++ , if linking with g++, you'll need -lgfortran . 如果要与gfortran链接,请添加-lstdc++ ;如果要与g ++链接,则需要-lgfortran Either way, you'll need both of them, it's just that g++ automagically links with libstdc++, and gfortran automagically links with libgfortran. 无论哪种方式,您都需要它们,只是g ++自动链接libstdc ++,而gfortran自动链接libgfortran。

There is no "portable" way as in cross-compiler or cross-"standard library vendor", because all the libraries are named differently. 没有像跨编译器或跨“标准库供应商”中那样的“便携式”方式,因为所有库的命名都不同。

Theoretically the STL is part of the C++, so you don't need to do anything in CMake to use STL. 从理论上讲,STL是C ++的一部分,因此您无需在CMake中进行任何操作即可使用STL。 On other hand: if your C++ libraries have dependencies and their have CMake module (eg: FintQt4), CMake automatically handle the linking process. 另一方面:如果您的C ++库具有依赖项,并且它们具有CMake模块(例如:FintQt4),则CMake会自动处理链接过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM