$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++ - 用于架构x86_64的clang++链接器 undefined symbol ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42991471/