如何解决架构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++

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

架构x86_64的未定义符号:“ _fcloseall”

架构x86_64抖动的未定义符号

Xcode 6.3上架构x86_64的未定义符号

SFML 2.1架构x86_64错误的未定义符号

iOS中架构x86_64的未定义符号

架构x86_64的未定义符号:OS X,Boost Log,CMake

Mac上的架构x86_64 C ++的未定义符号

Boost C ++的架构x86_64的未定义符号

架构x86_64的未定义符号:“ _ OBJC_CLASS _ $ _ HandBluetooth”,引用自:

架构x86_64的未定义符号:“ _rb_funcallv”

架构x86_64链接constexpr std :: array的未定义符号

如何修复架构x86_64,Boost Asio 1.58的未定义符号

找不到架构x86_64的未定义符号&& symbol(s)

使用Json-C的架构x86_64的未定义符号

iOS项目中架构x86_64的未定义符号

架构x86_64的未定义符号->架构x86_64的未找到符号

架构x86_64的未定义符号:“ vtkDebugLeaksManager :: vtkDebugLeaksManager()”,引用自:

Hello World中架构x86_64的未定义符号

架构x86_64的未定义符号是什么意思?

架构x86_64的未定义符号:带有SFML的CMMotionManager

Pod安装期间出现Crashlytics错误“架构x86_64的未定义符号”

错误架构x86_64的未定义符号:

Boost.MPI 为架构 x86_64 提供未定义符号

链接器错误:“架构 x86_64 的未定义符号”

由于架构 x86_64 的未定义符号,GLFW 的最小示例失败

反转字符串的代码:“架构 x86_64 的未定义符号”

ProgressHUD:架构 x86_64 的未定义符号:

使用多个文件时出现“架构 x86_64 的未定义符号”错误

xCode Cocoapods 构建失败“架构 x86_64 的未定义符号”