Can't compile C++ example

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
FreeBSD
Level 1
Level 1
Posts: 17
Joined: Sun Feb 14, 2021 5:12 am

Can't compile C++ example

Post by FreeBSD »

I installed clang from Software Manager on Linux Mint 20.3 Cinnamon,
I'm trying to build the following example:
#include <iostream>
using namespace std;

int main(){
std::cout << "Hello, world";
}

clang hello.cpp -o hello
/usr/bin/ld: /tmp/hello-017c47.o: in function `main':
hello.cpp:(.text+0xa): undefined reference to `std::cout'
/usr/bin/ld: hello.cpp:(.text+0x1d): 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*)'
/usr/bin/ld: /tmp/hello-017c47.o: in function `__cxx_global_var_init':
hello.cpp:(.text.startup+0xf): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: hello.cpp:(.text.startup+0x15): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
spamegg
Level 14
Level 14
Posts: 5101
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Can't compile C++ example

Post by spamegg »

You need to use clang++ as your command, not clang. That's for C code.
FreeBSD
Level 1
Level 1
Posts: 17
Joined: Sun Feb 14, 2021 5:12 am

Re: Can't compile C++ example - SOLVED

Post by FreeBSD »

That did it. Thank you so much.
User avatar
spamegg
Level 14
Level 14
Posts: 5101
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Can't compile C++ example

Post by spamegg »

Awesome, mark your topic [SOLVED], thanks!
Locked

Return to “Software & Applications”