c++ - 编译 C++ 程序时出错:错误:在 '>' 标记之前预期的 unqualified-id
问题描述
我尝试在我的 ubuntu 18.04 上编译 C++ 程序。在程序中,我使用了一些外部库。
错误如下所示:
blib/bun/impl/orm.hpp:1995:20: error: ‘struct blib::bun::__private::type_conversion’ redeclared as different kind of symbol
struct type_conversion<SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1944:20: note: previous declaration ‘template<class T> struct blib::bun::__private::type_conversion’
struct type_conversion {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1995:53: error: expected unqualified-id before ‘>’ token
struct type_conversion<SimpleObjHolder<T>> {
^~
blib/bun/impl/orm.hpp:2114:12: error: ‘type_conversion’ is not a class template
struct type_conversion<blib::bun::__private::SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:2114:67: error: conflicting declaration of template ‘template<class T> struct soci::type_conversion’
struct type_conversion<blib::bun::__private::SimpleObjHolder<T>> {
^~
In file included from /usr/local/include/soci/exchange-traits.h:11:0,
from /usr/local/include/soci/into-type.h:13,
from /usr/local/include/soci/blob-exchange.h:12,
from /usr/local/include/soci/soci.h:18,
from /home/mike/Documents/PROJECTS/C/blib/bun/impl/DbBackend.hpp:9,
from blib/bun/impl/orm.hpp:41,
from blib/bun/bun.hpp:3,
from main.cpp:12:
/usr/local/include/soci/type-conversion-traits.h:19:8: note: previous declaration ‘template<class T, class Enable> struct soci::type_conversion’
struct type_conversion
^~~~~~~~~~~~~~~
<builtin>: recipe for target 'main' failed
make: *** [main] Error 1
有问题的代码的示例部分如下所示:
struct type_conversion<SimpleObjHolder<T>> {
using ObjectHolderType = SimpleObjHolder<T>;
using ObjType = T;
......
确切的问题行是:
struct type_conversion<SimpleObjHolder<T>> {
似乎编译器无法理解语法,或者我的编译器版本不正确。
我是 C/C++ 的新手,请在这一刻澄清我..
这是生成文件:
LDFLAGS := -L/usr/local/lib -L/home/mike/Documents/PROJECTS/C/libs/socket \
-I/home/mike/Documents/PROJECTS/C/third_party/unqlite -I/home/mike/Documents/PROJECTS/C -I/home/mike/Documents/PROJECTS/C/third_party
LDLIBS := -lchilkat-9.5.0 -lpthread -lresolv -lsocket
EXECUTABLE := main
CXXFLAGS=-g -std=c++11 -Wall -pedantic
all: $(EXECUTABLE)
clean:
rm -f $(EXECUTABLE) *.o
添加后报错CXXFLAGS=-g -std=c++11 -Wall -pedantic
:
blib/bun/impl/orm.hpp:1995:20: error: ‘type_conversion’ is not a class template
struct type_conversion<SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1995:36: error: ‘SimpleObjHolder’ was not declared in this scope
struct type_conversion<SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1995:36: note: suggested alternative:
blib/bun/impl/orm.hpp:415:20: note: ‘blib::bun::__private::SimpleObjHolder’
struct SimpleObjHolder {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1995:20: error: ‘struct blib::bun::__private::type_conversion’ redeclared as different kind of symbol
struct type_conversion<SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1944:20: note: previous declaration ‘template<class T> struct blib::bun::__private::type_conversion’
struct type_conversion {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:1995:53: error: expected unqualified-id before ‘>’ token
struct type_conversion<SimpleObjHolder<T>> {
^~
blib/bun/impl/orm.hpp:2105:14: warning: extra ‘;’ [-Wpedantic]
};
^
blib/bun/impl/orm.hpp:2114:12: error: ‘type_conversion’ is not a class template
struct type_conversion<blib::bun::__private::SimpleObjHolder<T>> {
^~~~~~~~~~~~~~~
blib/bun/impl/orm.hpp:2114:67: error: conflicting declaration of template ‘template<class T> struct soci::type_conversion’
struct type_conversion<blib::bun::__private::SimpleObjHolder<T>> {
我试过了CXXFLAGS=-g -std=c++11 -Wall -pedantic
,,,CXXFLAGS=-g -std=c++14 -Wall -pedantic
CXXFLAGS=-g -std=c++17 -Wall -pedantic
gcc 版本 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
解决方案
推荐阅读
- c# - 使用 XUnit Mediatr 和 IServiceCollection 进行依赖注入
- php - 在表单中填充输入以查看数组
- javascript - 密码不应以数字开头
- jquery - JQuery 将名称的第一个字母放在圆圈中
- php - GET Route Laravel 中的 URL 参数
- python - 匹配列表中任意位置的字段的“if”条件
- kubernetes - Kubernetes 中节点和命名空间之间的关系是什么?
- git - 来自远程分叉存储库的 Gitlab 合并请求通过命令行不创建任何合并提交
- python - 如何在 python 中启用 sqlite3 FTS5 扩展(在 Windows 上)?
- c# - 什么是最有效的方法 - 检查标签或 GetComponent