我正使用Mac编写C++代码。为什么在编译时会出现以下错误?:
符号未定义(针对i386架构):“Log::theString”,出现在: Log::method(std::string) in libTest.a(Log.o) 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 ;
};
日志.cpp ----
#include "Log.h"
#include <ostream>
void Log::method(string arg){
theString = "hola";
cout << theString << endl;
}
我正在测试代码中调用'method',方式如下:'Log::method("asd"):'
感谢您的帮助。
using namespace *;
的观点很好。如果你能早点改掉这个习惯会更容易些。 - Benjineerusing namespace std;
放在你自己的命名空间声明内即可 :Pnamespace your_custom_namespace { using namespace std; }
- Pellet