0

最初に、小さなプログラム:

#include <mysql++.h>
using namespace mysqlpp;

void mainuu ()
{ Connection conn("mysql", "localhost", "root", "pwd");}

CodeLite またはそのような方法で 1 つのファイルとしてコンパイルすると:

g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -o Test mysql_api.cpp

大丈夫ですが、このファイルでプロジェクト全体をビルドしようとすると、次のようになります。

g++ -o ./Debug/server ./Debug/main.o ./Debug/log.o ./Debug/packet.o ./Debug/mysql_api.o  -L.   
./Debug/mysql_api.o: In function `mainuu()':
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::Connection(char const*, char const*, char const*, char const*, unsigned int)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:12: undefined reference to `mysqlpp::Connection::query(char const*)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(char const*, bool)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::operator<<(mysqlpp::quote_type1, mysqlpp::SQLTypeAdapter const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:19: undefined reference to `mysqlpp::operator<<(std::basic_ostream<char, std::char_traits<char> >&, mysqlpp::String const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
./Debug/mysql_api.o: In function `mysqlpp::Row::operator[](int) const':
/usr/include/mysql++/row.h:328: undefined reference to `mysqlpp::Row::at(unsigned int) const'
./Debug/mysql_api.o: In function `mysqlpp::Query::store()':
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::store(mysqlpp::SQLTypeAdapter const&)'
collect2: ld returned 1 exit status
make[1]: *** [Debug/server] Error 1
make[1]: Leaving directory `/home/asyler/.codelite/workspace/test/server'
make: *** [All] Error 2

CodeLite g++ コンパイラの設定は次のとおりです。

-g -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -L/usr/lib/mysql -L/usr/lib/mysql++ -lmysql++
4

2 に答える 2

1

これらはリンカーエラーです。

最終的な実行可能ファイルを作成するときは、単一​​の翻訳単位をコンパイルしたときと同様に、すべてのライブラリ関数への参照を提供する必要があります。

では、-lmysqlclient -lmysqlpp今回g++もどうぞ。

統合開発環境を使用している場合は、それに応じてプロジェクトのビルド設定を構成してください。特に、CodeLite には「コンパイラ」と「リンカー」の両方のビルド設定があることがわかります。あなたが求めているのは「リンカー」の設定です。

ビルド プロセス (つまり、コンパイル、リンク、および違い) の詳細については、優れた C++ の本を読んでください。

于 2011-08-18T14:11:18.867 に答える
1

CodeLite プロジェクトの設定を編集-lmysqlclient -lmysqlppし、コマンド ラインで渡すこれらの設定を追加する必要があるようです。[リンカー] タブの [ライブラリパス]フィールドと[ライブラリ] フィールドに入力します。

于 2011-08-18T14:11:49.757 に答える