c++ - clang++ 链接器架构 x86_64 的 undefined symbol

标签 c++ compiler-errors

$clang++ main.cpp -o out

出现如下错误,改成g++时出现同样的错误。我已经测试了一些简单的简单 C++ 代码,该命令工作正常。那么它是那个 PNG 类文件中的问题吗?然而,相同的文件以前在我的 MacOS 上运行,但今天突然失败了。

Undefined symbols for architecture x86_64:
"PNG::writeToFile(std::__1::basic_string<char, std::__1::char_traits<char>,   std::__1::allocator<char> > const&)", referenced from:
  _main in main-f6a06a.o
"PNG::PNG(std::__1::basic_string<char, std::__1::char_traits<char>,  std::__1::allocator<char> > const&)", referenced from:
  _main in main-f6a06a.o
"PNG::PNG(unsigned long, unsigned long)", referenced from:
  _main in main-f6a06a.o
"PNG::~PNG()", referenced from:
  _main in main-f6a06a.o
"PNG::operator()(unsigned long, unsigned long)", referenced from:
  _main in main-f6a06a.o
"PNG::width() const", referenced from:
  _main in main-f6a06a.o
 "PNG::height() const", referenced from:
  _main in main-f6a06a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

您是否错过了向链接器提供静态/共享以解决所提到方法的链接器错误的问题?另请注意,与 g++ 相比,clang++ 是不同的编译器,因此需要由您使用的同一编译器 (clang++) 预先编译的静态/共享库。

关于c++ - clang++ 链接器架构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42991471/

相关文章:

c++ - VS 2010 的行计数器

c++ - 将清除共享智能指针上的调用重置

compiler-errors - SPARC-RTEMS5-GCC忽略或找不到库

DEV-C++ 中的编译器错误

android - 无法使用android SDK编译项目

c++ - 使用提升多精度的数学精度问题

c++ - 方法可以添加到对象吗?

C++:单例类设计(错误:未解析的外部符号)

java - Java-ArrayOutOfBoundsException帮助我

c++ - C++ 中的狮身人面像 (Linux)