Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:09:51+00:00 2026-06-16T09:09:51+00:00

Possible Duplicate: GCC linker can’t find standard library? I am trying to mess with

  • 0

Possible Duplicate:
GCC linker can’t find standard library?

I am trying to mess with this C++ book I got for the holidays, I am coming from a limited understanding of python so this stuff is real strange to me.

I typed out this code from one of the first lessons into my text editor and saved it as a .cpp file.

#include <iostream>
int main()
{
    std::cout << "Enter two numbers:" << std::endl;
    int v1 = 0, v2 = 0;
    std::cin >> v1 >> v2;
    std::cout << "The sum of " << v1 << " and " << v2
              << " is " << v1 + v2 << std::endl;
    return 0;
}

but my terminal gives this crazy output when i try to compile it, whats going on?

Raymond-Weisss-MacBook-Pro:c++ Raylug$ gcc prog2.cpp
Undefined symbols for architecture x86_64:
  "std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:
      _main in cckdLEun.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
      _main in cckdLEun.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
      _main in cckdLEun.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in cckdLEun.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in cckdLEun.o
  "std::cin", referenced from:
      _main in cckdLEun.o
  "std::cout", referenced from:
      _main in cckdLEun.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in cckdLEun.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      _main in cckdLEun.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Raymond-Weisss-MacBook-Pro:c++ Raylug$ 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:09:52+00:00Added an answer on June 16, 2026 at 9:09 am

    Yes, you should use g++ to compile C++ instead of gcc, but it’s probably worth elaborating on the answer since you say you’re new to using compilers.

    GCC stands for the GNU Compiler Collection and is a collection of programs that can be used to compile source code for various languages. The command gcc provides the external interface for users to compile their programs. The gcc command will attempt to determine the language you want to compile from the file extensions on the source files. For example, a file named hello.c will compile as C, a file named foo.cpp will compile as C++, and a file named bar.m will compile as Objective-C.

    You can give the -x option to explicitly specify which language to compile, regardless of file extension. For example, gcc -x c++ main.c will compile main.c as a C++ file, despite having the .c extension.

    However, even though gcc will determine that your files are C++, it still won’t link to the C++ standard library by default. This library must be linked to to compile anything but the most simple C++ files. You can link to the GCC implementation of the standard library by adding -lstdc++ to your options. So gcc -lstdc++ prog2.cpp should work fine.

    However, for convenience, another command is provided for C++ programmers. Namely, g++. The g++ command will automatically link to the C++ standard library, so you don’t have to do it explicitly. It also causes .c, .h and .i files to be treated as C++ files.

    If you consistently stick with gcc for compiling C and g++, you should have no problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: problem with template inheritance This code doesn't compile in GCC: template <typename
Possible Duplicate: Can I make GCC warn on passing too-wide types to functions? Is
Possible Duplicate: Working of fork() in linux gcc Why does this code print two
Possible Duplicate: gcc-4.2 failed with exit code 1 iphone Can anybody tell what does
Possible Duplicate: Workaround for non-deduced context GCC cannot deduce parameters for this 'simple' function.
Possible Duplicate: Can I list-initialize a vector of move-only type? I use gcc 4.6.1
Possible Duplicate: GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference
Possible Duplicate: pthread Function from a Class I have this code that I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.