<small id='3edSd'></small><noframes id='3edSd'>

<legend id='3edSd'><style id='3edSd'><dir id='3edSd'><q id='3edSd'></q></dir></style></legend>
<i id='3edSd'><tr id='3edSd'><dt id='3edSd'><q id='3edSd'><span id='3edSd'><b id='3edSd'><form id='3edSd'><ins id='3edSd'></ins><ul id='3edSd'></ul><sub id='3edSd'></sub></form><legend id='3edSd'></legend><bdo id='3edSd'><pre id='3edSd'><center id='3edSd'></center></pre></bdo></b><th id='3edSd'></th></span></q></dt></tr></i><div id='3edSd'><tfoot id='3edSd'></tfoot><dl id='3edSd'><fieldset id='3edSd'></fieldset></dl></div>
<tfoot id='3edSd'></tfoot>

      • <bdo id='3edSd'></bdo><ul id='3edSd'></ul>
    1. 对“std::cout"的未定义引用

      时间:2023-09-19
        <bdo id='AWM09'></bdo><ul id='AWM09'></ul>

          <tfoot id='AWM09'></tfoot>

          <legend id='AWM09'><style id='AWM09'><dir id='AWM09'><q id='AWM09'></q></dir></style></legend>
          <i id='AWM09'><tr id='AWM09'><dt id='AWM09'><q id='AWM09'><span id='AWM09'><b id='AWM09'><form id='AWM09'><ins id='AWM09'></ins><ul id='AWM09'></ul><sub id='AWM09'></sub></form><legend id='AWM09'></legend><bdo id='AWM09'><pre id='AWM09'><center id='AWM09'></center></pre></bdo></b><th id='AWM09'></th></span></q></dt></tr></i><div id='AWM09'><tfoot id='AWM09'></tfoot><dl id='AWM09'><fieldset id='AWM09'></fieldset></dl></div>
              <tbody id='AWM09'></tbody>
          • <small id='AWM09'></small><noframes id='AWM09'>

                本文介绍了对“std::cout"的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                以这个为例:

                #include <iostream>
                using namespace std;
                int main()
                {
                    cout << "Hola, moondo.
                ";
                }
                

                它抛出错误:

                gcc -c main.cpp gcc -o edit main.o  main.o: In function `main':
                main.cpp:(.text+0xa): undefined reference to `std::cout'
                main.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<< <std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
                main.o: In function `__static_initialization_and_destruction_0(int,int)':
                main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
                main.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld
                returned 1 exit status make: *** [qs] Error 1
                

                另外,这个例子:

                #include <iostream>
                int main()
                {
                    std::cout<<"Hola, moondo.
                ";
                }
                

                抛出错误:

                gcc -c main.cpp gcc -o edit main.o  main.o: In function `main':
                main.cpp:(.text+0xa): undefined reference to `std::cout'
                main.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char> >&, char const*)'
                main.o: In function `__static_initialization_and_destruction_0(int,int)': main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
                main.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld
                returned 1 exit status make: *** [qs] Error 1
                

                注意:我使用的是 Debian Wheezy.

                Note: I am using Debian Wheezy.

                推荐答案

                编译程序:

                g++ -Wall -Wextra -Werror -c main.cpp -o main.o
                     ^^^^^^^^^^^^^^^^^^^^ <- For listing all warnings when your code is compiled.
                

                因为 cout 存在于 C++ 标准库中,使用 gcc 时需要 显式链接-lstdc++代码>;g++ 默认链接标准库.

                as cout is present in the C++ standard library, which would need explicit linking with -lstdc++ when using gcc; g++ links the standard library by default.

                使用gcc,(g++ 应该优于gcc)

                gcc main.cpp -lstdc++ -o main.o
                

                这篇关于对“std::cout"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将非 constexpr 标准库函数视为 constexpr 是否符合编 下一篇:在 C 代码中使用 C++ 库

                相关文章

                最新文章

                  <tfoot id='fjALG'></tfoot>
                    • <bdo id='fjALG'></bdo><ul id='fjALG'></ul>
                    <i id='fjALG'><tr id='fjALG'><dt id='fjALG'><q id='fjALG'><span id='fjALG'><b id='fjALG'><form id='fjALG'><ins id='fjALG'></ins><ul id='fjALG'></ul><sub id='fjALG'></sub></form><legend id='fjALG'></legend><bdo id='fjALG'><pre id='fjALG'><center id='fjALG'></center></pre></bdo></b><th id='fjALG'></th></span></q></dt></tr></i><div id='fjALG'><tfoot id='fjALG'></tfoot><dl id='fjALG'><fieldset id='fjALG'></fieldset></dl></div>

                    <small id='fjALG'></small><noframes id='fjALG'>

                    <legend id='fjALG'><style id='fjALG'><dir id='fjALG'><q id='fjALG'></q></dir></style></legend>