clang 3.8 make文件失败

时间:2017-01-18 13:57:55

标签: c++ c++11 clang

在我的头上搔了3个多小时后,我终于放弃了,决定请你帮忙。

我有一些文件,它们会编译成一个可执行文件。

使用-stdlib=libc++ flag,我会得到

/usr/include/c++/v1/string:1938:44: error: 'basic_string<_CharT, _Traits, _Allocator>' is missing exception specification 'noexcept(is_nothrow_copy_constructible<allocator_type>::value)'
basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
                                           ^
/usr/include/c++/v1/string:1326:40: note: previous declaration is here
    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)

我做了一些搜索,并且另一个SO问题可以解决。更改为-stdlib=libstdc++,我在控制台中获得了大量输出。

/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:382: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:382: undefined reference to `std::allocator<char>::~allocator()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:382: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:382: undefined reference to `std::allocator<char>::~allocator()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::allocator<char>::allocator()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::allocator<char>::~allocator()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:399: undefined reference to `std::allocator<char>::~allocator()'
png.o: In function `__cxx_global_var_init':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
png.o: In function `epng_err(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:18: undefined reference to `std::cerr'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:19: 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*)'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/home/bobby/Documents/freshmen/225/cs225/lab_intro/png.cpp:19: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
png.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1158: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1159: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1159: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1160: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(char const*, unsigned long)'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1161: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1163: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/basic_string.tcc:1163: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这只是信息泄露的最后一部分。

Make file is here

EXENAME = lab_intro
OBJS = main.o png.o rgbapixel.o

CXX = clang++
CXXFLAGS = -std=c++1y -stdlib=libstdc++ -c -g -O0 -Wall -Wextra -pedantic
LD = clang++
LDFLAGS = -std=c++1y -stdlib=libc++ -lpng -lc++abi -lpthread

all : $(EXENAME)

$(EXENAME) : $(OBJS)
    $(LD) $(OBJS) $(LDFLAGS) -o $(EXENAME)

main.o : main.cpp png.h rgbapixel.h
    $(CXX) $(CXXFLAGS) main.cpp

png.o : png.cpp png.h rgbapixel.h
    $(CXX) $(CXXFLAGS) png.cpp

rgbapixel.o : rgbapixel.cpp rgbapixel.h
    $(CXX) $(CXXFLAGS) rgbapixel.cpp

clean :
    -rm -f *.o $(EXENAME)

操作系统是Ubuntu 16.04LTS,安装了所有必需的依赖项(或者我认为我已正确安装)。

文件树

lab_intro/
    Makefile
    main.cpp
    png.cpp
    png.h
    rgbapixel.h
    rgbapixel.cpp
    sample.png

1 个答案:

答案 0 :(得分:5)

您需要在构建行中添加以下对中的一个:

  • -L / usr / lib -lstdc ++

  • -L / usr / lib -llibc ++