我在Mac上编写C++代码。为什么?:编译静态变量链接错误
Undefined symbols for architecture i386: "Log::theString", referenced from: Log::method(std::string) in libTest.a(Log.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)
不知道如果我的代码是错误的,或者有额外的标志添加到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”):'
感谢您的帮助。
我不同意,这是一个重复的问题。引用的另一个问题本质上是非常普遍的,并不会帮助我解决我的mac特定问题。 – Adam 2016-08-29 16:09:56