Page MenuHomeSolus

g++ and clang failing to compile hello world (iostream header)
Closed, InvalidPublic

Description

I just installed g++ and clang through eopkg on a clean install of Solus, and am failing to compile a program that outputs text to the standard output using the iostream header. It seems to be some issue dependencies, but I don't know C/C++ stuff that well.

This is the output I get with just 'g++ hello.cpp'

In file included from /usr/include/errno.h:35:0,
                 from /usr/include/c++/6.2.0/cerrno:42,
                 from /usr/include/c++/6.2.0/ext/string_conversions.h:44,
                 from /usr/include/c++/6.2.0/bits/basic_string.h:5402,
                 from /usr/include/c++/6.2.0/string:52,
                 from /usr/include/c++/6.2.0/bits/locale_classes.h:40,
                 from /usr/include/c++/6.2.0/bits/ios_base.h:41,
                 from /usr/include/c++/6.2.0/ios:42,
                 from /usr/include/c++/6.2.0/ostream:38,
                 from /usr/include/c++/6.2.0/iostream:39,
                 from hello.cpp:1:
/usr/include/bits/errno.h:24:26: fatal error: linux/errno.h: No such file or directory
 # include <linux/errno.h>
                          ^
compilation terminated.

clang is also failing, again a simple 'clang hello.cpp', with the following output.

/tmp/hello-e4f567.o: In function `main':
hello.cpp:(.text+0xa): undefined reference to `std::cout'
hello.cpp:(.text+0x24): 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*)'
/tmp/hello-e4f567.o: In function `__cxx_global_var_init':
hello.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::Init()'
hello.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)

And the hello.cpp file in case I've made some dumb mistake.

#include <iostream>

using namespace std;

int main() {
	cout << "Hello, World!";
	return 0;
}

Both clang and g++ are able to compile a similar program that uses cstdio and printf instead.

Event Timeline

MichaelNecio renamed this task from g++ failing to compile Hello World to g++ and clang failing to compile hello world (iostream header).Dec 22 2016, 12:16 AM
MichaelNecio updated the task description. (Show Details)
MichaelNecio updated the task description. (Show Details)

Did you install system.devel component?

Installing the system.devel component did work to make g++ work, thanks!

But clang is still failing with the same error message. Also maybe installing the g++ package should be enough to get a hello world compiling.

Also maybe installing the g++ package should be enough to get a hello world compiling.

Nope - this is why we have system.devel - a grouping for core development functionality :)