链接向量类时出现问题

发布于 2024-09-29 14:00:05 字数 4528 浏览 4 评论 0原文

我有一个大项目,其中有一堆 .cc 文件,其中主要包含 C 代码和一些 C++ 代码。我想在这个程序中使用向量,因为我需要一个易于制作 2d 的无界数据类型(换句话说,我不想使用数组或列表)。 问题是,当我在包含向量类后运行 make 时,我收到了以前没有收到的错误。唯一有区别的行是 #include。我没有编写 make 文件(大约有 4 或 5 个),但据我所知,它使用的是 GNU 编译器。我没有实例化向量对象,已经包含 using namespace std; 并且当我注释掉向量的 include 指令时,错误消失了。然而,在这个项目的另一个文件中,我使用了队列库,它没有任何问题。当我将其包含在 .h 文件中时,问题发生了,对于 .cc 文件没有问题,但由于我需要在 .h 文件中实例化矢量对象,所以我没有只使用 .cc 文件的商品为了这。有人可以为我解决这个问题提供任何帮助吗?

以下是从 bash 复制粘贴的导致错误的部分的输出:

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/main.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/scheduler.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/synch.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/system.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/thread.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/threadtest.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/interrupt.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/sysdep.cc

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2

/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’ 
variable

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp& 
std::min’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected ‘}’ before ‘if’


/usr/include/c++/4.4/bits/stl_algobase.h:237: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp& 
max’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected ‘}’ before ‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:258: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token


make[1]: *** [sysdep.o] Error 1

make[1]: Leaving directory `/home/f85/njvanbal/workspace/nachos2/userprog'

make: *** [all] Error 2

I have a big project with a bunch of .cc files that have mostly c code and some c++ code. I want to use a vector in this program since I need an unbounded data type that is simple to make 2d (in other words I don't want to use an array or a list).
The problem is that when I run my make after including the vector class I get errors that I didn't get before. The only line that makes any difference is #include <vector>. I did not write the make files (and there are about 4 or 5 of them) but to the best of my knowledge it is using the GNU compiler. I have no vector objects instantiated, already included using namespace std; and the error goes away when I comment out the include directive for vector. On another file in this project however I used the queue library and it didn't have any problem with it. The problem happens when I include it in a .h file, it has no problem with .cc files, but since I will need to instantiate a vector object in the .h file I don't have the commodity of only using .cc files for this. Can someone give me any help for this problem?

Here is the output copied pasted from bash for the part that leads up to the error:

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/main.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/scheduler.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/synch.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/system.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/thread.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/threadtest.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/interrupt.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/sysdep.cc

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2

/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’ 
variable

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp& 
std::min’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected ‘}’ before ‘if’


/usr/include/c++/4.4/bits/stl_algobase.h:237: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp& 
max’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected ‘}’ before ‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:258: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token


make[1]: *** [sysdep.o] Error 1

make[1]: Leaving directory `/home/f85/njvanbal/workspace/nachos2/userprog'

make: *** [all] Error 2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故笙诉离歌 2024-10-06 14:00:05

最好总是先回顾第一个错误;在您的情况下:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2
/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

看起来您在自己的代码中定义了一个名为 minmax 的宏(或者可能是函数)。 vector#include 显然还为 minmax 定义了宏,编译器感到困惑。更改 minmax 宏的名称。

Always best to look back to the first error first; in your case:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2
/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

Looks like you have defined a macro (or maybe a function) called min and max in your own code. The #include for vector apparently also defines a macro for min and max and the compiler is getting confused. Change the name of your min and max macros.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文