2

main.cpp

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

using namespace std;

int main(){
  Burrito b;
  return 0;
}

ブリトー.h

#ifndef BURRITO_H
#define BURRITO_H

class Burrito{
    public:
      Burrito();
};

#endif

ブリトー.cpp

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

Burrito::Burrito(){

}

コンパイル & リンク:

lzsb$ g++ main.cpp -o main
Undefined symbols for architecture x86_64:
  "Burrito::Burrito()", referenced from:
      _main in ccVpCr0z.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
lzsb$ 

プラットホーム:

Mac OS 10.6.8

G++ : i686-apple-darwin10 --with-gxx-include-dir=/usr/include/c++/4.2.1
4

2 に答える 2

10

You need to compile the Burrito.cpp file as well. The compiler creates object files from each .cpp file and links them afterwards. This is where your call fails, because the linker can't find the referenced Burrito class in any of your object files. To fix your compiler call just add Burrito.cpp

g++ main.cpp Burrito.cpp -o main
于 2012-06-12T08:17:59.123 に答える
4

コンパイル行は次のようになります。

g++ Burrito.cpp main.cpp -o main

于 2012-06-12T08:19:55.807 に答える