Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中架构x86_64的GCC未定义符号+;建造师_C++_Gcc_Syntax_Compiler Errors - Fatal编程技术网

C++ C+中架构x86_64的GCC未定义符号+;建造师

C++ C+中架构x86_64的GCC未定义符号+;建造师,c++,gcc,syntax,compiler-errors,C++,Gcc,Syntax,Compiler Errors,我刚刚启动了一个新项目,我的类框架没有编译。我收到的编译器错误是: 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

我刚刚启动了一个新项目,我的类框架没有编译。我收到的编译器错误是:

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)
系统是OSX10.9,编译器是GCC(在xCode中)


如果有人能告诉我为什么我会犯这个错误,我会非常高兴。提前感谢!:)

您已经声明了静态变量,但尚未定义它们。你需要加上这个

int SQLComm::port;
std::string SQLComm::ip;
到您的
SQLComm.cpp
文件


虽然。。。想想看,这可能不是你想要的。您打算声明非静态成员变量,例如,
SQLComm
的每个实例都应该包含这些变量,对吗?在这种情况下,只需删除
静态
(不要将上述内容添加到
.cpp
文件中。

您已经声明了静态变量,但尚未定义它们。您需要添加此项

int SQLComm::port;
std::string SQLComm::ip;
到您的
SQLComm.cpp
文件


尽管……考虑一下,这可能不是您想要的。您想要声明非静态成员变量,例如,
SQLComm
的每个实例都应该包含这些变量,对吗?在这种情况下,只需删除
静态
(并且不要将上述内容添加到
.cpp
文件。

您需要定义静态类变量。请尝试

int SQLComm::port;
std::string SQLComm::ip;
在SQLComm.cpp中


注意:最可能的情况是,您不想将这两个变量都声明为静态类变量,而是声明为普通实例变量。

您需要定义静态类变量。请重试

int SQLComm::port;
std::string SQLComm::ip;
在SQLComm.cpp中


注意:最可能的情况是,您不想将这两个变量都声明为静态类变量,而是声明为普通实例变量。

我不知道为什么在我发布这篇文章时缩进消失了,但由于程序非常短,我会让它保持这种状态。我不知道为什么在发布这篇文章时缩进消失了,但由于程序非常短,我将我就这么说吧。太棒了,谢谢!来自Java和C我习惯了Java的最终和C风格的静态。再次感谢:)太棒了,谢谢!来自Java和C我习惯了Java的最终和C风格的静态。再次感谢:)