Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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
架构x86_64的未定义符号:在C+中编译+; 使用链进行C++程序,编译过程中有问题,不知道为什么。p>_C++_X86 - Fatal编程技术网

架构x86_64的未定义符号:在C+中编译+; 使用链进行C++程序,编译过程中有问题,不知道为什么。p>

架构x86_64的未定义符号:在C+中编译+; 使用链进行C++程序,编译过程中有问题,不知道为什么。p>,c++,x86,C++,X86,我得到的错误是: Undefined symbols for architecture x86_64: "userInputOutput(linearList*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from: _main in ccBEoeAc.o "chain::chain(int)", referenc

我得到的错误是:

Undefined symbols for architecture x86_64:
  "userInputOutput(linearList*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
      _main in ccBEoeAc.o
  "chain::chain(int)", referenced from:
      _main in ccBEoeAc.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
架构x86_64的未定义符号: “userInputOutput(linearList*,std::basic_string)”,引用自: _ccBEoeAc.o中的主管道 “chain::chain(int)”,引用自: _ccBEoeAc.o中的主管道 ld:找不到架构x86_64的符号 collect2:ld返回了1个退出状态 如果我使用g++-cmain2.cpp,它会编译,但我想确保我并不是在用这个选项掩盖什么

Main2.cpp

#include <iostream>
#include "Chain.h"
#include "IOcode.h"

using namespace std;

int main (){

    //Call constructor, initial capacity 10
    chain *myChain=new chain(10);

    //Print initial chain
    userInputOutput(myChain, "chain");
}
#包括
#包括“Chain.h”
#包括“IOcode.h”
使用名称空间std;
int main(){
//调用构造函数,初始容量10
链*myChain=新链(10);
//打印初始链
用户输入输出(myChain,chain);
}
Chain.cpp

 #include "Chain.h"
#include <stdio.h>
#include <iostream>
#include <sstream>
#include "Myexception.h"

using namespace std;

    chain::chain(int initialCapacity)
    {
    cout<<"This method is working"<<endl;
/*  if (initialCapacity <1)
    {
        //throw illegalParameterValue();
    }
    firstNode=NULL;
    listSize=0;
*/
};
#包括“Chain.h”
#包括
#包括
#包括
#包括“Myexception.h”
使用名称空间std;
链::链(int initialCapacity)
{

你只是在编译一个文件

这应该是一个快速和肮脏的尝试好:

g++  main2.cpp Chain.cpp IOcode.cpp 

虽然我会添加
-Wall-Wextra-pedantic-Werror

但您只编译了一个文件

这应该是一个快速和肮脏的尝试好:

g++  main2.cpp Chain.cpp IOcode.cpp 

虽然我会添加
-Wall-Wextra-pedantic-Werror

您使用什么选项来编译和链接?但当我使用简单的g++main2.cpp编译时,我会遇到错误。当我包含-c时,它会消失,这对我意味着什么?@cdhowie当我使用g++包含-c时,我也无法运行可执行文件。
-c
选项com将源文件堆积到目标文件,但不将其链接到可执行文件中。如果没有
-c
,您将告诉编译器您已列出程序中的所有文件,但您没有--您省略了几个.cpp文件,因此编译器无法找到这些文件中函数的定义。@cdhowie谢谢对于响应,这是有意义的。我将进一步研究。您使用什么选项来编译和链接?当我使用简单的g++main2.cpp编译时,我会遇到错误。当我包含-c时,它就会消失,这对我意味着什么?@cdhowie当我使用g++包含-c时,我也无法运行可执行文件。
-c
选项编译source文件到目标文件,但不将其链接到可执行文件中。如果没有
-c
,您会告诉编译器您已经列出了程序中的所有文件,但是您没有--您省略了几个.cpp文件,因此编译器无法找到这些文件中函数的定义。@cdhowie感谢您的回复se,有道理。我将进一步研究。@user2824904rtfm;-)@user2824904rtfm;-)