如何求解体系结构x86_64的未定义符号
How to solve undefined symbol for architecture x86_64
我试图编译我的类,我得到以下结果。
g++ test.cpp -lconfig++ -stdlib=libstdc++
Undefined symbols for architecture x86_64:
"CommandParser::parseCommand(std::string)", referenced from:
_main in test-8f6e3f.o
"CommandParser::CommandParser()", referenced from:
_main in test-8f6e3f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我要编译的类:
#include "commandparser.h"
using namespace libconfig;
CommandParser::CommandParser(string configFile){
this->configFile = configFile;
}
CommandParser::CommandParser(){
this->configFile = CONFIG_FILE_NAME;
}
string CommandParser::parseCommand(string cmd){
Config cfg;
try{
cfg.readFile(this->configFile.c_str());
}
catch (const FileIOException &fi){
cerr << "I/O error while reading file." << std::endl;
exit(1);
}
catch (const ParseException &pe){
cerr << "Parse error at " << pe.getFile() << ":" << pe.getLine()
<< " - " << pe.getError() << endl;
exit(1);
}
try{
string path = cfg.lookup(cmd);
cout << "The path to the script is: " << path << endl;
return path;
}
catch(const SettingNotFoundException &e){
cerr << "No command with the name '"<<cmd<<"'"<<endl;
exit(1);
}
}
我怎么能解决这个问题,让代码编译?我用的是Mac OSX 10.9。
我在这里只是猜测,这个猜测是您显示的代码不是test.cpp
文件的一部分,而是在一个单独的文件中。这意味着您的构建命令
$ g++ test.cpp -lconfig++ -stdlib=libstdc++
将只构建test.cpp
。它不会自动将其他源文件添加到编译过程中。
您必须显式地使用构建所有相关的源文件,如
$ g++ test.cpp commandparser.cpp -lconfig++ -stdlib=libstdc++
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- C++ 中 dlsym 的未定义符号
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 体系结构x86_64的未定义符号:链接器错误
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 生成文件:体系结构x86_64的未定义符号
- libc++abi未定义符号:_ZTVN10__cxxabif120__si-class_type_infoE
- Xcode"体系结构x86_64的未定义符号"
- 体系结构x86_64的未定义符号:找不到原因
- SWIG链接器:未定义符号:_ZN2cv8fastFreeEPv(cv::fastFree(void*))
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 在Qt5上去静态库:架构的未定义符号x86_64:
- 体系结构x86_64的未定义符号:c++/ h 文件和 cpp 文件
- 监视 SDK 下的未定义符号"__Unwind_SjLj_Unregister"
- 使用 Boost/Python 的未定义符号 - 复杂
- 建筑x86_64的未定义符号:"vtkDebugLeaksManager::vtkDebugLeaksManager()",引用自: