Opened 13 years ago
Closed 13 years ago
#32917 closed defect (fixed)
clang++ 2.9, 3.0 and 3.1 do not link with the C++ standard library
Reported by: | roland@… | Owned by: | jeremyhu (Jeremy Huddleston Sequoia) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | 2.0.3 |
Keywords: | Cc: | ||
Port: | clang-2.9, clang-3.0, clang-3.1 |
Description
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++
.
Change History (5)
comment:1 Changed 13 years ago by ryandesign (Ryan Carsten Schmidt)
Owner: | changed from macports-tickets@… to jeremyhu@… |
---|---|
Port: | clang-2.9 clang-3.0 clang-3.1 added |
comment:2 Changed 13 years ago by jeremyhu (Jeremy Huddleston Sequoia)
comment:3 Changed 13 years ago by jeremyhu (Jeremy Huddleston Sequoia)
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 Changed 13 years ago by roland@…
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I have just upgraded clang-2.9
, clang-3.0
and clang-3.1
to their latest versions. There is another problem regarding the linker in all three ports:
% clang++-mp-2.9 a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation) % clang++-mp-3.0 a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation) % clang++-mp-3.1 a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation)
Using the clang++
binary from the /opt/local/libexec/llvm-x.y/bin/
directory produces the same error:
% /opt/local/libexec/llvm-2.9/bin/clang++ a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation) % /opt/local/libexec/llvm-3.0/bin/clang++ a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation) % /opt/local/libexec/llvm-3.1/bin/clang++ a.cc ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the output of clang++-mp-2.9
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-CZUJ1t.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. "/usr/libexec/gcc/i686-apple-darwin10/4.2.1/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-CZUJ1t.o /usr/lib/libstdc++.6.dylib -lSystem ld: unknown option: -demangle clang: error: linker command failed with exit code 1 (use -v to see invocation)
(clang++-mp-3.0
and clang++-mp-3.1
show similar error messages.)
comment:5 Changed 13 years ago by jeremyhu (Jeremy Huddleston Sequoia)
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
That is a different issue, so file a new bug report. This one is fixed.
Interestingly, using the file directly instead of the symlink works. eg: