0

私は C++ 初心者で、次の問題を数時間いじっています。うまくいけば、誰かが私を啓発することができます。

次のような内容の cpp ファイルがありました。

test.cpp ファイルの内容

#include <iostream>
#include <exception>
#include <stdlib.h>
#include <string.h>
using std::cin; using std::endl;
using std::string;


string foobar(string bar) {
  return "foo" + bar;
}

int main(int argc, char* argv[])
{
    string bar = "bar";
    System::convCout << "Foobar: " << foobar(bar) << endl;
}

これはコンパイルしてうまく動作します。ここで、foobar を外部ライブラリに入れたいと思います。

mylib.h ファイルの内容

string foobar(string bar);

mylib.cpp ファイルの内容

#include <string.h>
using std::cin; using std::endl;
using std::string;

string foobar(string bar) {
  return "foo" + bar;
}

test.cpp ファイルの内容

#include <iostream>
#include <exception>
#include <stdlib.h>
#include "mylib.h"

int main(int argc, char* argv[])
{
    string bar = "bar";
    System::convCout << "Foobar: " << foobar(bar) << endl;
}

test.cpp が mylib をコンパイルしてリンクするように Makefile を調整しましたが、常に次のエラーが発生します。

test.cpp::8 undefined reference to `foobar(std::string)

文字列引数をどのように処理する必要がありますか? 私の試みはここで完全に間違っているようです。

よろしくフェリックス

4

1 に答える 1