[英]Difference between -lstdc++ and -lstdc++11
Which standards gets invoked by invoking compiler flag "-lstdc++"? 调用编译器标志“ -lstdc ++”会调用哪些标准? Like with "-lstdc++11", the c++11 standard gets invoked and the same can be called by "-std=c++11".
与“ -lstdc ++ 11”一样,c ++ 11标准被调用,“-std = c ++ 11”可以调用相同的标准。
The -l
flag does not change standards conformance, it is used to specify what libraries to link with. -l
标志不会更改标准一致性,它用于指定要链接的库。
So, -lstdc++
would link with a library named libstdc++.a
or libstdc++.so
. 因此,
-lstdc++
将与名为libstdc++.a
或libstdc++.so
的库链接。 On my system, that library can be found at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
, but it will generally be different on your system. 在我的系统上,可以在
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
找到该库,但是在您的系统上它通常会有所不同。
This is no different from specifying something like -lSDL
, which links with libSDL.so
, or specifying -lpng
, which links with libpng.so
. 这与指定与
libSDL.so
类的东西(与-lSDL
链接)或指定-lpng
与libpng.so
链接的东西没有什么不同。
If you want to use a certain version of the C++ standard, use the -std
option (like -std=c++11
). 如果要使用特定版本的C ++标准,请使用
-std
选项(如-std=c++11
)。 This will also link the correct library in, so you do not need to do anything else (such as use any -l
options). 这还将链接正确的库,因此您无需执行其他任何操作(例如使用任何
-l
选项)。
You don't specify the compiler here, but let's assume it is clang++
or g++
or something similar. 您无需在此处指定编译器,但假设它是
clang++
或g++
或类似的东西。
Then the flag -l<library>
simply specifies that the library <library>
should be searched when linking. 然后,标志
-l<library>
仅指定链接时应搜索库<library>
。 This search will include a standard list of search directories and others that may have been added to the library path. 此搜索将包括搜索目录的标准列表以及可能已添加到库路径的其他目录。
Thus the flag -lstdc++
simply indicates that library should be searched at link time. 因此,标志
-lstdc++
只是表明应该在链接时搜索库。 It has no effect on the version of c++ that the compiler should think it is compiling. 它对编译器认为正在编译的c ++版本没有影响 。
In contrast, the flag -std=c++
generally acts as switch to the compiler that: 相反,标志
-std=c++
通常用作切换到以下编译器的开关:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.