gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) 上编译问题笔记

编译错误如下:

In file included from /usr/include/glib-2.0/glib/glib-typeof.h:39,

from /usr/include/glib-2.0/glib/gatomic.h:28,

from /usr/include/glib-2.0/glib/gthread.h:32,

from /usr/include/glib-2.0/glib/gasyncqueue.h:32,

from /usr/include/glib-2.0/glib.h:32,

from ../libqemu/qemu-common.h:39,

from ../libqemu/qemu-aio.h:17,

from ../libqemu/block.h:4,

from ../libqemu/block_int.h:27,

from Block.h:6,

from Block.cpp:1:

/usr/include/c++/11/type_traits:1006:3: error: template with C linkage

1006 | template<typename _Tp>

| ^~~~~~~~

In file included from Block.cpp:1:

Block.h:4:1: note: 'extern "C"' linkage started here

4 | extern "C"

| ^~~~~~~~~~

In file included from /usr/include/glib-2.0/glib/glib-typeof.h:39,

from /usr/include/glib-2.0/glib/gatomic.h:28,

from /usr/include/glib-2.0/glib/gthread.h:32,

from /usr/include/glib-2.0/glib/gasyncqueue.h:32,

from /usr/include/glib-2.0/glib.h:32,

from ../libqemu/qemu-common.h:39,

from ../libqemu/qemu-aio.h:17,

from ../libqemu/block.h:4,

from ../libqemu/block_int.h:27,

from Block.h:6,

from Block.cpp:1:

/usr/include/c++/11/type_traits:1015:3: error: template with C linkage

1015 | template<typename _Tp, typename... _Args>

| ^~~~~~~~

In file included from Block.cpp:1:

Block.h:4:1: note: 'extern "C"' linkage started here

4 | extern "C"

| ^~~~~~~~~~

In file included from /usr/include/glib-2.0/glib/glib-typeof.h:39,

from /usr/include/glib-2.0/glib/gatomic.h:28,

from /usr/include/glib-2.0/glib/gthread.h:32,

from /usr/include/glib-2.0/glib/gasyncqueue.h:32,

from /usr/include/glib-2.0/glib.h:32,

from ../libqemu/qemu-common.h:39,

from ../libqemu/qemu-aio.h:17,

from ../libqemu/block.h:4,

from ../libqemu/block_int.h:27,

from Block.h:6,

from Block.cpp:1:

/usr/include/c++/11/type_traits:1021:3: error: template with C linkage

1021 | template<typename _Tp, typename... _Args>

| ^~~~~~~~

In file included from Block.cpp:1:

解决方法:

修改了Block.cpp,在其#include "Block.h"之前添加 #include <glib.h>

相关推荐
晓纪同学5 分钟前
EffctiveC++_第三章_资源管理
开发语言·c++·算法
蚊子码农12 分钟前
每日一题--C语言指针与内存泄漏:一道小问题的深度复盘
c语言·开发语言
Fanfanaas12 分钟前
Linux 系统编程 进程篇(一)
linux·运维·服务器·c语言·开发语言·网络·学习
星辰徐哥16 分钟前
ARP缓存表:作用、查看方法与刷新技巧
开发语言·缓存·php
ego.iblacat18 分钟前
lvs 集群部署
开发语言·php·lvs
沐雪轻挽萤20 分钟前
6. C++17新特性-编译期 if 语句 (if constexpr)
开发语言·c++
水云桐程序员23 分钟前
C语言编程基础,输入与输出
c语言·开发语言·算法
爱代码的小黄人25 分钟前
MATLAB中for循环实现递减遍历(通用方法)
开发语言·matlab
weixin_7042660529 分钟前
手机体检预约系统开发解析
java·开发语言
白露与泡影30 分钟前
Java八股文大全(2026最新版)大厂面试题附答案详解
java·开发语言