【发布时间】:2013-11-14 21:27:58
【问题描述】:
我刚刚启动了一个新项目,但我的类骨架没有编译。我收到的编译器错误是:
Undefined symbols for architecture x86_64:
"SQLComm::ip", referenced from:
SQLComm::SQLComm(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in SQLComm.o
"SQLComm::port", referenced from:
SQLComm::SQLComm(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in SQLComm.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不知道为什么我的代码无法编译...这是错误的类:
SQLComm.h:
#ifndef __WhisperServer__SQLComm__
#define __WhisperServer__SQLComm__
#include <iostream>
#include <string>
class SQLComm {
public:
//Local vars
static int port;
static std::string ip;
//Public functions
void connect();
SQLComm(int sqlport, std::string sqlip);
~SQLComm();
private:
};
#endif /* defined(__WhisperServer__SQLComm__) */
这是 SQLComm.cpp:
#include "SQLComm.h"
SQLComm::SQLComm(int sqlport, std::string sqlip){
ip = sqlip;
port = sqlport;
}
SQLComm::~SQLComm(){
}
void SQLComm::connect(){
}
系统是OSX10.9,编译器是GCC(在xCode中)。
如果有人能告诉我为什么会出现此错误,我会非常高兴。提前致谢! :)
【问题讨论】:
-
我不知道为什么当我发布这个时缩进消失了,但由于程序真的很短,我会让它保持这种状态。
标签: c++ gcc syntax compiler-errors