C ++でlibconfigを使用して最初の基本プログラムを実行しようとしています。でコンパイルしましg++ testing.cpp -o testingた。
#include <iostream>
#include <cstdlib>
#include <libconfig.h++>
using namespace std;
using namespace libconfig;
int main(){
Config cfg;
// Read the file. If there is an error, report it and exit.
//try
//{
cfg.readFile("/tmp/eg-report-hutapp02q-161017-08-26/eg.cfg");
//}
/*catch(const FileIOException &fioex)
{
cerr << "I/O error while reading file." << endl;
return(EXIT_FAILURE);
}
catch(const ParseException &pex)
{
cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return(EXIT_FAILURE);
}*/
cout << "This compiled" << endl;
return 0;
}
rhel6 で実行すると、次のエラーが表示されます (最初の行のみ)。
testing.cpp:(.text+0x13): undefined reference to ``libconfig::Config::Config()'
Mac Darwin Kernel 15.5.0 で実行すると、次のエラーが発生します。
Undefined symbols for architecture x86_64:
"libconfig::Config::readFile(char const*)", referenced from:
_main in testing-59bdf7.o
"libconfig::Config::Config()", referenced from:
_main in testing-59bdf7.o
"libconfig::Config::~Config()", referenced from:
_main in testing-59bdf7.o
"typeinfo for libconfig::ParseException", referenced from:
GCC_except_table0 in testing-59bdf7.o
"typeinfo for libconfig::FileIOException", referenced from:
GCC_except_table0 in testing-59bdf7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
これは、ダウンロードした libconfig-1.5.tar.gz ファイルのほんの一例です。Macでmakefileプロセスを実行し、そのエラーが発生した後、brewでlibconfig-1.6をインストールしましたが、同じエラーが発生しました。私はここで途方に暮れています。どんな助けでも大歓迎です。