g++ fails to link when using the -flto switch
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
binutils (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Any C++ program I tried to build with GCC failed with undefined reference errors. As a test case, I have created a simple Hello World program:
$ cat hello.cpp
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
}
$ g++ -o hello hello.cpp -flto
/usr/lib/
/usr/lib/
/usr/lib/
/usr/lib/
/usr/lib/
/lib/x86_
/usr/lib/
/usr/lib/
/usr/lib/
/usr/lib/
/lib/x86_
/usr/lib/
/usr/lib/
/lib/x86_
/lib/x86_
/usr/lib/
collect2: ld returned 1 exit status
Every C++ program I tried to build with -flto failed at link stage. C programs compile without problems. A workaround is to add the -B/usr/lib/gold-ld/ switch to the command line:
$ g++ -B/usr/lib/gold-ld/ -flto -o hello hello.cpp
$ # Success
ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: binutils 2.21.53.
ProcVersionSign
Uname: Linux 3.0.0-12-generic x86_64
NonfreeKernelMo
ApportVersion: 1.23-0ubuntu4
Architecture: amd64
Date: Thu Nov 3 21:43:56 2011
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64 (20110427.1)
ProcEnviron:
LANGUAGE=
PATH=(custom, no user)
LANG=pt_BR.UTF-8
SHELL=/bin/bash
SourcePackage: binutils
UpgradeStatus: Upgraded to oneiric on 2011-10-15 (19 days ago)
Changed in binutils (Ubuntu): | |
status: | New → Confirmed |
tags: | removed: running-unity |
fixed in -updates