【发布时间】:2012-03-06 03:26:53
【问题描述】:
我正在 Mac 上编写 C++ 代码。为什么编译的时候会出现这个错误?:
架构 i386 的未定义符号:“Log::theString”, 参考自: libTest.a(Log.o) 中的 Log::method(std::string) ld:未找到架构 i386 的符号 clang:错误:链接器命令失败 退出代码 1(使用 -v 查看调用)
不确定我的代码是否错误,或者我必须向 Xcode 添加其他标志。我当前的 XCode 配置是“静态库”项目的默认配置。
我的代码:
Log.h------------
#include <iostream>
#include <string>
using namespace std;
class Log{
public:
static void method(string arg);
private:
static string theString ;
};
Log.cpp ----
#include "Log.h"
#include <ostream>
void Log::method(string arg){
theString = "hola";
cout << theString << endl;
}
我从测试代码中调用“方法”,方式如下: 'Log::method("asd"):'
感谢您的帮助。
【问题讨论】:
标签: c++ xcode static-libraries clang static-methods