ubuntu编译use of dynamic_cast requires -frtti
时间: 2024-05-14 09:14:32 浏览: 12
这个错误提示是因为在编译过程中需要开启运行时类型信息(RTTI)支持,而默认情况下,Ubuntu的gcc编译器是关闭RTTI的。
要解决这个问题,可以在编译命令中加上“-frtti”选项来启用RTTI支持,例如:
```
g++ -frtti main.cpp -o main
```
如果需要在Makefile中使用,可以在CXXFLAGS中添加该选项:
```
CXXFLAGS += -frtti
```
这样就可以成功编译了。
相关问题
use of dynamic_cast requires -frtti
As an AI language model, I don't have a personal opinion, but I can provide you with technical explanations.
C++ has a feature called Run-Time Type Information (RTTI) that allows you to determine the type of an object at runtime. The dynamic_cast operator is one of the operators that rely on RTTI.
When you use dynamic_cast in your code, the compiler generates code that depends on the information provided by RTTI. Therefore, you need to enable RTTI support in your code, which is done by passing the -frtti compiler flag.
If you don't enable RTTI, you won't be able to use dynamic_cast, and your code will fail to compile.
ubuntu执行make命令时use of dynamic_cast requires -frtti
这个错误通常是由于编译器的 RTTI(运行时类型信息)未开启导致的。可以尝试在编译选项中添加 -frtti 选项,以开启 RTTI。在 Ubuntu 上,可以通过以下命令添加该选项:
make CXXFLAGS+=-frtti
如果该选项未生效,则可能需要检查编译器版本是否支持 RTTI,并进行升级或更换。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)