簡體   English   中英

體系結構x86_64的未定義符號:用C ++編譯

[英]Undefined symbols for architecture x86_64: Compiling in C++

使用鏈工作C ++程序並且在不知道原因的情況下編譯有問題。

我得到的錯誤是:

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

如果我使用g ++ -c main2.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.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;
*/
};

IOcode.cpp

#include <iostream>
#include "Linearlist.h"

using namespace std;

void userInputOutput (linearList* l, string dataStructure){

    for (int i = 0; i < 13; i++)
            l->insert(i, i+1);
    cout<<"The initial "<<dataStructure<<" is: ";
    l->traverse();
    cout<<"welcome to the assignmet 3!"<<endl;
    while(true){
       //do stuff

    }
}

知道我為什么會收到這些錯誤嗎? IOcode文件提供給我,我創建的chain.cpp。 對不起,可憐的代碼,C ++的新手。

您只是編譯一個文件。

這對於快速而骯臟的嘗試應該沒問題:

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

雖然我會添加-Wall -Wextra -pedantic -Werror

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM