[MacPorts] #32917: clang++ 2.9, 3.0 and 3.1 do not link with the C++ standard library
MacPorts
noreply at macports.org
Wed Jan 18 02:08:01 PST 2012
#32917: clang++ 2.9, 3.0 and 3.1 do not link with the C++ standard library
----------------------------------+-----------------------------------------
Reporter: roland@… | Owner: macports-tickets@…
Type: defect | Status: new
Priority: Normal | Milestone:
Component: ports | Version: 2.0.3
Keywords: | Port:
----------------------------------+-----------------------------------------
The `clang++-mp-2.9` compiler from the MacPorts (from port `clang-2.9`)
does not seem to link C++ code correctly. In particular, the linker does
not link with the C++ standard library.
For instance, compiling a very simple program does not work, since the
linker is unable to find iostream classes and other required routines from
the C++ standard library:
{{{
% cat a.cc
#include <iostream>
int
main ()
{
std::cout << "Hello World!" << std::endl;
}
% clang++-mp-2.9 a.cc
Undefined symbols for architecture x86_64:
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in cc-FzHhK1.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in cc-FzHhK1.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 cc-FzHhK1.o
"std::cout", referenced from:
_main in cc-FzHhK1.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 cc-FzHhK1.o
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced
from:
_main in cc-FzHhK1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
}}}
Here is the output of the compiler with the `-v` option:
{{{
% clang++-mp-2.9 -v a.cc
clang version 2.9 (tags/RELEASE_29/final)
Target: x86_64-apple-darwin10
Thread model: posix
"/opt/local/libexec/llvm-2.9/bin/clang" -cc1 -triple x86_64-apple-
darwin10.0.0 -emit-obj -mrelax-all -disable-free -main-file-name a.cc
-pic-level 1 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu
core2 -target-linker-version 127.2 -v -resource-dir
/opt/local/libexec/llvm-2.9/bin/../lib/clang/2.9 -ferror-limit 19
-fmessage-length 80 -stack-protector 1 -fblocks -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/TT/TTWwnJg92RaMtk+BYog6aU+++TI/-Tmp-/cc-z6esE6.o -x c++ a.cc
clang -cc1 version 2.9 based upon llvm 2.9 hosted on x86_64-apple-darwin10
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64
/usr/include/c++/4.2.1/backward
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/i686-apple-darwin8
/usr/include/c++/4.0.0/backward
/usr/local/include
/opt/local/libexec/llvm-2.9/bin/../lib/clang/2.9/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/opt/local/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min
10.6.0 -o a.out -lcrt1.10.6.o
/var/folders/TT/TTWwnJg92RaMtk+BYog6aU+++TI/-Tmp-/cc-z6esE6.o -lSystem
Undefined symbols for architecture x86_64:
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in cc-z6esE6.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in cc-z6esE6.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 cc-z6esE6.o
"std::cout", referenced from:
_main in cc-z6esE6.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 cc-z6esE6.o
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced
from:
_main in cc-z6esE6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
}}}
My environment is Mac OS X 10.6 with the latest MacPorts.
I have the same problem with `clang++-mp-3.0` (port `clang-3.0`) and
`clang++-mp-3.0` (port `clang-3.0`).
Note that the old `clang++` compiler from port `clang` (version 2.8) that
is still installed on my system does not have this problem:
{{{
% clang++ -v a.cc
clang version 2.8 (branches/release_28)
Target: x86_64-apple-darwin10
Thread model: posix
"/opt/local/bin/clang" -cc1 -triple x86_64-apple-darwin10.0.0 -emit-obj
-mrelax-all -disable-free -disable-llvm-verifier -main-file-name a.cc
-pic-level 1 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu
core2 -target-linker-version 97.14 -v -resource-dir
/opt/local/lib/clang/2.8 -ferror-limit 19 -fmessage-length 80 -stack-
protector 1 -fblocks -fexceptions -fdiagnostics-show-option -fcolor-
diagnostics -o /var/folders/TT/TTWwnJg92RaMtk+BYog6aU+++TI/-Tmp-/cc-
1NH4kO.o -x c++ a.cc
clang -cc1 version 2.8 based upon llvm 2.8 hosted on x86_64-apple-darwin10
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64
/usr/include/c++/4.2.1/backward
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/i686-apple-darwin8
/usr/include/c++/4.0.0/backward
/usr/local/include
/opt/local/lib/clang/2.8/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/opt/local/bin/../libexec/gcc/i686-apple-darwin10/4.2.1/ld" -dynamic
-arch x86_64 -macosx_version_min 10.6.0 -o a.out -lcrt1.10.6.o
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 -L/usr/lib/gcc/i686-apple-
darwin10/4.2.1/x86_64 -L/usr/lib/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-
darwin10/4.2.1 -L/opt/local/bin/../lib -L/usr/lib/gcc/i686-apple-
darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686
-apple-darwin10/4.2.1/../../..
/var/folders/TT/TTWwnJg92RaMtk+BYog6aU+++TI/-Tmp-/cc-1NH4kO.o -lstdc++
-lSystem -lgcc
}}}
Here, the compiler actually links with `libstdc++`.
--
Ticket URL: <https://trac.macports.org/ticket/32917>
MacPorts <http://www.macports.org/>
Ports system for Mac OS
More information about the macports-tickets
mailing list