[cfe-users] Undefined reference when compiling in O2 (Clang 3.4)

Baptiste Wicht baptistewicht at gmail.com
Sat Apr 12 09:52:13 PDT 2014


Hi,

I've a strange problems with Clang 3.4. I'm on Gentoo and I'm using the
official Gentoo version 3.4-r100. I'm using the version 0.0_p20131222 of
libcxx and libcxxrt.

My code is working fine when optimizations are at low level (-O0 -O1 -Os)
but when I use higher levels (-O2 -O3 -Ofast), my code does not link:

release/src/ast/Operator.cpp.o: In function
`eddic::ast::operator<<(std::__1::basic_ostream<char,
std::__1::char_traits<char> >&, eddic::ast::Operator)':
/home/wichtounet/dev/eddic/src/ast/Operator.cpp:15: undefined reference to
`std::__1::basic_ostream<char, std::__1::char_traits<char> >&
std::__1::operator<< <char, std::__1::char_traits<char>,
std::__1::allocator<char> >(std::__1::basic_ostream<char,
std::__1::char_traits<char> >&, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

I'm using clang++ to compile and link. I'm using -std=c++1y -stdlib=libc++
options.

The code in question does not seem to be the cause of the problem:

std::ostream& ast::operator<< (std::ostream& stream, ast::Operator op){
    std::string value = "asd";
    return stream << value;
}

What I'm doing wrong ?
Could it be a problem in one of the optimizations ? (Between O2 and Os)

Thanks for any help, I'm kind of stuck on that for some time now.

Baptiste Wicht

-- 
Baptiste Wicht, HES-SO University of applied Sciences
My personal website - http://baptiste-wicht.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20140412/1d091804/attachment.html>


More information about the cfe-users mailing list