本文介绍了为什么简单的mysql ++代码编译独立,但不是在项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,小程序:

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

void mainuu()
{Connection conn(mysql,localhost,root,pwd);}
/ pre>

如果我在CodeLite中将其编译为一个文件,或以这种方式:

 code> g ++ -I / usr / include / mysql -I / usr / include / mysql ++ -lmysqlclient -lmysqlpp -o测试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:在函数`mainuu()':
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10:未定义引用`mysqlpp: :Connection :: Connection(char const *,char const *,char const *,char const *,unsigned int)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:12:未定义的引用`mysqlpp :: Connection :: query(char const *)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13:未定义引用`mysqlpp :: SQLTypeAdapter: :SQLTypeAdapter(char const *,bool)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13:未定义引用`mysqlpp :: operator<<(mysqlpp :: quote_type1 ,mysqlpp :: SQLTypeAdapter const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:19:未定义引用`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:未定义引用`mysqlpp :: Connection ::〜Connection()'
./Debug/mysql_api.o:在函数`mysqlpp :: Row :: operator [](int)const'中:
/usr/include/mysql++/row.h:328:undefined `mysqlpp :: Row :: at(unsigned int)const'
./Debug/mysql_api.o:在函数`mysqlpp :: Query :: store()':
/ usr / include / mysql ++ /query.h:467:未定义引用`mysqlpp :: Query :: str(mysqlpp :: SQLQueryParms&)'
/usr/include/mysql++/query.h:467:未定义引用`mysqlpp :: SQLTypeAdapter :: SQLTypeAdapter(std :: basic_string< char,std :: char_traits< char>,std :: allocator< char> > const& bool)'
/usr/include/mysql++/query.h:467:未定义的引用`mysqlpp :: Query :: store(mysqlpp :: SQLTypeAdapter const&)'
collect2:ld返回1退出状态
make [1]:*** [Debug / server]错误1
make [1]:离开目录`/home/asyler/.codelite/workspace/test/server'
make:*** [全部]错误2

这里是CodeLite g ++编译器设置: / p>

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


解决方案

看起来你需要编辑CodeLite项目设置,并添加在命令行中传递的这些设置 -lmysqlclient -lmysqlpp 。在链接器上填写。


At first, small program:

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

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

If I compile it as one file in CodeLite or in such way:

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

it's okbut, when I try to build whole project with this file I get this:

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

Here is CodeLite g++ compiler settings:

-g -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -L/usr/lib/mysql -L/usr/lib/mysql++ -lmysql++
解决方案

Looks like you need to edit CodeLite project settings and add these settings -lmysqlclient -lmysqlpp that you pass in command line. Fill Library Path and Libraries fields on Linker tab.

这篇关于为什么简单的mysql ++代码编译独立,但不是在项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 13:29